1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Intel SOC Telemetry Platform Driver: Currently supports APL
4*4882a593Smuzhiyun * Copyright (c) 2015, Intel Corporation.
5*4882a593Smuzhiyun * All Rights Reserved.
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * This file provides the platform specific telemetry implementation for APL.
8*4882a593Smuzhiyun * It used the PUNIT and PMC IPC interfaces for configuring the counters.
9*4882a593Smuzhiyun * The accumulated results are fetched from SRAM.
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #include <linux/io.h>
13*4882a593Smuzhiyun #include <linux/module.h>
14*4882a593Smuzhiyun #include <linux/platform_device.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #include <asm/cpu_device_id.h>
17*4882a593Smuzhiyun #include <asm/intel-family.h>
18*4882a593Smuzhiyun #include <asm/intel_punit_ipc.h>
19*4882a593Smuzhiyun #include <asm/intel_telemetry.h>
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #define DRIVER_NAME "intel_telemetry"
22*4882a593Smuzhiyun #define DRIVER_VERSION "1.0.0"
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #define TELEM_TRC_VERBOSITY_MASK 0x3
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #define TELEM_MIN_PERIOD(x) ((x) & 0x7F0000)
27*4882a593Smuzhiyun #define TELEM_MAX_PERIOD(x) ((x) & 0x7F000000)
28*4882a593Smuzhiyun #define TELEM_SAMPLE_PERIOD_INVALID(x) ((x) & (BIT(7)))
29*4882a593Smuzhiyun #define TELEM_CLEAR_SAMPLE_PERIOD(x) ((x) &= ~0x7F)
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #define TELEM_SAMPLING_DEFAULT_PERIOD 0xD
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #define TELEM_MAX_EVENTS_SRAM 28
34*4882a593Smuzhiyun #define TELEM_SSRAM_STARTTIME_OFFSET 8
35*4882a593Smuzhiyun #define TELEM_SSRAM_EVTLOG_OFFSET 16
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun #define IOSS_TELEM 0xeb
38*4882a593Smuzhiyun #define IOSS_TELEM_EVENT_READ 0x0
39*4882a593Smuzhiyun #define IOSS_TELEM_EVENT_WRITE 0x1
40*4882a593Smuzhiyun #define IOSS_TELEM_INFO_READ 0x2
41*4882a593Smuzhiyun #define IOSS_TELEM_TRACE_CTL_READ 0x5
42*4882a593Smuzhiyun #define IOSS_TELEM_TRACE_CTL_WRITE 0x6
43*4882a593Smuzhiyun #define IOSS_TELEM_EVENT_CTL_READ 0x7
44*4882a593Smuzhiyun #define IOSS_TELEM_EVENT_CTL_WRITE 0x8
45*4882a593Smuzhiyun #define IOSS_TELEM_EVT_WRITE_SIZE 0x3
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
48*4882a593Smuzhiyun #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
49*4882a593Smuzhiyun #define TELEM_SSRAM_READ_TIMEOUT 10
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun #define TELEM_INFO_NENABLES_MASK 0xFF
52*4882a593Smuzhiyun #define TELEM_EVENT_ENABLE 0x8000
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun #define TELEM_MASK_BIT 1
55*4882a593Smuzhiyun #define TELEM_MASK_BYTE 0xFF
56*4882a593Smuzhiyun #define BYTES_PER_LONG 8
57*4882a593Smuzhiyun #define TELEM_MASK_PCS_STATE 0xF
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun #define TELEM_DISABLE(x) ((x) &= ~(BIT(31)))
60*4882a593Smuzhiyun #define TELEM_CLEAR_EVENTS(x) ((x) |= (BIT(30)))
61*4882a593Smuzhiyun #define TELEM_ENABLE_SRAM_EVT_TRACE(x) ((x) &= ~(BIT(30) | BIT(24)))
62*4882a593Smuzhiyun #define TELEM_ENABLE_PERIODIC(x) ((x) |= (BIT(23) | BIT(31) | BIT(7)))
63*4882a593Smuzhiyun #define TELEM_EXTRACT_VERBOSITY(x, y) ((y) = (((x) >> 27) & 0x3))
64*4882a593Smuzhiyun #define TELEM_CLEAR_VERBOSITY_BITS(x) ((x) &= ~(BIT(27) | BIT(28)))
65*4882a593Smuzhiyun #define TELEM_SET_VERBOSITY_BITS(x, y) ((x) |= ((y) << 27))
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun enum telemetry_action {
68*4882a593Smuzhiyun TELEM_UPDATE = 0,
69*4882a593Smuzhiyun TELEM_ADD,
70*4882a593Smuzhiyun TELEM_RESET,
71*4882a593Smuzhiyun TELEM_ACTION_NONE
72*4882a593Smuzhiyun };
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun struct telem_ssram_region {
75*4882a593Smuzhiyun u64 timestamp;
76*4882a593Smuzhiyun u64 start_time;
77*4882a593Smuzhiyun u64 events[TELEM_MAX_EVENTS_SRAM];
78*4882a593Smuzhiyun };
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun static struct telemetry_plt_config *telm_conf;
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun /*
83*4882a593Smuzhiyun * The following counters are programmed by default during setup.
84*4882a593Smuzhiyun * Only 20 allocated to kernel driver
85*4882a593Smuzhiyun */
86*4882a593Smuzhiyun static struct telemetry_evtmap
87*4882a593Smuzhiyun telemetry_apl_ioss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
88*4882a593Smuzhiyun {"SOC_S0IX_TOTAL_RES", 0x4800},
89*4882a593Smuzhiyun {"SOC_S0IX_TOTAL_OCC", 0x4000},
90*4882a593Smuzhiyun {"SOC_S0IX_SHALLOW_RES", 0x4801},
91*4882a593Smuzhiyun {"SOC_S0IX_SHALLOW_OCC", 0x4001},
92*4882a593Smuzhiyun {"SOC_S0IX_DEEP_RES", 0x4802},
93*4882a593Smuzhiyun {"SOC_S0IX_DEEP_OCC", 0x4002},
94*4882a593Smuzhiyun {"PMC_POWER_GATE", 0x5818},
95*4882a593Smuzhiyun {"PMC_D3_STATES", 0x5819},
96*4882a593Smuzhiyun {"PMC_D0I3_STATES", 0x581A},
97*4882a593Smuzhiyun {"PMC_S0IX_WAKE_REASON_GPIO", 0x6000},
98*4882a593Smuzhiyun {"PMC_S0IX_WAKE_REASON_TIMER", 0x6001},
99*4882a593Smuzhiyun {"PMC_S0IX_WAKE_REASON_VNNREQ", 0x6002},
100*4882a593Smuzhiyun {"PMC_S0IX_WAKE_REASON_LOWPOWER", 0x6003},
101*4882a593Smuzhiyun {"PMC_S0IX_WAKE_REASON_EXTERNAL", 0x6004},
102*4882a593Smuzhiyun {"PMC_S0IX_WAKE_REASON_MISC", 0x6005},
103*4882a593Smuzhiyun {"PMC_S0IX_BLOCKING_IPS_D3_D0I3", 0x6006},
104*4882a593Smuzhiyun {"PMC_S0IX_BLOCKING_IPS_PG", 0x6007},
105*4882a593Smuzhiyun {"PMC_S0IX_BLOCKING_MISC_IPS_PG", 0x6008},
106*4882a593Smuzhiyun {"PMC_S0IX_BLOCK_IPS_VNN_REQ", 0x6009},
107*4882a593Smuzhiyun {"PMC_S0IX_BLOCK_IPS_CLOCKS", 0x600B},
108*4882a593Smuzhiyun };
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun static struct telemetry_evtmap
112*4882a593Smuzhiyun telemetry_apl_pss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
113*4882a593Smuzhiyun {"IA_CORE0_C6_RES", 0x0400},
114*4882a593Smuzhiyun {"IA_CORE0_C6_CTR", 0x0000},
115*4882a593Smuzhiyun {"IA_MODULE0_C7_RES", 0x0410},
116*4882a593Smuzhiyun {"IA_MODULE0_C7_CTR", 0x000E},
117*4882a593Smuzhiyun {"IA_C0_RES", 0x0805},
118*4882a593Smuzhiyun {"PCS_LTR", 0x2801},
119*4882a593Smuzhiyun {"PSTATES", 0x2802},
120*4882a593Smuzhiyun {"SOC_S0I3_RES", 0x0409},
121*4882a593Smuzhiyun {"SOC_S0I3_CTR", 0x000A},
122*4882a593Smuzhiyun {"PCS_S0I3_CTR", 0x0009},
123*4882a593Smuzhiyun {"PCS_C1E_RES", 0x041A},
124*4882a593Smuzhiyun {"PCS_IDLE_STATUS", 0x2806},
125*4882a593Smuzhiyun {"IA_PERF_LIMITS", 0x280B},
126*4882a593Smuzhiyun {"GT_PERF_LIMITS", 0x280C},
127*4882a593Smuzhiyun {"PCS_WAKEUP_S0IX_CTR", 0x0030},
128*4882a593Smuzhiyun {"PCS_IDLE_BLOCKED", 0x2C00},
129*4882a593Smuzhiyun {"PCS_S0IX_BLOCKED", 0x2C01},
130*4882a593Smuzhiyun {"PCS_S0IX_WAKE_REASONS", 0x2C02},
131*4882a593Smuzhiyun {"PCS_LTR_BLOCKING", 0x2C03},
132*4882a593Smuzhiyun {"PC2_AND_MEM_SHALLOW_IDLE_RES", 0x1D40},
133*4882a593Smuzhiyun };
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun static struct telemetry_evtmap
136*4882a593Smuzhiyun telemetry_glk_pss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
137*4882a593Smuzhiyun {"IA_CORE0_C6_RES", 0x0400},
138*4882a593Smuzhiyun {"IA_CORE0_C6_CTR", 0x0000},
139*4882a593Smuzhiyun {"IA_MODULE0_C7_RES", 0x0410},
140*4882a593Smuzhiyun {"IA_MODULE0_C7_CTR", 0x000C},
141*4882a593Smuzhiyun {"IA_C0_RES", 0x0805},
142*4882a593Smuzhiyun {"PCS_LTR", 0x2801},
143*4882a593Smuzhiyun {"PSTATES", 0x2802},
144*4882a593Smuzhiyun {"SOC_S0I3_RES", 0x0407},
145*4882a593Smuzhiyun {"SOC_S0I3_CTR", 0x0008},
146*4882a593Smuzhiyun {"PCS_S0I3_CTR", 0x0007},
147*4882a593Smuzhiyun {"PCS_C1E_RES", 0x0414},
148*4882a593Smuzhiyun {"PCS_IDLE_STATUS", 0x2806},
149*4882a593Smuzhiyun {"IA_PERF_LIMITS", 0x280B},
150*4882a593Smuzhiyun {"GT_PERF_LIMITS", 0x280C},
151*4882a593Smuzhiyun {"PCS_WAKEUP_S0IX_CTR", 0x0025},
152*4882a593Smuzhiyun {"PCS_IDLE_BLOCKED", 0x2C00},
153*4882a593Smuzhiyun {"PCS_S0IX_BLOCKED", 0x2C01},
154*4882a593Smuzhiyun {"PCS_S0IX_WAKE_REASONS", 0x2C02},
155*4882a593Smuzhiyun {"PCS_LTR_BLOCKING", 0x2C03},
156*4882a593Smuzhiyun {"PC2_AND_MEM_SHALLOW_IDLE_RES", 0x1D40},
157*4882a593Smuzhiyun };
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun /* APL specific Data */
160*4882a593Smuzhiyun static struct telemetry_plt_config telem_apl_config = {
161*4882a593Smuzhiyun .pss_config = {
162*4882a593Smuzhiyun .telem_evts = telemetry_apl_pss_default_events,
163*4882a593Smuzhiyun },
164*4882a593Smuzhiyun .ioss_config = {
165*4882a593Smuzhiyun .telem_evts = telemetry_apl_ioss_default_events,
166*4882a593Smuzhiyun },
167*4882a593Smuzhiyun };
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun /* GLK specific Data */
170*4882a593Smuzhiyun static struct telemetry_plt_config telem_glk_config = {
171*4882a593Smuzhiyun .pss_config = {
172*4882a593Smuzhiyun .telem_evts = telemetry_glk_pss_default_events,
173*4882a593Smuzhiyun },
174*4882a593Smuzhiyun .ioss_config = {
175*4882a593Smuzhiyun .telem_evts = telemetry_apl_ioss_default_events,
176*4882a593Smuzhiyun },
177*4882a593Smuzhiyun };
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun static const struct x86_cpu_id telemetry_cpu_ids[] = {
180*4882a593Smuzhiyun X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT, &telem_apl_config),
181*4882a593Smuzhiyun X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT_PLUS, &telem_glk_config),
182*4882a593Smuzhiyun {}
183*4882a593Smuzhiyun };
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun MODULE_DEVICE_TABLE(x86cpu, telemetry_cpu_ids);
186*4882a593Smuzhiyun
telem_get_unitconfig(enum telemetry_unit telem_unit,struct telemetry_unit_config ** unit_config)187*4882a593Smuzhiyun static inline int telem_get_unitconfig(enum telemetry_unit telem_unit,
188*4882a593Smuzhiyun struct telemetry_unit_config **unit_config)
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun if (telem_unit == TELEM_PSS)
191*4882a593Smuzhiyun *unit_config = &(telm_conf->pss_config);
192*4882a593Smuzhiyun else if (telem_unit == TELEM_IOSS)
193*4882a593Smuzhiyun *unit_config = &(telm_conf->ioss_config);
194*4882a593Smuzhiyun else
195*4882a593Smuzhiyun return -EINVAL;
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun return 0;
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun
telemetry_check_evtid(enum telemetry_unit telem_unit,u32 * evtmap,u8 len,enum telemetry_action action)201*4882a593Smuzhiyun static int telemetry_check_evtid(enum telemetry_unit telem_unit,
202*4882a593Smuzhiyun u32 *evtmap, u8 len,
203*4882a593Smuzhiyun enum telemetry_action action)
204*4882a593Smuzhiyun {
205*4882a593Smuzhiyun struct telemetry_unit_config *unit_config;
206*4882a593Smuzhiyun int ret;
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun ret = telem_get_unitconfig(telem_unit, &unit_config);
209*4882a593Smuzhiyun if (ret < 0)
210*4882a593Smuzhiyun return ret;
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun switch (action) {
213*4882a593Smuzhiyun case TELEM_RESET:
214*4882a593Smuzhiyun if (len > TELEM_MAX_EVENTS_SRAM)
215*4882a593Smuzhiyun return -EINVAL;
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun break;
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun case TELEM_UPDATE:
220*4882a593Smuzhiyun if (len > TELEM_MAX_EVENTS_SRAM)
221*4882a593Smuzhiyun return -EINVAL;
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun if ((len > 0) && (evtmap == NULL))
224*4882a593Smuzhiyun return -EINVAL;
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun break;
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun case TELEM_ADD:
229*4882a593Smuzhiyun if ((len + unit_config->ssram_evts_used) >
230*4882a593Smuzhiyun TELEM_MAX_EVENTS_SRAM)
231*4882a593Smuzhiyun return -EINVAL;
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun if ((len > 0) && (evtmap == NULL))
234*4882a593Smuzhiyun return -EINVAL;
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun break;
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun default:
239*4882a593Smuzhiyun pr_err("Unknown Telemetry action specified %d\n", action);
240*4882a593Smuzhiyun return -EINVAL;
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun return 0;
244*4882a593Smuzhiyun }
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun
telemetry_plt_config_ioss_event(u32 evt_id,int index)247*4882a593Smuzhiyun static inline int telemetry_plt_config_ioss_event(u32 evt_id, int index)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun u32 write_buf;
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun write_buf = evt_id | TELEM_EVENT_ENABLE;
252*4882a593Smuzhiyun write_buf <<= BITS_PER_BYTE;
253*4882a593Smuzhiyun write_buf |= index;
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun return intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
256*4882a593Smuzhiyun IOSS_TELEM_EVENT_WRITE, &write_buf,
257*4882a593Smuzhiyun IOSS_TELEM_EVT_WRITE_SIZE, NULL, 0);
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun
telemetry_plt_config_pss_event(u32 evt_id,int index)260*4882a593Smuzhiyun static inline int telemetry_plt_config_pss_event(u32 evt_id, int index)
261*4882a593Smuzhiyun {
262*4882a593Smuzhiyun u32 write_buf;
263*4882a593Smuzhiyun int ret;
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun write_buf = evt_id | TELEM_EVENT_ENABLE;
266*4882a593Smuzhiyun ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT,
267*4882a593Smuzhiyun index, 0, &write_buf, NULL);
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun return ret;
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun
telemetry_setup_iossevtconfig(struct telemetry_evtconfig evtconfig,enum telemetry_action action)272*4882a593Smuzhiyun static int telemetry_setup_iossevtconfig(struct telemetry_evtconfig evtconfig,
273*4882a593Smuzhiyun enum telemetry_action action)
274*4882a593Smuzhiyun {
275*4882a593Smuzhiyun struct intel_scu_ipc_dev *scu = telm_conf->scu;
276*4882a593Smuzhiyun u8 num_ioss_evts, ioss_period;
277*4882a593Smuzhiyun int ret, index, idx;
278*4882a593Smuzhiyun u32 *ioss_evtmap;
279*4882a593Smuzhiyun u32 telem_ctrl;
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun num_ioss_evts = evtconfig.num_evts;
282*4882a593Smuzhiyun ioss_period = evtconfig.period;
283*4882a593Smuzhiyun ioss_evtmap = evtconfig.evtmap;
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun /* Get telemetry EVENT CTL */
286*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
287*4882a593Smuzhiyun IOSS_TELEM_EVENT_CTL_READ, NULL, 0,
288*4882a593Smuzhiyun &telem_ctrl, sizeof(telem_ctrl));
289*4882a593Smuzhiyun if (ret) {
290*4882a593Smuzhiyun pr_err("IOSS TELEM_CTRL Read Failed\n");
291*4882a593Smuzhiyun return ret;
292*4882a593Smuzhiyun }
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun /* Disable Telemetry */
295*4882a593Smuzhiyun TELEM_DISABLE(telem_ctrl);
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
298*4882a593Smuzhiyun IOSS_TELEM_EVENT_CTL_WRITE, &telem_ctrl,
299*4882a593Smuzhiyun sizeof(telem_ctrl), NULL, 0);
300*4882a593Smuzhiyun if (ret) {
301*4882a593Smuzhiyun pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
302*4882a593Smuzhiyun return ret;
303*4882a593Smuzhiyun }
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun /* Reset Everything */
307*4882a593Smuzhiyun if (action == TELEM_RESET) {
308*4882a593Smuzhiyun /* Clear All Events */
309*4882a593Smuzhiyun TELEM_CLEAR_EVENTS(telem_ctrl);
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
312*4882a593Smuzhiyun IOSS_TELEM_EVENT_CTL_WRITE,
313*4882a593Smuzhiyun &telem_ctrl, sizeof(telem_ctrl),
314*4882a593Smuzhiyun NULL, 0);
315*4882a593Smuzhiyun if (ret) {
316*4882a593Smuzhiyun pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
317*4882a593Smuzhiyun return ret;
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun telm_conf->ioss_config.ssram_evts_used = 0;
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun /* Configure Events */
322*4882a593Smuzhiyun for (idx = 0; idx < num_ioss_evts; idx++) {
323*4882a593Smuzhiyun if (telemetry_plt_config_ioss_event(
324*4882a593Smuzhiyun telm_conf->ioss_config.telem_evts[idx].evt_id,
325*4882a593Smuzhiyun idx)) {
326*4882a593Smuzhiyun pr_err("IOSS TELEM_RESET Fail for data: %x\n",
327*4882a593Smuzhiyun telm_conf->ioss_config.telem_evts[idx].evt_id);
328*4882a593Smuzhiyun continue;
329*4882a593Smuzhiyun }
330*4882a593Smuzhiyun telm_conf->ioss_config.ssram_evts_used++;
331*4882a593Smuzhiyun }
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun /* Re-Configure Everything */
335*4882a593Smuzhiyun if (action == TELEM_UPDATE) {
336*4882a593Smuzhiyun /* Clear All Events */
337*4882a593Smuzhiyun TELEM_CLEAR_EVENTS(telem_ctrl);
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
340*4882a593Smuzhiyun IOSS_TELEM_EVENT_CTL_WRITE,
341*4882a593Smuzhiyun &telem_ctrl, sizeof(telem_ctrl),
342*4882a593Smuzhiyun NULL, 0);
343*4882a593Smuzhiyun if (ret) {
344*4882a593Smuzhiyun pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
345*4882a593Smuzhiyun return ret;
346*4882a593Smuzhiyun }
347*4882a593Smuzhiyun telm_conf->ioss_config.ssram_evts_used = 0;
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun /* Configure Events */
350*4882a593Smuzhiyun for (index = 0; index < num_ioss_evts; index++) {
351*4882a593Smuzhiyun telm_conf->ioss_config.telem_evts[index].evt_id =
352*4882a593Smuzhiyun ioss_evtmap[index];
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun if (telemetry_plt_config_ioss_event(
355*4882a593Smuzhiyun telm_conf->ioss_config.telem_evts[index].evt_id,
356*4882a593Smuzhiyun index)) {
357*4882a593Smuzhiyun pr_err("IOSS TELEM_UPDATE Fail for Evt%x\n",
358*4882a593Smuzhiyun ioss_evtmap[index]);
359*4882a593Smuzhiyun continue;
360*4882a593Smuzhiyun }
361*4882a593Smuzhiyun telm_conf->ioss_config.ssram_evts_used++;
362*4882a593Smuzhiyun }
363*4882a593Smuzhiyun }
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun /* Add some Events */
366*4882a593Smuzhiyun if (action == TELEM_ADD) {
367*4882a593Smuzhiyun /* Configure Events */
368*4882a593Smuzhiyun for (index = telm_conf->ioss_config.ssram_evts_used, idx = 0;
369*4882a593Smuzhiyun idx < num_ioss_evts; index++, idx++) {
370*4882a593Smuzhiyun telm_conf->ioss_config.telem_evts[index].evt_id =
371*4882a593Smuzhiyun ioss_evtmap[idx];
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun if (telemetry_plt_config_ioss_event(
374*4882a593Smuzhiyun telm_conf->ioss_config.telem_evts[index].evt_id,
375*4882a593Smuzhiyun index)) {
376*4882a593Smuzhiyun pr_err("IOSS TELEM_ADD Fail for Event %x\n",
377*4882a593Smuzhiyun ioss_evtmap[idx]);
378*4882a593Smuzhiyun continue;
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun telm_conf->ioss_config.ssram_evts_used++;
381*4882a593Smuzhiyun }
382*4882a593Smuzhiyun }
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun /* Enable Periodic Telemetry Events and enable SRAM trace */
385*4882a593Smuzhiyun TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
386*4882a593Smuzhiyun TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
387*4882a593Smuzhiyun TELEM_ENABLE_PERIODIC(telem_ctrl);
388*4882a593Smuzhiyun telem_ctrl |= ioss_period;
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
391*4882a593Smuzhiyun IOSS_TELEM_EVENT_CTL_WRITE,
392*4882a593Smuzhiyun &telem_ctrl, sizeof(telem_ctrl), NULL, 0);
393*4882a593Smuzhiyun if (ret) {
394*4882a593Smuzhiyun pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
395*4882a593Smuzhiyun return ret;
396*4882a593Smuzhiyun }
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun telm_conf->ioss_config.curr_period = ioss_period;
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun return 0;
401*4882a593Smuzhiyun }
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun
telemetry_setup_pssevtconfig(struct telemetry_evtconfig evtconfig,enum telemetry_action action)404*4882a593Smuzhiyun static int telemetry_setup_pssevtconfig(struct telemetry_evtconfig evtconfig,
405*4882a593Smuzhiyun enum telemetry_action action)
406*4882a593Smuzhiyun {
407*4882a593Smuzhiyun u8 num_pss_evts, pss_period;
408*4882a593Smuzhiyun int ret, index, idx;
409*4882a593Smuzhiyun u32 *pss_evtmap;
410*4882a593Smuzhiyun u32 telem_ctrl;
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun num_pss_evts = evtconfig.num_evts;
413*4882a593Smuzhiyun pss_period = evtconfig.period;
414*4882a593Smuzhiyun pss_evtmap = evtconfig.evtmap;
415*4882a593Smuzhiyun
416*4882a593Smuzhiyun /* PSS Config */
417*4882a593Smuzhiyun /* Get telemetry EVENT CTL */
418*4882a593Smuzhiyun ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL,
419*4882a593Smuzhiyun 0, 0, NULL, &telem_ctrl);
420*4882a593Smuzhiyun if (ret) {
421*4882a593Smuzhiyun pr_err("PSS TELEM_CTRL Read Failed\n");
422*4882a593Smuzhiyun return ret;
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun /* Disable Telemetry */
426*4882a593Smuzhiyun TELEM_DISABLE(telem_ctrl);
427*4882a593Smuzhiyun ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
428*4882a593Smuzhiyun 0, 0, &telem_ctrl, NULL);
429*4882a593Smuzhiyun if (ret) {
430*4882a593Smuzhiyun pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
431*4882a593Smuzhiyun return ret;
432*4882a593Smuzhiyun }
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun /* Reset Everything */
435*4882a593Smuzhiyun if (action == TELEM_RESET) {
436*4882a593Smuzhiyun /* Clear All Events */
437*4882a593Smuzhiyun TELEM_CLEAR_EVENTS(telem_ctrl);
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun ret = intel_punit_ipc_command(
440*4882a593Smuzhiyun IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
441*4882a593Smuzhiyun 0, 0, &telem_ctrl, NULL);
442*4882a593Smuzhiyun if (ret) {
443*4882a593Smuzhiyun pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
444*4882a593Smuzhiyun return ret;
445*4882a593Smuzhiyun }
446*4882a593Smuzhiyun telm_conf->pss_config.ssram_evts_used = 0;
447*4882a593Smuzhiyun /* Configure Events */
448*4882a593Smuzhiyun for (idx = 0; idx < num_pss_evts; idx++) {
449*4882a593Smuzhiyun if (telemetry_plt_config_pss_event(
450*4882a593Smuzhiyun telm_conf->pss_config.telem_evts[idx].evt_id,
451*4882a593Smuzhiyun idx)) {
452*4882a593Smuzhiyun pr_err("PSS TELEM_RESET Fail for Event %x\n",
453*4882a593Smuzhiyun telm_conf->pss_config.telem_evts[idx].evt_id);
454*4882a593Smuzhiyun continue;
455*4882a593Smuzhiyun }
456*4882a593Smuzhiyun telm_conf->pss_config.ssram_evts_used++;
457*4882a593Smuzhiyun }
458*4882a593Smuzhiyun }
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun /* Re-Configure Everything */
461*4882a593Smuzhiyun if (action == TELEM_UPDATE) {
462*4882a593Smuzhiyun /* Clear All Events */
463*4882a593Smuzhiyun TELEM_CLEAR_EVENTS(telem_ctrl);
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun ret = intel_punit_ipc_command(
466*4882a593Smuzhiyun IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
467*4882a593Smuzhiyun 0, 0, &telem_ctrl, NULL);
468*4882a593Smuzhiyun if (ret) {
469*4882a593Smuzhiyun pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
470*4882a593Smuzhiyun return ret;
471*4882a593Smuzhiyun }
472*4882a593Smuzhiyun telm_conf->pss_config.ssram_evts_used = 0;
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun /* Configure Events */
475*4882a593Smuzhiyun for (index = 0; index < num_pss_evts; index++) {
476*4882a593Smuzhiyun telm_conf->pss_config.telem_evts[index].evt_id =
477*4882a593Smuzhiyun pss_evtmap[index];
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun if (telemetry_plt_config_pss_event(
480*4882a593Smuzhiyun telm_conf->pss_config.telem_evts[index].evt_id,
481*4882a593Smuzhiyun index)) {
482*4882a593Smuzhiyun pr_err("PSS TELEM_UPDATE Fail for Event %x\n",
483*4882a593Smuzhiyun pss_evtmap[index]);
484*4882a593Smuzhiyun continue;
485*4882a593Smuzhiyun }
486*4882a593Smuzhiyun telm_conf->pss_config.ssram_evts_used++;
487*4882a593Smuzhiyun }
488*4882a593Smuzhiyun }
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun /* Add some Events */
491*4882a593Smuzhiyun if (action == TELEM_ADD) {
492*4882a593Smuzhiyun /* Configure Events */
493*4882a593Smuzhiyun for (index = telm_conf->pss_config.ssram_evts_used, idx = 0;
494*4882a593Smuzhiyun idx < num_pss_evts; index++, idx++) {
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun telm_conf->pss_config.telem_evts[index].evt_id =
497*4882a593Smuzhiyun pss_evtmap[idx];
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun if (telemetry_plt_config_pss_event(
500*4882a593Smuzhiyun telm_conf->pss_config.telem_evts[index].evt_id,
501*4882a593Smuzhiyun index)) {
502*4882a593Smuzhiyun pr_err("PSS TELEM_ADD Fail for Event %x\n",
503*4882a593Smuzhiyun pss_evtmap[idx]);
504*4882a593Smuzhiyun continue;
505*4882a593Smuzhiyun }
506*4882a593Smuzhiyun telm_conf->pss_config.ssram_evts_used++;
507*4882a593Smuzhiyun }
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun /* Enable Periodic Telemetry Events and enable SRAM trace */
511*4882a593Smuzhiyun TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
512*4882a593Smuzhiyun TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
513*4882a593Smuzhiyun TELEM_ENABLE_PERIODIC(telem_ctrl);
514*4882a593Smuzhiyun telem_ctrl |= pss_period;
515*4882a593Smuzhiyun
516*4882a593Smuzhiyun ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
517*4882a593Smuzhiyun 0, 0, &telem_ctrl, NULL);
518*4882a593Smuzhiyun if (ret) {
519*4882a593Smuzhiyun pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
520*4882a593Smuzhiyun return ret;
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun
523*4882a593Smuzhiyun telm_conf->pss_config.curr_period = pss_period;
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun return 0;
526*4882a593Smuzhiyun }
527*4882a593Smuzhiyun
telemetry_setup_evtconfig(struct telemetry_evtconfig pss_evtconfig,struct telemetry_evtconfig ioss_evtconfig,enum telemetry_action action)528*4882a593Smuzhiyun static int telemetry_setup_evtconfig(struct telemetry_evtconfig pss_evtconfig,
529*4882a593Smuzhiyun struct telemetry_evtconfig ioss_evtconfig,
530*4882a593Smuzhiyun enum telemetry_action action)
531*4882a593Smuzhiyun {
532*4882a593Smuzhiyun int ret;
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun mutex_lock(&(telm_conf->telem_lock));
535*4882a593Smuzhiyun
536*4882a593Smuzhiyun if ((action == TELEM_UPDATE) && (telm_conf->telem_in_use)) {
537*4882a593Smuzhiyun ret = -EBUSY;
538*4882a593Smuzhiyun goto out;
539*4882a593Smuzhiyun }
540*4882a593Smuzhiyun
541*4882a593Smuzhiyun ret = telemetry_check_evtid(TELEM_PSS, pss_evtconfig.evtmap,
542*4882a593Smuzhiyun pss_evtconfig.num_evts, action);
543*4882a593Smuzhiyun if (ret)
544*4882a593Smuzhiyun goto out;
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun ret = telemetry_check_evtid(TELEM_IOSS, ioss_evtconfig.evtmap,
547*4882a593Smuzhiyun ioss_evtconfig.num_evts, action);
548*4882a593Smuzhiyun if (ret)
549*4882a593Smuzhiyun goto out;
550*4882a593Smuzhiyun
551*4882a593Smuzhiyun if (ioss_evtconfig.num_evts) {
552*4882a593Smuzhiyun ret = telemetry_setup_iossevtconfig(ioss_evtconfig, action);
553*4882a593Smuzhiyun if (ret)
554*4882a593Smuzhiyun goto out;
555*4882a593Smuzhiyun }
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun if (pss_evtconfig.num_evts) {
558*4882a593Smuzhiyun ret = telemetry_setup_pssevtconfig(pss_evtconfig, action);
559*4882a593Smuzhiyun if (ret)
560*4882a593Smuzhiyun goto out;
561*4882a593Smuzhiyun }
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun if ((action == TELEM_UPDATE) || (action == TELEM_ADD))
564*4882a593Smuzhiyun telm_conf->telem_in_use = true;
565*4882a593Smuzhiyun else
566*4882a593Smuzhiyun telm_conf->telem_in_use = false;
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun out:
569*4882a593Smuzhiyun mutex_unlock(&(telm_conf->telem_lock));
570*4882a593Smuzhiyun return ret;
571*4882a593Smuzhiyun }
572*4882a593Smuzhiyun
telemetry_setup(struct platform_device * pdev)573*4882a593Smuzhiyun static int telemetry_setup(struct platform_device *pdev)
574*4882a593Smuzhiyun {
575*4882a593Smuzhiyun struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;
576*4882a593Smuzhiyun u32 read_buf, events, event_regs;
577*4882a593Smuzhiyun int ret;
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
580*4882a593Smuzhiyun IOSS_TELEM_INFO_READ, NULL, 0,
581*4882a593Smuzhiyun &read_buf, sizeof(read_buf));
582*4882a593Smuzhiyun if (ret) {
583*4882a593Smuzhiyun dev_err(&pdev->dev, "IOSS TELEM_INFO Read Failed\n");
584*4882a593Smuzhiyun return ret;
585*4882a593Smuzhiyun }
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun /* Get telemetry Info */
588*4882a593Smuzhiyun events = (read_buf & TELEM_INFO_SRAMEVTS_MASK) >>
589*4882a593Smuzhiyun TELEM_INFO_SRAMEVTS_SHIFT;
590*4882a593Smuzhiyun event_regs = read_buf & TELEM_INFO_NENABLES_MASK;
591*4882a593Smuzhiyun if ((events < TELEM_MAX_EVENTS_SRAM) ||
592*4882a593Smuzhiyun (event_regs < TELEM_MAX_EVENTS_SRAM)) {
593*4882a593Smuzhiyun dev_err(&pdev->dev, "IOSS:Insufficient Space for SRAM Trace\n");
594*4882a593Smuzhiyun dev_err(&pdev->dev, "SRAM Events %d; Event Regs %d\n",
595*4882a593Smuzhiyun events, event_regs);
596*4882a593Smuzhiyun return -ENOMEM;
597*4882a593Smuzhiyun }
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun telm_conf->ioss_config.min_period = TELEM_MIN_PERIOD(read_buf);
600*4882a593Smuzhiyun telm_conf->ioss_config.max_period = TELEM_MAX_PERIOD(read_buf);
601*4882a593Smuzhiyun
602*4882a593Smuzhiyun /* PUNIT Mailbox Setup */
603*4882a593Smuzhiyun ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_INFO, 0, 0,
604*4882a593Smuzhiyun NULL, &read_buf);
605*4882a593Smuzhiyun if (ret) {
606*4882a593Smuzhiyun dev_err(&pdev->dev, "PSS TELEM_INFO Read Failed\n");
607*4882a593Smuzhiyun return ret;
608*4882a593Smuzhiyun }
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun /* Get telemetry Info */
611*4882a593Smuzhiyun events = (read_buf & TELEM_INFO_SRAMEVTS_MASK) >>
612*4882a593Smuzhiyun TELEM_INFO_SRAMEVTS_SHIFT;
613*4882a593Smuzhiyun event_regs = read_buf & TELEM_INFO_SRAMEVTS_MASK;
614*4882a593Smuzhiyun if ((events < TELEM_MAX_EVENTS_SRAM) ||
615*4882a593Smuzhiyun (event_regs < TELEM_MAX_EVENTS_SRAM)) {
616*4882a593Smuzhiyun dev_err(&pdev->dev, "PSS:Insufficient Space for SRAM Trace\n");
617*4882a593Smuzhiyun dev_err(&pdev->dev, "SRAM Events %d; Event Regs %d\n",
618*4882a593Smuzhiyun events, event_regs);
619*4882a593Smuzhiyun return -ENOMEM;
620*4882a593Smuzhiyun }
621*4882a593Smuzhiyun
622*4882a593Smuzhiyun telm_conf->pss_config.min_period = TELEM_MIN_PERIOD(read_buf);
623*4882a593Smuzhiyun telm_conf->pss_config.max_period = TELEM_MAX_PERIOD(read_buf);
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun pss_evtconfig.evtmap = NULL;
626*4882a593Smuzhiyun pss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
627*4882a593Smuzhiyun pss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun ioss_evtconfig.evtmap = NULL;
630*4882a593Smuzhiyun ioss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
631*4882a593Smuzhiyun ioss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
634*4882a593Smuzhiyun TELEM_RESET);
635*4882a593Smuzhiyun if (ret) {
636*4882a593Smuzhiyun dev_err(&pdev->dev, "TELEMETRY Setup Failed\n");
637*4882a593Smuzhiyun return ret;
638*4882a593Smuzhiyun }
639*4882a593Smuzhiyun return 0;
640*4882a593Smuzhiyun }
641*4882a593Smuzhiyun
telemetry_plt_update_events(struct telemetry_evtconfig pss_evtconfig,struct telemetry_evtconfig ioss_evtconfig)642*4882a593Smuzhiyun static int telemetry_plt_update_events(struct telemetry_evtconfig pss_evtconfig,
643*4882a593Smuzhiyun struct telemetry_evtconfig ioss_evtconfig)
644*4882a593Smuzhiyun {
645*4882a593Smuzhiyun int ret;
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun if ((pss_evtconfig.num_evts > 0) &&
648*4882a593Smuzhiyun (TELEM_SAMPLE_PERIOD_INVALID(pss_evtconfig.period))) {
649*4882a593Smuzhiyun pr_err("PSS Sampling Period Out of Range\n");
650*4882a593Smuzhiyun return -EINVAL;
651*4882a593Smuzhiyun }
652*4882a593Smuzhiyun
653*4882a593Smuzhiyun if ((ioss_evtconfig.num_evts > 0) &&
654*4882a593Smuzhiyun (TELEM_SAMPLE_PERIOD_INVALID(ioss_evtconfig.period))) {
655*4882a593Smuzhiyun pr_err("IOSS Sampling Period Out of Range\n");
656*4882a593Smuzhiyun return -EINVAL;
657*4882a593Smuzhiyun }
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
660*4882a593Smuzhiyun TELEM_UPDATE);
661*4882a593Smuzhiyun if (ret)
662*4882a593Smuzhiyun pr_err("TELEMETRY Config Failed\n");
663*4882a593Smuzhiyun
664*4882a593Smuzhiyun return ret;
665*4882a593Smuzhiyun }
666*4882a593Smuzhiyun
667*4882a593Smuzhiyun
telemetry_plt_set_sampling_period(u8 pss_period,u8 ioss_period)668*4882a593Smuzhiyun static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)
669*4882a593Smuzhiyun {
670*4882a593Smuzhiyun u32 telem_ctrl = 0;
671*4882a593Smuzhiyun int ret = 0;
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun mutex_lock(&(telm_conf->telem_lock));
674*4882a593Smuzhiyun if (ioss_period) {
675*4882a593Smuzhiyun struct intel_scu_ipc_dev *scu = telm_conf->scu;
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun if (TELEM_SAMPLE_PERIOD_INVALID(ioss_period)) {
678*4882a593Smuzhiyun pr_err("IOSS Sampling Period Out of Range\n");
679*4882a593Smuzhiyun ret = -EINVAL;
680*4882a593Smuzhiyun goto out;
681*4882a593Smuzhiyun }
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun /* Get telemetry EVENT CTL */
684*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
685*4882a593Smuzhiyun IOSS_TELEM_EVENT_CTL_READ, NULL, 0,
686*4882a593Smuzhiyun &telem_ctrl, sizeof(telem_ctrl));
687*4882a593Smuzhiyun if (ret) {
688*4882a593Smuzhiyun pr_err("IOSS TELEM_CTRL Read Failed\n");
689*4882a593Smuzhiyun goto out;
690*4882a593Smuzhiyun }
691*4882a593Smuzhiyun
692*4882a593Smuzhiyun /* Disable Telemetry */
693*4882a593Smuzhiyun TELEM_DISABLE(telem_ctrl);
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
696*4882a593Smuzhiyun IOSS_TELEM_EVENT_CTL_WRITE,
697*4882a593Smuzhiyun &telem_ctrl, sizeof(telem_ctrl),
698*4882a593Smuzhiyun NULL, 0);
699*4882a593Smuzhiyun if (ret) {
700*4882a593Smuzhiyun pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
701*4882a593Smuzhiyun goto out;
702*4882a593Smuzhiyun }
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun /* Enable Periodic Telemetry Events and enable SRAM trace */
705*4882a593Smuzhiyun TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
706*4882a593Smuzhiyun TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
707*4882a593Smuzhiyun TELEM_ENABLE_PERIODIC(telem_ctrl);
708*4882a593Smuzhiyun telem_ctrl |= ioss_period;
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
711*4882a593Smuzhiyun IOSS_TELEM_EVENT_CTL_WRITE,
712*4882a593Smuzhiyun &telem_ctrl, sizeof(telem_ctrl),
713*4882a593Smuzhiyun NULL, 0);
714*4882a593Smuzhiyun if (ret) {
715*4882a593Smuzhiyun pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
716*4882a593Smuzhiyun goto out;
717*4882a593Smuzhiyun }
718*4882a593Smuzhiyun telm_conf->ioss_config.curr_period = ioss_period;
719*4882a593Smuzhiyun }
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun if (pss_period) {
722*4882a593Smuzhiyun if (TELEM_SAMPLE_PERIOD_INVALID(pss_period)) {
723*4882a593Smuzhiyun pr_err("PSS Sampling Period Out of Range\n");
724*4882a593Smuzhiyun ret = -EINVAL;
725*4882a593Smuzhiyun goto out;
726*4882a593Smuzhiyun }
727*4882a593Smuzhiyun
728*4882a593Smuzhiyun /* Get telemetry EVENT CTL */
729*4882a593Smuzhiyun ret = intel_punit_ipc_command(
730*4882a593Smuzhiyun IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL,
731*4882a593Smuzhiyun 0, 0, NULL, &telem_ctrl);
732*4882a593Smuzhiyun if (ret) {
733*4882a593Smuzhiyun pr_err("PSS TELEM_CTRL Read Failed\n");
734*4882a593Smuzhiyun goto out;
735*4882a593Smuzhiyun }
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun /* Disable Telemetry */
738*4882a593Smuzhiyun TELEM_DISABLE(telem_ctrl);
739*4882a593Smuzhiyun ret = intel_punit_ipc_command(
740*4882a593Smuzhiyun IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
741*4882a593Smuzhiyun 0, 0, &telem_ctrl, NULL);
742*4882a593Smuzhiyun if (ret) {
743*4882a593Smuzhiyun pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
744*4882a593Smuzhiyun goto out;
745*4882a593Smuzhiyun }
746*4882a593Smuzhiyun
747*4882a593Smuzhiyun /* Enable Periodic Telemetry Events and enable SRAM trace */
748*4882a593Smuzhiyun TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
749*4882a593Smuzhiyun TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
750*4882a593Smuzhiyun TELEM_ENABLE_PERIODIC(telem_ctrl);
751*4882a593Smuzhiyun telem_ctrl |= pss_period;
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun ret = intel_punit_ipc_command(
754*4882a593Smuzhiyun IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
755*4882a593Smuzhiyun 0, 0, &telem_ctrl, NULL);
756*4882a593Smuzhiyun if (ret) {
757*4882a593Smuzhiyun pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
758*4882a593Smuzhiyun goto out;
759*4882a593Smuzhiyun }
760*4882a593Smuzhiyun telm_conf->pss_config.curr_period = pss_period;
761*4882a593Smuzhiyun }
762*4882a593Smuzhiyun
763*4882a593Smuzhiyun out:
764*4882a593Smuzhiyun mutex_unlock(&(telm_conf->telem_lock));
765*4882a593Smuzhiyun return ret;
766*4882a593Smuzhiyun }
767*4882a593Smuzhiyun
768*4882a593Smuzhiyun
telemetry_plt_get_sampling_period(u8 * pss_min_period,u8 * pss_max_period,u8 * ioss_min_period,u8 * ioss_max_period)769*4882a593Smuzhiyun static int telemetry_plt_get_sampling_period(u8 *pss_min_period,
770*4882a593Smuzhiyun u8 *pss_max_period,
771*4882a593Smuzhiyun u8 *ioss_min_period,
772*4882a593Smuzhiyun u8 *ioss_max_period)
773*4882a593Smuzhiyun {
774*4882a593Smuzhiyun *pss_min_period = telm_conf->pss_config.min_period;
775*4882a593Smuzhiyun *pss_max_period = telm_conf->pss_config.max_period;
776*4882a593Smuzhiyun *ioss_min_period = telm_conf->ioss_config.min_period;
777*4882a593Smuzhiyun *ioss_max_period = telm_conf->ioss_config.max_period;
778*4882a593Smuzhiyun
779*4882a593Smuzhiyun return 0;
780*4882a593Smuzhiyun }
781*4882a593Smuzhiyun
782*4882a593Smuzhiyun
telemetry_plt_reset_events(void)783*4882a593Smuzhiyun static int telemetry_plt_reset_events(void)
784*4882a593Smuzhiyun {
785*4882a593Smuzhiyun struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;
786*4882a593Smuzhiyun int ret;
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun pss_evtconfig.evtmap = NULL;
789*4882a593Smuzhiyun pss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
790*4882a593Smuzhiyun pss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
791*4882a593Smuzhiyun
792*4882a593Smuzhiyun ioss_evtconfig.evtmap = NULL;
793*4882a593Smuzhiyun ioss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
794*4882a593Smuzhiyun ioss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
795*4882a593Smuzhiyun
796*4882a593Smuzhiyun ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
797*4882a593Smuzhiyun TELEM_RESET);
798*4882a593Smuzhiyun if (ret)
799*4882a593Smuzhiyun pr_err("TELEMETRY Reset Failed\n");
800*4882a593Smuzhiyun
801*4882a593Smuzhiyun return ret;
802*4882a593Smuzhiyun }
803*4882a593Smuzhiyun
804*4882a593Smuzhiyun
telemetry_plt_get_eventconfig(struct telemetry_evtconfig * pss_config,struct telemetry_evtconfig * ioss_config,int pss_len,int ioss_len)805*4882a593Smuzhiyun static int telemetry_plt_get_eventconfig(struct telemetry_evtconfig *pss_config,
806*4882a593Smuzhiyun struct telemetry_evtconfig *ioss_config,
807*4882a593Smuzhiyun int pss_len, int ioss_len)
808*4882a593Smuzhiyun {
809*4882a593Smuzhiyun u32 *pss_evtmap, *ioss_evtmap;
810*4882a593Smuzhiyun u32 index;
811*4882a593Smuzhiyun
812*4882a593Smuzhiyun pss_evtmap = pss_config->evtmap;
813*4882a593Smuzhiyun ioss_evtmap = ioss_config->evtmap;
814*4882a593Smuzhiyun
815*4882a593Smuzhiyun mutex_lock(&(telm_conf->telem_lock));
816*4882a593Smuzhiyun pss_config->num_evts = telm_conf->pss_config.ssram_evts_used;
817*4882a593Smuzhiyun ioss_config->num_evts = telm_conf->ioss_config.ssram_evts_used;
818*4882a593Smuzhiyun
819*4882a593Smuzhiyun pss_config->period = telm_conf->pss_config.curr_period;
820*4882a593Smuzhiyun ioss_config->period = telm_conf->ioss_config.curr_period;
821*4882a593Smuzhiyun
822*4882a593Smuzhiyun if ((pss_len < telm_conf->pss_config.ssram_evts_used) ||
823*4882a593Smuzhiyun (ioss_len < telm_conf->ioss_config.ssram_evts_used)) {
824*4882a593Smuzhiyun mutex_unlock(&(telm_conf->telem_lock));
825*4882a593Smuzhiyun return -EINVAL;
826*4882a593Smuzhiyun }
827*4882a593Smuzhiyun
828*4882a593Smuzhiyun for (index = 0; index < telm_conf->pss_config.ssram_evts_used;
829*4882a593Smuzhiyun index++) {
830*4882a593Smuzhiyun pss_evtmap[index] =
831*4882a593Smuzhiyun telm_conf->pss_config.telem_evts[index].evt_id;
832*4882a593Smuzhiyun }
833*4882a593Smuzhiyun
834*4882a593Smuzhiyun for (index = 0; index < telm_conf->ioss_config.ssram_evts_used;
835*4882a593Smuzhiyun index++) {
836*4882a593Smuzhiyun ioss_evtmap[index] =
837*4882a593Smuzhiyun telm_conf->ioss_config.telem_evts[index].evt_id;
838*4882a593Smuzhiyun }
839*4882a593Smuzhiyun
840*4882a593Smuzhiyun mutex_unlock(&(telm_conf->telem_lock));
841*4882a593Smuzhiyun return 0;
842*4882a593Smuzhiyun }
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun
telemetry_plt_add_events(u8 num_pss_evts,u8 num_ioss_evts,u32 * pss_evtmap,u32 * ioss_evtmap)845*4882a593Smuzhiyun static int telemetry_plt_add_events(u8 num_pss_evts, u8 num_ioss_evts,
846*4882a593Smuzhiyun u32 *pss_evtmap, u32 *ioss_evtmap)
847*4882a593Smuzhiyun {
848*4882a593Smuzhiyun struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;
849*4882a593Smuzhiyun int ret;
850*4882a593Smuzhiyun
851*4882a593Smuzhiyun pss_evtconfig.evtmap = pss_evtmap;
852*4882a593Smuzhiyun pss_evtconfig.num_evts = num_pss_evts;
853*4882a593Smuzhiyun pss_evtconfig.period = telm_conf->pss_config.curr_period;
854*4882a593Smuzhiyun
855*4882a593Smuzhiyun ioss_evtconfig.evtmap = ioss_evtmap;
856*4882a593Smuzhiyun ioss_evtconfig.num_evts = num_ioss_evts;
857*4882a593Smuzhiyun ioss_evtconfig.period = telm_conf->ioss_config.curr_period;
858*4882a593Smuzhiyun
859*4882a593Smuzhiyun ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
860*4882a593Smuzhiyun TELEM_ADD);
861*4882a593Smuzhiyun if (ret)
862*4882a593Smuzhiyun pr_err("TELEMETRY ADD Failed\n");
863*4882a593Smuzhiyun
864*4882a593Smuzhiyun return ret;
865*4882a593Smuzhiyun }
866*4882a593Smuzhiyun
telem_evtlog_read(enum telemetry_unit telem_unit,struct telem_ssram_region * ssram_region,u8 len)867*4882a593Smuzhiyun static int telem_evtlog_read(enum telemetry_unit telem_unit,
868*4882a593Smuzhiyun struct telem_ssram_region *ssram_region, u8 len)
869*4882a593Smuzhiyun {
870*4882a593Smuzhiyun struct telemetry_unit_config *unit_config;
871*4882a593Smuzhiyun u64 timestamp_prev, timestamp_next;
872*4882a593Smuzhiyun int ret, index, timeout = 0;
873*4882a593Smuzhiyun
874*4882a593Smuzhiyun ret = telem_get_unitconfig(telem_unit, &unit_config);
875*4882a593Smuzhiyun if (ret < 0)
876*4882a593Smuzhiyun return ret;
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun if (len > unit_config->ssram_evts_used)
879*4882a593Smuzhiyun len = unit_config->ssram_evts_used;
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun do {
882*4882a593Smuzhiyun timestamp_prev = readq(unit_config->regmap);
883*4882a593Smuzhiyun if (!timestamp_prev) {
884*4882a593Smuzhiyun pr_err("Ssram under update. Please Try Later\n");
885*4882a593Smuzhiyun return -EBUSY;
886*4882a593Smuzhiyun }
887*4882a593Smuzhiyun
888*4882a593Smuzhiyun ssram_region->start_time = readq(unit_config->regmap +
889*4882a593Smuzhiyun TELEM_SSRAM_STARTTIME_OFFSET);
890*4882a593Smuzhiyun
891*4882a593Smuzhiyun for (index = 0; index < len; index++) {
892*4882a593Smuzhiyun ssram_region->events[index] =
893*4882a593Smuzhiyun readq(unit_config->regmap + TELEM_SSRAM_EVTLOG_OFFSET +
894*4882a593Smuzhiyun BYTES_PER_LONG*index);
895*4882a593Smuzhiyun }
896*4882a593Smuzhiyun
897*4882a593Smuzhiyun timestamp_next = readq(unit_config->regmap);
898*4882a593Smuzhiyun if (!timestamp_next) {
899*4882a593Smuzhiyun pr_err("Ssram under update. Please Try Later\n");
900*4882a593Smuzhiyun return -EBUSY;
901*4882a593Smuzhiyun }
902*4882a593Smuzhiyun
903*4882a593Smuzhiyun if (timeout++ > TELEM_SSRAM_READ_TIMEOUT) {
904*4882a593Smuzhiyun pr_err("Timeout while reading Events\n");
905*4882a593Smuzhiyun return -EBUSY;
906*4882a593Smuzhiyun }
907*4882a593Smuzhiyun
908*4882a593Smuzhiyun } while (timestamp_prev != timestamp_next);
909*4882a593Smuzhiyun
910*4882a593Smuzhiyun ssram_region->timestamp = timestamp_next;
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun return len;
913*4882a593Smuzhiyun }
914*4882a593Smuzhiyun
telemetry_plt_raw_read_eventlog(enum telemetry_unit telem_unit,struct telemetry_evtlog * evtlog,int len,int log_all_evts)915*4882a593Smuzhiyun static int telemetry_plt_raw_read_eventlog(enum telemetry_unit telem_unit,
916*4882a593Smuzhiyun struct telemetry_evtlog *evtlog,
917*4882a593Smuzhiyun int len, int log_all_evts)
918*4882a593Smuzhiyun {
919*4882a593Smuzhiyun int index, idx1, ret, readlen = len;
920*4882a593Smuzhiyun struct telem_ssram_region ssram_region;
921*4882a593Smuzhiyun struct telemetry_evtmap *evtmap;
922*4882a593Smuzhiyun
923*4882a593Smuzhiyun switch (telem_unit) {
924*4882a593Smuzhiyun case TELEM_PSS:
925*4882a593Smuzhiyun evtmap = telm_conf->pss_config.telem_evts;
926*4882a593Smuzhiyun break;
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun case TELEM_IOSS:
929*4882a593Smuzhiyun evtmap = telm_conf->ioss_config.telem_evts;
930*4882a593Smuzhiyun break;
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun default:
933*4882a593Smuzhiyun pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
934*4882a593Smuzhiyun return -EINVAL;
935*4882a593Smuzhiyun }
936*4882a593Smuzhiyun
937*4882a593Smuzhiyun if (!log_all_evts)
938*4882a593Smuzhiyun readlen = TELEM_MAX_EVENTS_SRAM;
939*4882a593Smuzhiyun
940*4882a593Smuzhiyun ret = telem_evtlog_read(telem_unit, &ssram_region, readlen);
941*4882a593Smuzhiyun if (ret < 0)
942*4882a593Smuzhiyun return ret;
943*4882a593Smuzhiyun
944*4882a593Smuzhiyun /* Invalid evt-id array specified via length mismatch */
945*4882a593Smuzhiyun if ((!log_all_evts) && (len > ret))
946*4882a593Smuzhiyun return -EINVAL;
947*4882a593Smuzhiyun
948*4882a593Smuzhiyun if (log_all_evts)
949*4882a593Smuzhiyun for (index = 0; index < ret; index++) {
950*4882a593Smuzhiyun evtlog[index].telem_evtlog = ssram_region.events[index];
951*4882a593Smuzhiyun evtlog[index].telem_evtid = evtmap[index].evt_id;
952*4882a593Smuzhiyun }
953*4882a593Smuzhiyun else
954*4882a593Smuzhiyun for (index = 0, readlen = 0; (index < ret) && (readlen < len);
955*4882a593Smuzhiyun index++) {
956*4882a593Smuzhiyun for (idx1 = 0; idx1 < len; idx1++) {
957*4882a593Smuzhiyun /* Elements matched */
958*4882a593Smuzhiyun if (evtmap[index].evt_id ==
959*4882a593Smuzhiyun evtlog[idx1].telem_evtid) {
960*4882a593Smuzhiyun evtlog[idx1].telem_evtlog =
961*4882a593Smuzhiyun ssram_region.events[index];
962*4882a593Smuzhiyun readlen++;
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun break;
965*4882a593Smuzhiyun }
966*4882a593Smuzhiyun }
967*4882a593Smuzhiyun }
968*4882a593Smuzhiyun
969*4882a593Smuzhiyun return readlen;
970*4882a593Smuzhiyun }
971*4882a593Smuzhiyun
telemetry_plt_read_eventlog(enum telemetry_unit telem_unit,struct telemetry_evtlog * evtlog,int len,int log_all_evts)972*4882a593Smuzhiyun static int telemetry_plt_read_eventlog(enum telemetry_unit telem_unit,
973*4882a593Smuzhiyun struct telemetry_evtlog *evtlog, int len, int log_all_evts)
974*4882a593Smuzhiyun {
975*4882a593Smuzhiyun int ret;
976*4882a593Smuzhiyun
977*4882a593Smuzhiyun mutex_lock(&(telm_conf->telem_lock));
978*4882a593Smuzhiyun ret = telemetry_plt_raw_read_eventlog(telem_unit, evtlog,
979*4882a593Smuzhiyun len, log_all_evts);
980*4882a593Smuzhiyun mutex_unlock(&(telm_conf->telem_lock));
981*4882a593Smuzhiyun
982*4882a593Smuzhiyun return ret;
983*4882a593Smuzhiyun }
984*4882a593Smuzhiyun
telemetry_plt_get_trace_verbosity(enum telemetry_unit telem_unit,u32 * verbosity)985*4882a593Smuzhiyun static int telemetry_plt_get_trace_verbosity(enum telemetry_unit telem_unit,
986*4882a593Smuzhiyun u32 *verbosity)
987*4882a593Smuzhiyun {
988*4882a593Smuzhiyun u32 temp = 0;
989*4882a593Smuzhiyun int ret;
990*4882a593Smuzhiyun
991*4882a593Smuzhiyun if (verbosity == NULL)
992*4882a593Smuzhiyun return -EINVAL;
993*4882a593Smuzhiyun
994*4882a593Smuzhiyun mutex_lock(&(telm_conf->telem_trace_lock));
995*4882a593Smuzhiyun switch (telem_unit) {
996*4882a593Smuzhiyun case TELEM_PSS:
997*4882a593Smuzhiyun ret = intel_punit_ipc_command(
998*4882a593Smuzhiyun IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL,
999*4882a593Smuzhiyun 0, 0, NULL, &temp);
1000*4882a593Smuzhiyun if (ret) {
1001*4882a593Smuzhiyun pr_err("PSS TRACE_CTRL Read Failed\n");
1002*4882a593Smuzhiyun goto out;
1003*4882a593Smuzhiyun }
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun break;
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun case TELEM_IOSS:
1008*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(telm_conf->scu,
1009*4882a593Smuzhiyun IOSS_TELEM, IOSS_TELEM_TRACE_CTL_READ,
1010*4882a593Smuzhiyun NULL, 0, &temp, sizeof(temp));
1011*4882a593Smuzhiyun if (ret) {
1012*4882a593Smuzhiyun pr_err("IOSS TRACE_CTL Read Failed\n");
1013*4882a593Smuzhiyun goto out;
1014*4882a593Smuzhiyun }
1015*4882a593Smuzhiyun
1016*4882a593Smuzhiyun break;
1017*4882a593Smuzhiyun
1018*4882a593Smuzhiyun default:
1019*4882a593Smuzhiyun pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
1020*4882a593Smuzhiyun ret = -EINVAL;
1021*4882a593Smuzhiyun break;
1022*4882a593Smuzhiyun }
1023*4882a593Smuzhiyun TELEM_EXTRACT_VERBOSITY(temp, *verbosity);
1024*4882a593Smuzhiyun
1025*4882a593Smuzhiyun out:
1026*4882a593Smuzhiyun mutex_unlock(&(telm_conf->telem_trace_lock));
1027*4882a593Smuzhiyun return ret;
1028*4882a593Smuzhiyun }
1029*4882a593Smuzhiyun
telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit,u32 verbosity)1030*4882a593Smuzhiyun static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit,
1031*4882a593Smuzhiyun u32 verbosity)
1032*4882a593Smuzhiyun {
1033*4882a593Smuzhiyun u32 temp = 0;
1034*4882a593Smuzhiyun int ret;
1035*4882a593Smuzhiyun
1036*4882a593Smuzhiyun verbosity &= TELEM_TRC_VERBOSITY_MASK;
1037*4882a593Smuzhiyun
1038*4882a593Smuzhiyun mutex_lock(&(telm_conf->telem_trace_lock));
1039*4882a593Smuzhiyun switch (telem_unit) {
1040*4882a593Smuzhiyun case TELEM_PSS:
1041*4882a593Smuzhiyun ret = intel_punit_ipc_command(
1042*4882a593Smuzhiyun IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL,
1043*4882a593Smuzhiyun 0, 0, NULL, &temp);
1044*4882a593Smuzhiyun if (ret) {
1045*4882a593Smuzhiyun pr_err("PSS TRACE_CTRL Read Failed\n");
1046*4882a593Smuzhiyun goto out;
1047*4882a593Smuzhiyun }
1048*4882a593Smuzhiyun
1049*4882a593Smuzhiyun TELEM_CLEAR_VERBOSITY_BITS(temp);
1050*4882a593Smuzhiyun TELEM_SET_VERBOSITY_BITS(temp, verbosity);
1051*4882a593Smuzhiyun
1052*4882a593Smuzhiyun ret = intel_punit_ipc_command(
1053*4882a593Smuzhiyun IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL,
1054*4882a593Smuzhiyun 0, 0, &temp, NULL);
1055*4882a593Smuzhiyun if (ret) {
1056*4882a593Smuzhiyun pr_err("PSS TRACE_CTRL Verbosity Set Failed\n");
1057*4882a593Smuzhiyun goto out;
1058*4882a593Smuzhiyun }
1059*4882a593Smuzhiyun break;
1060*4882a593Smuzhiyun
1061*4882a593Smuzhiyun case TELEM_IOSS:
1062*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
1063*4882a593Smuzhiyun IOSS_TELEM_TRACE_CTL_READ,
1064*4882a593Smuzhiyun NULL, 0, &temp, sizeof(temp));
1065*4882a593Smuzhiyun if (ret) {
1066*4882a593Smuzhiyun pr_err("IOSS TRACE_CTL Read Failed\n");
1067*4882a593Smuzhiyun goto out;
1068*4882a593Smuzhiyun }
1069*4882a593Smuzhiyun
1070*4882a593Smuzhiyun TELEM_CLEAR_VERBOSITY_BITS(temp);
1071*4882a593Smuzhiyun TELEM_SET_VERBOSITY_BITS(temp, verbosity);
1072*4882a593Smuzhiyun
1073*4882a593Smuzhiyun ret = intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
1074*4882a593Smuzhiyun IOSS_TELEM_TRACE_CTL_WRITE,
1075*4882a593Smuzhiyun &temp, sizeof(temp), NULL, 0);
1076*4882a593Smuzhiyun if (ret) {
1077*4882a593Smuzhiyun pr_err("IOSS TRACE_CTL Verbosity Set Failed\n");
1078*4882a593Smuzhiyun goto out;
1079*4882a593Smuzhiyun }
1080*4882a593Smuzhiyun break;
1081*4882a593Smuzhiyun
1082*4882a593Smuzhiyun default:
1083*4882a593Smuzhiyun pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
1084*4882a593Smuzhiyun ret = -EINVAL;
1085*4882a593Smuzhiyun break;
1086*4882a593Smuzhiyun }
1087*4882a593Smuzhiyun
1088*4882a593Smuzhiyun out:
1089*4882a593Smuzhiyun mutex_unlock(&(telm_conf->telem_trace_lock));
1090*4882a593Smuzhiyun return ret;
1091*4882a593Smuzhiyun }
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun static const struct telemetry_core_ops telm_pltops = {
1094*4882a593Smuzhiyun .get_trace_verbosity = telemetry_plt_get_trace_verbosity,
1095*4882a593Smuzhiyun .set_trace_verbosity = telemetry_plt_set_trace_verbosity,
1096*4882a593Smuzhiyun .set_sampling_period = telemetry_plt_set_sampling_period,
1097*4882a593Smuzhiyun .get_sampling_period = telemetry_plt_get_sampling_period,
1098*4882a593Smuzhiyun .raw_read_eventlog = telemetry_plt_raw_read_eventlog,
1099*4882a593Smuzhiyun .get_eventconfig = telemetry_plt_get_eventconfig,
1100*4882a593Smuzhiyun .update_events = telemetry_plt_update_events,
1101*4882a593Smuzhiyun .read_eventlog = telemetry_plt_read_eventlog,
1102*4882a593Smuzhiyun .reset_events = telemetry_plt_reset_events,
1103*4882a593Smuzhiyun .add_events = telemetry_plt_add_events,
1104*4882a593Smuzhiyun };
1105*4882a593Smuzhiyun
telemetry_pltdrv_probe(struct platform_device * pdev)1106*4882a593Smuzhiyun static int telemetry_pltdrv_probe(struct platform_device *pdev)
1107*4882a593Smuzhiyun {
1108*4882a593Smuzhiyun const struct x86_cpu_id *id;
1109*4882a593Smuzhiyun void __iomem *mem;
1110*4882a593Smuzhiyun int ret;
1111*4882a593Smuzhiyun
1112*4882a593Smuzhiyun id = x86_match_cpu(telemetry_cpu_ids);
1113*4882a593Smuzhiyun if (!id)
1114*4882a593Smuzhiyun return -ENODEV;
1115*4882a593Smuzhiyun
1116*4882a593Smuzhiyun telm_conf = (struct telemetry_plt_config *)id->driver_data;
1117*4882a593Smuzhiyun
1118*4882a593Smuzhiyun telm_conf->pmc = dev_get_drvdata(pdev->dev.parent);
1119*4882a593Smuzhiyun
1120*4882a593Smuzhiyun mem = devm_platform_ioremap_resource(pdev, 0);
1121*4882a593Smuzhiyun if (IS_ERR(mem))
1122*4882a593Smuzhiyun return PTR_ERR(mem);
1123*4882a593Smuzhiyun
1124*4882a593Smuzhiyun telm_conf->pss_config.regmap = mem;
1125*4882a593Smuzhiyun
1126*4882a593Smuzhiyun mem = devm_platform_ioremap_resource(pdev, 1);
1127*4882a593Smuzhiyun if (IS_ERR(mem))
1128*4882a593Smuzhiyun return PTR_ERR(mem);
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun telm_conf->ioss_config.regmap = mem;
1131*4882a593Smuzhiyun
1132*4882a593Smuzhiyun telm_conf->scu = devm_intel_scu_ipc_dev_get(&pdev->dev);
1133*4882a593Smuzhiyun if (!telm_conf->scu) {
1134*4882a593Smuzhiyun ret = -EPROBE_DEFER;
1135*4882a593Smuzhiyun goto out;
1136*4882a593Smuzhiyun }
1137*4882a593Smuzhiyun
1138*4882a593Smuzhiyun mutex_init(&telm_conf->telem_lock);
1139*4882a593Smuzhiyun mutex_init(&telm_conf->telem_trace_lock);
1140*4882a593Smuzhiyun
1141*4882a593Smuzhiyun ret = telemetry_setup(pdev);
1142*4882a593Smuzhiyun if (ret)
1143*4882a593Smuzhiyun goto out;
1144*4882a593Smuzhiyun
1145*4882a593Smuzhiyun ret = telemetry_set_pltdata(&telm_pltops, telm_conf);
1146*4882a593Smuzhiyun if (ret) {
1147*4882a593Smuzhiyun dev_err(&pdev->dev, "TELEMETRY Set Pltops Failed.\n");
1148*4882a593Smuzhiyun goto out;
1149*4882a593Smuzhiyun }
1150*4882a593Smuzhiyun
1151*4882a593Smuzhiyun return 0;
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun out:
1154*4882a593Smuzhiyun dev_err(&pdev->dev, "TELEMETRY Setup Failed.\n");
1155*4882a593Smuzhiyun
1156*4882a593Smuzhiyun return ret;
1157*4882a593Smuzhiyun }
1158*4882a593Smuzhiyun
telemetry_pltdrv_remove(struct platform_device * pdev)1159*4882a593Smuzhiyun static int telemetry_pltdrv_remove(struct platform_device *pdev)
1160*4882a593Smuzhiyun {
1161*4882a593Smuzhiyun telemetry_clear_pltdata();
1162*4882a593Smuzhiyun return 0;
1163*4882a593Smuzhiyun }
1164*4882a593Smuzhiyun
1165*4882a593Smuzhiyun static struct platform_driver telemetry_soc_driver = {
1166*4882a593Smuzhiyun .probe = telemetry_pltdrv_probe,
1167*4882a593Smuzhiyun .remove = telemetry_pltdrv_remove,
1168*4882a593Smuzhiyun .driver = {
1169*4882a593Smuzhiyun .name = DRIVER_NAME,
1170*4882a593Smuzhiyun },
1171*4882a593Smuzhiyun };
1172*4882a593Smuzhiyun
telemetry_module_init(void)1173*4882a593Smuzhiyun static int __init telemetry_module_init(void)
1174*4882a593Smuzhiyun {
1175*4882a593Smuzhiyun return platform_driver_register(&telemetry_soc_driver);
1176*4882a593Smuzhiyun }
1177*4882a593Smuzhiyun
telemetry_module_exit(void)1178*4882a593Smuzhiyun static void __exit telemetry_module_exit(void)
1179*4882a593Smuzhiyun {
1180*4882a593Smuzhiyun platform_driver_unregister(&telemetry_soc_driver);
1181*4882a593Smuzhiyun }
1182*4882a593Smuzhiyun
1183*4882a593Smuzhiyun device_initcall(telemetry_module_init);
1184*4882a593Smuzhiyun module_exit(telemetry_module_exit);
1185*4882a593Smuzhiyun
1186*4882a593Smuzhiyun MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
1187*4882a593Smuzhiyun MODULE_DESCRIPTION("Intel SoC Telemetry Platform Driver");
1188*4882a593Smuzhiyun MODULE_VERSION(DRIVER_VERSION);
1189*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
1190