Andy Shevchenko | 917f450 | 2018-09-26 18:27:40 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Intel SOC Telemetry debugfs Driver: Currently supports APL |
| 4 | * Copyright (c) 2015, Intel Corporation. |
| 5 | * All Rights Reserved. |
| 6 | * |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 7 | * This file provides the debugfs interfaces for telemetry. |
| 8 | * /sys/kernel/debug/telemetry/pss_info: Shows Primary Control Sub-Sys Counters |
| 9 | * /sys/kernel/debug/telemetry/ioss_info: Shows IO Sub-System Counters |
| 10 | * /sys/kernel/debug/telemetry/soc_states: Shows SoC State |
| 11 | * /sys/kernel/debug/telemetry/pss_trace_verbosity: Read and Change Tracing |
| 12 | * Verbosity via firmware |
| 13 | * /sys/kernel/debug/telemetry/ioss_race_verbosity: Write and Change Tracing |
| 14 | * Verbosity via firmware |
| 15 | */ |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 16 | #include <linux/debugfs.h> |
Rajneesh Bhardwaj | a5e5022 | 2017-10-10 15:35:19 +0530 | [diff] [blame] | 17 | #include <linux/device.h> |
Rajneesh Bhardwaj | a5e5022 | 2017-10-10 15:35:19 +0530 | [diff] [blame] | 18 | #include <linux/module.h> |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 19 | #include <linux/pci.h> |
Rajneesh Bhardwaj | a5e5022 | 2017-10-10 15:35:19 +0530 | [diff] [blame] | 20 | #include <linux/seq_file.h> |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 21 | #include <linux/suspend.h> |
| 22 | |
| 23 | #include <asm/cpu_device_id.h> |
Dave Hansen | 678dec0 | 2016-06-02 17:19:47 -0700 | [diff] [blame] | 24 | #include <asm/intel-family.h> |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 25 | #include <asm/intel_pmc_ipc.h> |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 26 | #include <asm/intel_telemetry.h> |
| 27 | |
Chakravarty, Souvik K | c622cbe | 2017-11-24 19:04:44 +0530 | [diff] [blame] | 28 | #define DRIVER_NAME "telemetry_soc_debugfs" |
| 29 | #define DRIVER_VERSION "1.0.0" |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 30 | |
| 31 | /* ApolloLake SoC Event-IDs */ |
| 32 | #define TELEM_APL_PSS_PSTATES_ID 0x2802 |
| 33 | #define TELEM_APL_PSS_IDLE_ID 0x2806 |
| 34 | #define TELEM_APL_PCS_IDLE_BLOCKED_ID 0x2C00 |
| 35 | #define TELEM_APL_PCS_S0IX_BLOCKED_ID 0x2C01 |
| 36 | #define TELEM_APL_PSS_WAKEUP_ID 0x2C02 |
| 37 | #define TELEM_APL_PSS_LTR_BLOCKING_ID 0x2C03 |
| 38 | |
| 39 | #define TELEM_APL_S0IX_TOTAL_OCC_ID 0x4000 |
| 40 | #define TELEM_APL_S0IX_SHLW_OCC_ID 0x4001 |
| 41 | #define TELEM_APL_S0IX_DEEP_OCC_ID 0x4002 |
| 42 | #define TELEM_APL_S0IX_TOTAL_RES_ID 0x4800 |
| 43 | #define TELEM_APL_S0IX_SHLW_RES_ID 0x4801 |
| 44 | #define TELEM_APL_S0IX_DEEP_RES_ID 0x4802 |
| 45 | #define TELEM_APL_D0IX_ID 0x581A |
| 46 | #define TELEM_APL_D3_ID 0x5819 |
| 47 | #define TELEM_APL_PG_ID 0x5818 |
| 48 | |
| 49 | #define TELEM_INFO_SRAMEVTS_MASK 0xFF00 |
| 50 | #define TELEM_INFO_SRAMEVTS_SHIFT 0x8 |
| 51 | #define TELEM_SSRAM_READ_TIMEOUT 10 |
| 52 | |
| 53 | #define TELEM_MASK_BIT 1 |
| 54 | #define TELEM_MASK_BYTE 0xFF |
| 55 | #define BYTES_PER_LONG 8 |
| 56 | #define TELEM_APL_MASK_PCS_STATE 0xF |
| 57 | |
| 58 | /* Max events in bitmap to check for */ |
| 59 | #define TELEM_PSS_IDLE_EVTS 25 |
| 60 | #define TELEM_PSS_IDLE_BLOCKED_EVTS 20 |
| 61 | #define TELEM_PSS_S0IX_BLOCKED_EVTS 20 |
| 62 | #define TELEM_PSS_S0IX_WAKEUP_EVTS 20 |
| 63 | #define TELEM_PSS_LTR_BLOCKING_EVTS 20 |
| 64 | #define TELEM_IOSS_DX_D0IX_EVTS 25 |
| 65 | #define TELEM_IOSS_PG_EVTS 30 |
| 66 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 67 | #define TELEM_DEBUGFS_CPU(model, data) \ |
Yu, Ong Hock | 08a2451 | 2016-06-23 14:59:58 +0800 | [diff] [blame] | 68 | { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&data} |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 69 | |
| 70 | #define TELEM_CHECK_AND_PARSE_EVTS(EVTID, EVTNUM, BUF, EVTLOG, EVTDAT, MASK) { \ |
| 71 | if (evtlog[index].telem_evtid == (EVTID)) { \ |
| 72 | for (idx = 0; idx < (EVTNUM); idx++) \ |
| 73 | (BUF)[idx] = ((EVTLOG) >> (EVTDAT)[idx].bit_pos) & \ |
| 74 | (MASK); \ |
| 75 | continue; \ |
| 76 | } \ |
| 77 | } |
| 78 | |
| 79 | #define TELEM_CHECK_AND_PARSE_CTRS(EVTID, CTR) { \ |
| 80 | if (evtlog[index].telem_evtid == (EVTID)) { \ |
| 81 | (CTR) = evtlog[index].telem_evtlog; \ |
| 82 | continue; \ |
| 83 | } \ |
| 84 | } |
| 85 | |
| 86 | static u8 suspend_prep_ok; |
| 87 | static u32 suspend_shlw_ctr_temp, suspend_deep_ctr_temp; |
| 88 | static u64 suspend_shlw_res_temp, suspend_deep_res_temp; |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 89 | |
| 90 | struct telemetry_susp_stats { |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 91 | u32 shlw_ctr; |
| 92 | u32 deep_ctr; |
| 93 | u64 shlw_res; |
| 94 | u64 deep_res; |
| 95 | }; |
| 96 | |
| 97 | /* Bitmap definitions for default counters in APL */ |
| 98 | struct telem_pss_idle_stateinfo { |
| 99 | const char *name; |
| 100 | u32 bit_pos; |
| 101 | }; |
| 102 | |
| 103 | static struct telem_pss_idle_stateinfo telem_apl_pss_idle_data[] = { |
| 104 | {"IA_CORE0_C1E", 0}, |
| 105 | {"IA_CORE1_C1E", 1}, |
| 106 | {"IA_CORE2_C1E", 2}, |
| 107 | {"IA_CORE3_C1E", 3}, |
| 108 | {"IA_CORE0_C6", 16}, |
| 109 | {"IA_CORE1_C6", 17}, |
| 110 | {"IA_CORE2_C6", 18}, |
| 111 | {"IA_CORE3_C6", 19}, |
| 112 | {"IA_MODULE0_C7", 32}, |
| 113 | {"IA_MODULE1_C7", 33}, |
| 114 | {"GT_RC6", 40}, |
| 115 | {"IUNIT_PROCESSING_IDLE", 41}, |
| 116 | {"FAR_MEM_IDLE", 43}, |
| 117 | {"DISPLAY_IDLE", 44}, |
| 118 | {"IUNIT_INPUT_SYSTEM_IDLE", 45}, |
| 119 | {"PCS_STATUS", 60}, |
| 120 | }; |
| 121 | |
| 122 | struct telem_pcs_blkd_info { |
| 123 | const char *name; |
| 124 | u32 bit_pos; |
| 125 | }; |
| 126 | |
| 127 | static struct telem_pcs_blkd_info telem_apl_pcs_idle_blkd_data[] = { |
| 128 | {"COMPUTE", 0}, |
| 129 | {"MISC", 8}, |
| 130 | {"MODULE_ACTIONS_PENDING", 16}, |
| 131 | {"LTR", 24}, |
| 132 | {"DISPLAY_WAKE", 32}, |
| 133 | {"ISP_WAKE", 40}, |
| 134 | {"PSF0_ACTIVE", 48}, |
| 135 | }; |
| 136 | |
| 137 | static struct telem_pcs_blkd_info telem_apl_pcs_s0ix_blkd_data[] = { |
| 138 | {"LTR", 0}, |
| 139 | {"IRTL", 8}, |
| 140 | {"WAKE_DEADLINE_PENDING", 16}, |
| 141 | {"DISPLAY", 24}, |
| 142 | {"ISP", 32}, |
| 143 | {"CORE", 40}, |
| 144 | {"PMC", 48}, |
| 145 | {"MISC", 56}, |
| 146 | }; |
| 147 | |
| 148 | struct telem_pss_ltr_info { |
| 149 | const char *name; |
| 150 | u32 bit_pos; |
| 151 | }; |
| 152 | |
| 153 | static struct telem_pss_ltr_info telem_apl_pss_ltr_data[] = { |
| 154 | {"CORE_ACTIVE", 0}, |
| 155 | {"MEM_UP", 8}, |
| 156 | {"DFX", 16}, |
| 157 | {"DFX_FORCE_LTR", 24}, |
| 158 | {"DISPLAY", 32}, |
| 159 | {"ISP", 40}, |
| 160 | {"SOUTH", 48}, |
| 161 | }; |
| 162 | |
| 163 | struct telem_pss_wakeup_info { |
| 164 | const char *name; |
| 165 | u32 bit_pos; |
| 166 | }; |
| 167 | |
| 168 | static struct telem_pss_wakeup_info telem_apl_pss_wakeup[] = { |
| 169 | {"IP_IDLE", 0}, |
| 170 | {"DISPLAY_WAKE", 8}, |
| 171 | {"VOLTAGE_REG_INT", 16}, |
| 172 | {"DROWSY_TIMER (HOTPLUG)", 24}, |
| 173 | {"CORE_WAKE", 32}, |
| 174 | {"MISC_S0IX", 40}, |
| 175 | {"MISC_ABORT", 56}, |
| 176 | }; |
| 177 | |
| 178 | struct telem_ioss_d0ix_stateinfo { |
| 179 | const char *name; |
| 180 | u32 bit_pos; |
| 181 | }; |
| 182 | |
| 183 | static struct telem_ioss_d0ix_stateinfo telem_apl_ioss_d0ix_data[] = { |
| 184 | {"CSE", 0}, |
| 185 | {"SCC2", 1}, |
| 186 | {"GMM", 2}, |
| 187 | {"XDCI", 3}, |
| 188 | {"XHCI", 4}, |
| 189 | {"ISH", 5}, |
| 190 | {"AVS", 6}, |
| 191 | {"PCIE0P1", 7}, |
| 192 | {"PECI0P0", 8}, |
| 193 | {"LPSS", 9}, |
| 194 | {"SCC", 10}, |
| 195 | {"PWM", 11}, |
| 196 | {"PCIE1_P3", 12}, |
| 197 | {"PCIE1_P2", 13}, |
| 198 | {"PCIE1_P1", 14}, |
| 199 | {"PCIE1_P0", 15}, |
| 200 | {"CNV", 16}, |
| 201 | {"SATA", 17}, |
| 202 | {"PRTC", 18}, |
| 203 | }; |
| 204 | |
| 205 | struct telem_ioss_pg_info { |
| 206 | const char *name; |
| 207 | u32 bit_pos; |
| 208 | }; |
| 209 | |
| 210 | static struct telem_ioss_pg_info telem_apl_ioss_pg_data[] = { |
| 211 | {"LPSS", 0}, |
| 212 | {"SCC", 1}, |
| 213 | {"P2SB", 2}, |
| 214 | {"SCC2", 3}, |
| 215 | {"GMM", 4}, |
| 216 | {"PCIE0", 5}, |
| 217 | {"XDCI", 6}, |
| 218 | {"xHCI", 7}, |
| 219 | {"CSE", 8}, |
| 220 | {"SPI", 9}, |
| 221 | {"AVSPGD4", 10}, |
| 222 | {"AVSPGD3", 11}, |
| 223 | {"AVSPGD2", 12}, |
| 224 | {"AVSPGD1", 13}, |
| 225 | {"ISH", 14}, |
| 226 | {"EXI", 15}, |
| 227 | {"NPKVRC", 16}, |
| 228 | {"NPKVNN", 17}, |
| 229 | {"CUNIT", 18}, |
| 230 | {"FUSE_CTRL", 19}, |
| 231 | {"PCIE1", 20}, |
| 232 | {"CNV", 21}, |
| 233 | {"LPC", 22}, |
| 234 | {"SATA", 23}, |
| 235 | {"SMB", 24}, |
| 236 | {"PRTC", 25}, |
| 237 | }; |
| 238 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 239 | struct telemetry_debugfs_conf { |
| 240 | struct telemetry_susp_stats suspend_stats; |
| 241 | struct dentry *telemetry_dbg_dir; |
| 242 | |
| 243 | /* Bitmap Data */ |
| 244 | struct telem_ioss_d0ix_stateinfo *ioss_d0ix_data; |
| 245 | struct telem_pss_idle_stateinfo *pss_idle_data; |
| 246 | struct telem_pcs_blkd_info *pcs_idle_blkd_data; |
| 247 | struct telem_pcs_blkd_info *pcs_s0ix_blkd_data; |
| 248 | struct telem_pss_wakeup_info *pss_wakeup; |
| 249 | struct telem_pss_ltr_info *pss_ltr_data; |
| 250 | struct telem_ioss_pg_info *ioss_pg_data; |
| 251 | u8 pcs_idle_blkd_evts; |
| 252 | u8 pcs_s0ix_blkd_evts; |
| 253 | u8 pss_wakeup_evts; |
| 254 | u8 pss_idle_evts; |
| 255 | u8 pss_ltr_evts; |
| 256 | u8 ioss_d0ix_evts; |
| 257 | u8 ioss_pg_evts; |
| 258 | |
| 259 | /* IDs */ |
| 260 | u16 pss_ltr_blocking_id; |
| 261 | u16 pcs_idle_blkd_id; |
| 262 | u16 pcs_s0ix_blkd_id; |
| 263 | u16 s0ix_total_occ_id; |
| 264 | u16 s0ix_shlw_occ_id; |
| 265 | u16 s0ix_deep_occ_id; |
| 266 | u16 s0ix_total_res_id; |
| 267 | u16 s0ix_shlw_res_id; |
| 268 | u16 s0ix_deep_res_id; |
| 269 | u16 pss_wakeup_id; |
| 270 | u16 ioss_d0ix_id; |
| 271 | u16 pstates_id; |
| 272 | u16 pss_idle_id; |
| 273 | u16 ioss_d3_id; |
| 274 | u16 ioss_pg_id; |
| 275 | }; |
| 276 | |
| 277 | static struct telemetry_debugfs_conf *debugfs_conf; |
| 278 | |
| 279 | static struct telemetry_debugfs_conf telem_apl_debugfs_conf = { |
| 280 | .pss_idle_data = telem_apl_pss_idle_data, |
| 281 | .pcs_idle_blkd_data = telem_apl_pcs_idle_blkd_data, |
| 282 | .pcs_s0ix_blkd_data = telem_apl_pcs_s0ix_blkd_data, |
| 283 | .pss_ltr_data = telem_apl_pss_ltr_data, |
| 284 | .pss_wakeup = telem_apl_pss_wakeup, |
| 285 | .ioss_d0ix_data = telem_apl_ioss_d0ix_data, |
| 286 | .ioss_pg_data = telem_apl_ioss_pg_data, |
| 287 | |
Allen Pais | ae11c5b | 2017-09-13 16:29:31 +0530 | [diff] [blame] | 288 | .pss_idle_evts = ARRAY_SIZE(telem_apl_pss_idle_data), |
| 289 | .pcs_idle_blkd_evts = ARRAY_SIZE(telem_apl_pcs_idle_blkd_data), |
| 290 | .pcs_s0ix_blkd_evts = ARRAY_SIZE(telem_apl_pcs_s0ix_blkd_data), |
| 291 | .pss_ltr_evts = ARRAY_SIZE(telem_apl_pss_ltr_data), |
| 292 | .pss_wakeup_evts = ARRAY_SIZE(telem_apl_pss_wakeup), |
| 293 | .ioss_d0ix_evts = ARRAY_SIZE(telem_apl_ioss_d0ix_data), |
| 294 | .ioss_pg_evts = ARRAY_SIZE(telem_apl_ioss_pg_data), |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 295 | |
| 296 | .pstates_id = TELEM_APL_PSS_PSTATES_ID, |
| 297 | .pss_idle_id = TELEM_APL_PSS_IDLE_ID, |
| 298 | .pcs_idle_blkd_id = TELEM_APL_PCS_IDLE_BLOCKED_ID, |
| 299 | .pcs_s0ix_blkd_id = TELEM_APL_PCS_S0IX_BLOCKED_ID, |
| 300 | .pss_wakeup_id = TELEM_APL_PSS_WAKEUP_ID, |
| 301 | .pss_ltr_blocking_id = TELEM_APL_PSS_LTR_BLOCKING_ID, |
| 302 | .s0ix_total_occ_id = TELEM_APL_S0IX_TOTAL_OCC_ID, |
| 303 | .s0ix_shlw_occ_id = TELEM_APL_S0IX_SHLW_OCC_ID, |
| 304 | .s0ix_deep_occ_id = TELEM_APL_S0IX_DEEP_OCC_ID, |
| 305 | .s0ix_total_res_id = TELEM_APL_S0IX_TOTAL_RES_ID, |
| 306 | .s0ix_shlw_res_id = TELEM_APL_S0IX_SHLW_RES_ID, |
| 307 | .s0ix_deep_res_id = TELEM_APL_S0IX_DEEP_RES_ID, |
| 308 | .ioss_d0ix_id = TELEM_APL_D0IX_ID, |
| 309 | .ioss_d3_id = TELEM_APL_D3_ID, |
| 310 | .ioss_pg_id = TELEM_APL_PG_ID, |
| 311 | }; |
| 312 | |
| 313 | static const struct x86_cpu_id telemetry_debugfs_cpu_ids[] = { |
Dave Hansen | 678dec0 | 2016-06-02 17:19:47 -0700 | [diff] [blame] | 314 | TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_debugfs_conf), |
Rajneesh Bhardwaj | 54949a6 | 2017-07-20 19:51:13 +0530 | [diff] [blame] | 315 | TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GEMINI_LAKE, telem_apl_debugfs_conf), |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 316 | {} |
| 317 | }; |
| 318 | |
| 319 | MODULE_DEVICE_TABLE(x86cpu, telemetry_debugfs_cpu_ids); |
| 320 | |
| 321 | static int telemetry_debugfs_check_evts(void) |
| 322 | { |
| 323 | if ((debugfs_conf->pss_idle_evts > TELEM_PSS_IDLE_EVTS) || |
| 324 | (debugfs_conf->pcs_idle_blkd_evts > TELEM_PSS_IDLE_BLOCKED_EVTS) || |
| 325 | (debugfs_conf->pcs_s0ix_blkd_evts > TELEM_PSS_S0IX_BLOCKED_EVTS) || |
| 326 | (debugfs_conf->pss_ltr_evts > TELEM_PSS_LTR_BLOCKING_EVTS) || |
| 327 | (debugfs_conf->pss_wakeup_evts > TELEM_PSS_S0IX_WAKEUP_EVTS) || |
| 328 | (debugfs_conf->ioss_d0ix_evts > TELEM_IOSS_DX_D0IX_EVTS) || |
| 329 | (debugfs_conf->ioss_pg_evts > TELEM_IOSS_PG_EVTS)) |
| 330 | return -EINVAL; |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | static int telem_pss_states_show(struct seq_file *s, void *unused) |
| 336 | { |
| 337 | struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS]; |
| 338 | struct telemetry_debugfs_conf *conf = debugfs_conf; |
| 339 | const char *name[TELEM_MAX_OS_ALLOCATED_EVENTS]; |
| 340 | u32 pcs_idle_blkd[TELEM_PSS_IDLE_BLOCKED_EVTS], |
| 341 | pcs_s0ix_blkd[TELEM_PSS_S0IX_BLOCKED_EVTS], |
| 342 | pss_s0ix_wakeup[TELEM_PSS_S0IX_WAKEUP_EVTS], |
| 343 | pss_ltr_blkd[TELEM_PSS_LTR_BLOCKING_EVTS], |
| 344 | pss_idle[TELEM_PSS_IDLE_EVTS]; |
| 345 | int index, idx, ret, err = 0; |
| 346 | u64 pstates = 0; |
| 347 | |
| 348 | ret = telemetry_read_eventlog(TELEM_PSS, evtlog, |
| 349 | TELEM_MAX_OS_ALLOCATED_EVENTS); |
| 350 | if (ret < 0) |
| 351 | return ret; |
| 352 | |
| 353 | err = telemetry_get_evtname(TELEM_PSS, name, |
| 354 | TELEM_MAX_OS_ALLOCATED_EVENTS); |
| 355 | if (err < 0) |
| 356 | return err; |
| 357 | |
| 358 | seq_puts(s, "\n----------------------------------------------------\n"); |
| 359 | seq_puts(s, "\tPSS TELEM EVENTLOG (Residency = field/19.2 us\n"); |
| 360 | seq_puts(s, "----------------------------------------------------\n"); |
| 361 | for (index = 0; index < ret; index++) { |
| 362 | seq_printf(s, "%-32s %llu\n", |
| 363 | name[index], evtlog[index].telem_evtlog); |
| 364 | |
| 365 | /* Fetch PSS IDLE State */ |
| 366 | if (evtlog[index].telem_evtid == conf->pss_idle_id) { |
| 367 | pss_idle[conf->pss_idle_evts - 1] = |
| 368 | (evtlog[index].telem_evtlog >> |
| 369 | conf->pss_idle_data[conf->pss_idle_evts - 1].bit_pos) & |
| 370 | TELEM_APL_MASK_PCS_STATE; |
| 371 | } |
| 372 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 373 | TELEM_CHECK_AND_PARSE_EVTS(conf->pss_idle_id, |
| 374 | conf->pss_idle_evts - 1, |
| 375 | pss_idle, evtlog[index].telem_evtlog, |
| 376 | conf->pss_idle_data, TELEM_MASK_BIT); |
| 377 | |
| 378 | TELEM_CHECK_AND_PARSE_EVTS(conf->pcs_idle_blkd_id, |
| 379 | conf->pcs_idle_blkd_evts, |
| 380 | pcs_idle_blkd, |
| 381 | evtlog[index].telem_evtlog, |
| 382 | conf->pcs_idle_blkd_data, |
| 383 | TELEM_MASK_BYTE); |
| 384 | |
| 385 | TELEM_CHECK_AND_PARSE_EVTS(conf->pcs_s0ix_blkd_id, |
| 386 | conf->pcs_s0ix_blkd_evts, |
| 387 | pcs_s0ix_blkd, |
| 388 | evtlog[index].telem_evtlog, |
| 389 | conf->pcs_s0ix_blkd_data, |
| 390 | TELEM_MASK_BYTE); |
| 391 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 392 | TELEM_CHECK_AND_PARSE_EVTS(conf->pss_wakeup_id, |
| 393 | conf->pss_wakeup_evts, |
| 394 | pss_s0ix_wakeup, |
| 395 | evtlog[index].telem_evtlog, |
| 396 | conf->pss_wakeup, TELEM_MASK_BYTE); |
| 397 | |
| 398 | TELEM_CHECK_AND_PARSE_EVTS(conf->pss_ltr_blocking_id, |
| 399 | conf->pss_ltr_evts, pss_ltr_blkd, |
| 400 | evtlog[index].telem_evtlog, |
| 401 | conf->pss_ltr_data, TELEM_MASK_BYTE); |
| 402 | |
| 403 | if (evtlog[index].telem_evtid == debugfs_conf->pstates_id) |
| 404 | pstates = evtlog[index].telem_evtlog; |
| 405 | } |
| 406 | |
| 407 | seq_puts(s, "\n--------------------------------------\n"); |
| 408 | seq_puts(s, "PStates\n"); |
| 409 | seq_puts(s, "--------------------------------------\n"); |
| 410 | seq_puts(s, "Domain\t\t\t\tFreq(Mhz)\n"); |
| 411 | seq_printf(s, " IA\t\t\t\t %llu\n GT\t\t\t\t %llu\n", |
| 412 | (pstates & TELEM_MASK_BYTE)*100, |
| 413 | ((pstates >> 8) & TELEM_MASK_BYTE)*50/3); |
| 414 | |
| 415 | seq_printf(s, " IUNIT\t\t\t\t %llu\n SA\t\t\t\t %llu\n", |
| 416 | ((pstates >> 16) & TELEM_MASK_BYTE)*25, |
| 417 | ((pstates >> 24) & TELEM_MASK_BYTE)*50/3); |
| 418 | |
| 419 | seq_puts(s, "\n--------------------------------------\n"); |
| 420 | seq_puts(s, "PSS IDLE Status\n"); |
| 421 | seq_puts(s, "--------------------------------------\n"); |
| 422 | seq_puts(s, "Device\t\t\t\t\tIDLE\n"); |
| 423 | for (index = 0; index < debugfs_conf->pss_idle_evts; index++) { |
| 424 | seq_printf(s, "%-32s\t%u\n", |
| 425 | debugfs_conf->pss_idle_data[index].name, |
| 426 | pss_idle[index]); |
| 427 | } |
| 428 | |
| 429 | seq_puts(s, "\n--------------------------------------\n"); |
| 430 | seq_puts(s, "PSS Idle blkd Status (~1ms saturating bucket)\n"); |
| 431 | seq_puts(s, "--------------------------------------\n"); |
| 432 | seq_puts(s, "Blocker\t\t\t\t\tCount\n"); |
| 433 | for (index = 0; index < debugfs_conf->pcs_idle_blkd_evts; index++) { |
| 434 | seq_printf(s, "%-32s\t%u\n", |
| 435 | debugfs_conf->pcs_idle_blkd_data[index].name, |
| 436 | pcs_idle_blkd[index]); |
| 437 | } |
| 438 | |
| 439 | seq_puts(s, "\n--------------------------------------\n"); |
| 440 | seq_puts(s, "PSS S0ix blkd Status (~1ms saturating bucket)\n"); |
| 441 | seq_puts(s, "--------------------------------------\n"); |
| 442 | seq_puts(s, "Blocker\t\t\t\t\tCount\n"); |
| 443 | for (index = 0; index < debugfs_conf->pcs_s0ix_blkd_evts; index++) { |
| 444 | seq_printf(s, "%-32s\t%u\n", |
| 445 | debugfs_conf->pcs_s0ix_blkd_data[index].name, |
| 446 | pcs_s0ix_blkd[index]); |
| 447 | } |
| 448 | |
| 449 | seq_puts(s, "\n--------------------------------------\n"); |
| 450 | seq_puts(s, "LTR Blocking Status (~1ms saturating bucket)\n"); |
| 451 | seq_puts(s, "--------------------------------------\n"); |
| 452 | seq_puts(s, "Blocker\t\t\t\t\tCount\n"); |
| 453 | for (index = 0; index < debugfs_conf->pss_ltr_evts; index++) { |
| 454 | seq_printf(s, "%-32s\t%u\n", |
| 455 | debugfs_conf->pss_ltr_data[index].name, |
| 456 | pss_s0ix_wakeup[index]); |
| 457 | } |
| 458 | |
| 459 | seq_puts(s, "\n--------------------------------------\n"); |
| 460 | seq_puts(s, "Wakes Status (~1ms saturating bucket)\n"); |
| 461 | seq_puts(s, "--------------------------------------\n"); |
| 462 | seq_puts(s, "Wakes\t\t\t\t\tCount\n"); |
| 463 | for (index = 0; index < debugfs_conf->pss_wakeup_evts; index++) { |
| 464 | seq_printf(s, "%-32s\t%u\n", |
| 465 | debugfs_conf->pss_wakeup[index].name, |
| 466 | pss_ltr_blkd[index]); |
| 467 | } |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | static int telem_pss_state_open(struct inode *inode, struct file *file) |
| 473 | { |
| 474 | return single_open(file, telem_pss_states_show, inode->i_private); |
| 475 | } |
| 476 | |
| 477 | static const struct file_operations telem_pss_ops = { |
| 478 | .open = telem_pss_state_open, |
| 479 | .read = seq_read, |
| 480 | .llseek = seq_lseek, |
| 481 | .release = single_release, |
| 482 | }; |
| 483 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 484 | static int telem_ioss_states_show(struct seq_file *s, void *unused) |
| 485 | { |
| 486 | struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS]; |
| 487 | const char *name[TELEM_MAX_OS_ALLOCATED_EVENTS]; |
| 488 | int index, ret, err; |
| 489 | |
| 490 | ret = telemetry_read_eventlog(TELEM_IOSS, evtlog, |
| 491 | TELEM_MAX_OS_ALLOCATED_EVENTS); |
| 492 | if (ret < 0) |
| 493 | return ret; |
| 494 | |
| 495 | err = telemetry_get_evtname(TELEM_IOSS, name, |
| 496 | TELEM_MAX_OS_ALLOCATED_EVENTS); |
| 497 | if (err < 0) |
| 498 | return err; |
| 499 | |
| 500 | seq_puts(s, "--------------------------------------\n"); |
| 501 | seq_puts(s, "\tI0SS TELEMETRY EVENTLOG\n"); |
| 502 | seq_puts(s, "--------------------------------------\n"); |
| 503 | for (index = 0; index < ret; index++) { |
| 504 | seq_printf(s, "%-32s 0x%llx\n", |
| 505 | name[index], evtlog[index].telem_evtlog); |
| 506 | } |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | static int telem_ioss_state_open(struct inode *inode, struct file *file) |
| 512 | { |
| 513 | return single_open(file, telem_ioss_states_show, inode->i_private); |
| 514 | } |
| 515 | |
| 516 | static const struct file_operations telem_ioss_ops = { |
| 517 | .open = telem_ioss_state_open, |
| 518 | .read = seq_read, |
| 519 | .llseek = seq_lseek, |
| 520 | .release = single_release, |
| 521 | }; |
| 522 | |
| 523 | static int telem_soc_states_show(struct seq_file *s, void *unused) |
| 524 | { |
| 525 | u32 d3_sts[TELEM_IOSS_DX_D0IX_EVTS], d0ix_sts[TELEM_IOSS_DX_D0IX_EVTS]; |
| 526 | u32 pg_sts[TELEM_IOSS_PG_EVTS], pss_idle[TELEM_PSS_IDLE_EVTS]; |
| 527 | struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS]; |
| 528 | u32 s0ix_total_ctr = 0, s0ix_shlw_ctr = 0, s0ix_deep_ctr = 0; |
| 529 | u64 s0ix_total_res = 0, s0ix_shlw_res = 0, s0ix_deep_res = 0; |
| 530 | struct telemetry_debugfs_conf *conf = debugfs_conf; |
| 531 | struct pci_dev *dev = NULL; |
| 532 | int index, idx, ret; |
| 533 | u32 d3_state; |
| 534 | u16 pmcsr; |
| 535 | |
| 536 | ret = telemetry_read_eventlog(TELEM_IOSS, evtlog, |
| 537 | TELEM_MAX_OS_ALLOCATED_EVENTS); |
| 538 | if (ret < 0) |
| 539 | return ret; |
| 540 | |
| 541 | for (index = 0; index < ret; index++) { |
| 542 | TELEM_CHECK_AND_PARSE_EVTS(conf->ioss_d3_id, |
| 543 | conf->ioss_d0ix_evts, |
| 544 | d3_sts, evtlog[index].telem_evtlog, |
| 545 | conf->ioss_d0ix_data, |
| 546 | TELEM_MASK_BIT); |
| 547 | |
| 548 | TELEM_CHECK_AND_PARSE_EVTS(conf->ioss_pg_id, conf->ioss_pg_evts, |
| 549 | pg_sts, evtlog[index].telem_evtlog, |
| 550 | conf->ioss_pg_data, TELEM_MASK_BIT); |
| 551 | |
| 552 | TELEM_CHECK_AND_PARSE_EVTS(conf->ioss_d0ix_id, |
| 553 | conf->ioss_d0ix_evts, |
| 554 | d0ix_sts, evtlog[index].telem_evtlog, |
| 555 | conf->ioss_d0ix_data, |
| 556 | TELEM_MASK_BIT); |
| 557 | |
| 558 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_total_occ_id, |
| 559 | s0ix_total_ctr); |
| 560 | |
| 561 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id, |
| 562 | s0ix_shlw_ctr); |
| 563 | |
| 564 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id, |
| 565 | s0ix_deep_ctr); |
| 566 | |
| 567 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_total_res_id, |
| 568 | s0ix_total_res); |
| 569 | |
| 570 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id, |
| 571 | s0ix_shlw_res); |
| 572 | |
| 573 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id, |
| 574 | s0ix_deep_res); |
| 575 | } |
| 576 | |
| 577 | seq_puts(s, "\n---------------------------------------------------\n"); |
| 578 | seq_puts(s, "S0IX Type\t\t\t Occurrence\t\t Residency(us)\n"); |
| 579 | seq_puts(s, "---------------------------------------------------\n"); |
| 580 | |
| 581 | seq_printf(s, "S0IX Shallow\t\t\t %10u\t %10llu\n", |
| 582 | s0ix_shlw_ctr - |
Chakravarty, Souvik K | ffd623d | 2017-11-24 19:04:43 +0530 | [diff] [blame] | 583 | conf->suspend_stats.shlw_ctr, |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 584 | (u64)((s0ix_shlw_res - |
Chakravarty, Souvik K | ffd623d | 2017-11-24 19:04:43 +0530 | [diff] [blame] | 585 | conf->suspend_stats.shlw_res)*10/192)); |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 586 | |
| 587 | seq_printf(s, "S0IX Deep\t\t\t %10u\t %10llu\n", |
| 588 | s0ix_deep_ctr - |
Chakravarty, Souvik K | ffd623d | 2017-11-24 19:04:43 +0530 | [diff] [blame] | 589 | conf->suspend_stats.deep_ctr, |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 590 | (u64)((s0ix_deep_res - |
Chakravarty, Souvik K | ffd623d | 2017-11-24 19:04:43 +0530 | [diff] [blame] | 591 | conf->suspend_stats.deep_res)*10/192)); |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 592 | |
| 593 | seq_printf(s, "Suspend(With S0ixShallow)\t %10u\t %10llu\n", |
| 594 | conf->suspend_stats.shlw_ctr, |
| 595 | (u64)(conf->suspend_stats.shlw_res*10)/192); |
| 596 | |
| 597 | seq_printf(s, "Suspend(With S0ixDeep)\t\t %10u\t %10llu\n", |
| 598 | conf->suspend_stats.deep_ctr, |
| 599 | (u64)(conf->suspend_stats.deep_res*10)/192); |
| 600 | |
Chakravarty, Souvik K | ffd623d | 2017-11-24 19:04:43 +0530 | [diff] [blame] | 601 | seq_printf(s, "TOTAL S0IX\t\t\t %10u\t %10llu\n", s0ix_total_ctr, |
Chakravarty, Souvik K | c622cbe | 2017-11-24 19:04:44 +0530 | [diff] [blame] | 602 | (u64)(s0ix_total_res*10/192)); |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 603 | seq_puts(s, "\n-------------------------------------------------\n"); |
| 604 | seq_puts(s, "\t\tDEVICE STATES\n"); |
| 605 | seq_puts(s, "-------------------------------------------------\n"); |
| 606 | |
| 607 | for_each_pci_dev(dev) { |
| 608 | pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); |
| 609 | d3_state = ((pmcsr & PCI_PM_CTRL_STATE_MASK) == |
| 610 | (__force int)PCI_D3hot) ? 1 : 0; |
| 611 | |
| 612 | seq_printf(s, "pci %04x %04X %s %20.20s: ", |
| 613 | dev->vendor, dev->device, dev_name(&dev->dev), |
| 614 | dev_driver_string(&dev->dev)); |
| 615 | seq_printf(s, " d3:%x\n", d3_state); |
| 616 | } |
| 617 | |
| 618 | seq_puts(s, "\n--------------------------------------\n"); |
| 619 | seq_puts(s, "D3/D0i3 Status\n"); |
| 620 | seq_puts(s, "--------------------------------------\n"); |
| 621 | seq_puts(s, "Block\t\t D3\t D0i3\n"); |
| 622 | for (index = 0; index < conf->ioss_d0ix_evts; index++) { |
| 623 | seq_printf(s, "%-10s\t %u\t %u\n", |
| 624 | conf->ioss_d0ix_data[index].name, |
| 625 | d3_sts[index], d0ix_sts[index]); |
| 626 | } |
| 627 | |
| 628 | seq_puts(s, "\n--------------------------------------\n"); |
| 629 | seq_puts(s, "South Complex PowerGate Status\n"); |
| 630 | seq_puts(s, "--------------------------------------\n"); |
| 631 | seq_puts(s, "Device\t\t PG\n"); |
| 632 | for (index = 0; index < conf->ioss_pg_evts; index++) { |
| 633 | seq_printf(s, "%-10s\t %u\n", |
| 634 | conf->ioss_pg_data[index].name, |
| 635 | pg_sts[index]); |
| 636 | } |
| 637 | |
| 638 | evtlog->telem_evtid = conf->pss_idle_id; |
| 639 | ret = telemetry_read_events(TELEM_PSS, evtlog, 1); |
| 640 | if (ret < 0) |
| 641 | return ret; |
| 642 | |
| 643 | seq_puts(s, "\n-----------------------------------------\n"); |
| 644 | seq_puts(s, "North Idle Status\n"); |
| 645 | seq_puts(s, "-----------------------------------------\n"); |
| 646 | for (idx = 0; idx < conf->pss_idle_evts - 1; idx++) { |
| 647 | pss_idle[idx] = (evtlog->telem_evtlog >> |
| 648 | conf->pss_idle_data[idx].bit_pos) & |
| 649 | TELEM_MASK_BIT; |
| 650 | } |
| 651 | |
| 652 | pss_idle[idx] = (evtlog->telem_evtlog >> |
| 653 | conf->pss_idle_data[idx].bit_pos) & |
| 654 | TELEM_APL_MASK_PCS_STATE; |
| 655 | |
| 656 | for (index = 0; index < conf->pss_idle_evts; index++) { |
| 657 | seq_printf(s, "%-30s %u\n", |
| 658 | conf->pss_idle_data[index].name, |
| 659 | pss_idle[index]); |
| 660 | } |
| 661 | |
| 662 | seq_puts(s, "\nPCS_STATUS Code\n"); |
| 663 | seq_puts(s, "0:C0 1:C1 2:C1_DN_WT_DEV 3:C2 4:C2_WT_DE_MEM_UP\n"); |
| 664 | seq_puts(s, "5:C2_WT_DE_MEM_DOWN 6:C2_UP_WT_DEV 7:C2_DN 8:C2_VOA\n"); |
| 665 | seq_puts(s, "9:C2_VOA_UP 10:S0IX_PRE 11:S0IX\n"); |
| 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | static int telem_soc_state_open(struct inode *inode, struct file *file) |
| 671 | { |
| 672 | return single_open(file, telem_soc_states_show, inode->i_private); |
| 673 | } |
| 674 | |
| 675 | static const struct file_operations telem_socstate_ops = { |
| 676 | .open = telem_soc_state_open, |
| 677 | .read = seq_read, |
| 678 | .llseek = seq_lseek, |
| 679 | .release = single_release, |
| 680 | }; |
| 681 | |
Rajneesh Bhardwaj | bc8c47a | 2017-06-23 22:22:35 +0530 | [diff] [blame] | 682 | static int telem_s0ix_res_get(void *data, u64 *val) |
| 683 | { |
| 684 | u64 s0ix_total_res; |
| 685 | int ret; |
| 686 | |
| 687 | ret = intel_pmc_s0ix_counter_read(&s0ix_total_res); |
| 688 | if (ret) { |
| 689 | pr_err("Failed to read S0ix residency"); |
| 690 | return ret; |
| 691 | } |
| 692 | |
| 693 | *val = s0ix_total_res; |
| 694 | |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | DEFINE_DEBUGFS_ATTRIBUTE(telem_s0ix_fops, telem_s0ix_res_get, NULL, "%llu\n"); |
| 699 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 700 | static int telem_pss_trc_verb_show(struct seq_file *s, void *unused) |
| 701 | { |
| 702 | u32 verbosity; |
| 703 | int err; |
| 704 | |
| 705 | err = telemetry_get_trace_verbosity(TELEM_PSS, &verbosity); |
| 706 | if (err) { |
| 707 | pr_err("Get PSS Trace Verbosity Failed with Error %d\n", err); |
| 708 | return -EFAULT; |
| 709 | } |
| 710 | |
| 711 | seq_printf(s, "PSS Trace Verbosity %u\n", verbosity); |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static ssize_t telem_pss_trc_verb_write(struct file *file, |
| 716 | const char __user *userbuf, |
| 717 | size_t count, loff_t *ppos) |
| 718 | { |
| 719 | u32 verbosity; |
| 720 | int err; |
| 721 | |
| 722 | if (kstrtou32_from_user(userbuf, count, 0, &verbosity)) |
| 723 | return -EFAULT; |
| 724 | |
| 725 | err = telemetry_set_trace_verbosity(TELEM_PSS, verbosity); |
| 726 | if (err) { |
| 727 | pr_err("Changing PSS Trace Verbosity Failed. Error %d\n", err); |
| 728 | count = err; |
| 729 | } |
| 730 | |
| 731 | return count; |
| 732 | } |
| 733 | |
| 734 | static int telem_pss_trc_verb_open(struct inode *inode, struct file *file) |
| 735 | { |
| 736 | return single_open(file, telem_pss_trc_verb_show, inode->i_private); |
| 737 | } |
| 738 | |
| 739 | static const struct file_operations telem_pss_trc_verb_ops = { |
| 740 | .open = telem_pss_trc_verb_open, |
| 741 | .read = seq_read, |
| 742 | .write = telem_pss_trc_verb_write, |
| 743 | .llseek = seq_lseek, |
| 744 | .release = single_release, |
| 745 | }; |
| 746 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 747 | static int telem_ioss_trc_verb_show(struct seq_file *s, void *unused) |
| 748 | { |
| 749 | u32 verbosity; |
| 750 | int err; |
| 751 | |
| 752 | err = telemetry_get_trace_verbosity(TELEM_IOSS, &verbosity); |
| 753 | if (err) { |
| 754 | pr_err("Get IOSS Trace Verbosity Failed with Error %d\n", err); |
| 755 | return -EFAULT; |
| 756 | } |
| 757 | |
| 758 | seq_printf(s, "IOSS Trace Verbosity %u\n", verbosity); |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | static ssize_t telem_ioss_trc_verb_write(struct file *file, |
| 763 | const char __user *userbuf, |
| 764 | size_t count, loff_t *ppos) |
| 765 | { |
| 766 | u32 verbosity; |
| 767 | int err; |
| 768 | |
| 769 | if (kstrtou32_from_user(userbuf, count, 0, &verbosity)) |
| 770 | return -EFAULT; |
| 771 | |
| 772 | err = telemetry_set_trace_verbosity(TELEM_IOSS, verbosity); |
| 773 | if (err) { |
| 774 | pr_err("Changing IOSS Trace Verbosity Failed. Error %d\n", err); |
| 775 | count = err; |
| 776 | } |
| 777 | |
| 778 | return count; |
| 779 | } |
| 780 | |
| 781 | static int telem_ioss_trc_verb_open(struct inode *inode, struct file *file) |
| 782 | { |
| 783 | return single_open(file, telem_ioss_trc_verb_show, inode->i_private); |
| 784 | } |
| 785 | |
| 786 | static const struct file_operations telem_ioss_trc_verb_ops = { |
| 787 | .open = telem_ioss_trc_verb_open, |
| 788 | .read = seq_read, |
| 789 | .write = telem_ioss_trc_verb_write, |
| 790 | .llseek = seq_lseek, |
| 791 | .release = single_release, |
| 792 | }; |
| 793 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 794 | static int pm_suspend_prep_cb(void) |
| 795 | { |
| 796 | struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS]; |
| 797 | struct telemetry_debugfs_conf *conf = debugfs_conf; |
| 798 | int ret, index; |
| 799 | |
| 800 | ret = telemetry_raw_read_eventlog(TELEM_IOSS, evtlog, |
| 801 | TELEM_MAX_OS_ALLOCATED_EVENTS); |
| 802 | if (ret < 0) { |
| 803 | suspend_prep_ok = 0; |
| 804 | goto out; |
| 805 | } |
| 806 | |
| 807 | for (index = 0; index < ret; index++) { |
| 808 | |
| 809 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id, |
| 810 | suspend_shlw_ctr_temp); |
| 811 | |
| 812 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id, |
| 813 | suspend_deep_ctr_temp); |
| 814 | |
| 815 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id, |
| 816 | suspend_shlw_res_temp); |
| 817 | |
| 818 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id, |
| 819 | suspend_deep_res_temp); |
| 820 | } |
| 821 | suspend_prep_ok = 1; |
| 822 | out: |
| 823 | return NOTIFY_OK; |
| 824 | } |
| 825 | |
| 826 | static int pm_suspend_exit_cb(void) |
| 827 | { |
| 828 | struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS]; |
| 829 | static u32 suspend_shlw_ctr_exit, suspend_deep_ctr_exit; |
| 830 | static u64 suspend_shlw_res_exit, suspend_deep_res_exit; |
| 831 | struct telemetry_debugfs_conf *conf = debugfs_conf; |
| 832 | int ret, index; |
| 833 | |
| 834 | if (!suspend_prep_ok) |
| 835 | goto out; |
| 836 | |
| 837 | ret = telemetry_raw_read_eventlog(TELEM_IOSS, evtlog, |
| 838 | TELEM_MAX_OS_ALLOCATED_EVENTS); |
| 839 | if (ret < 0) |
| 840 | goto out; |
| 841 | |
| 842 | for (index = 0; index < ret; index++) { |
| 843 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id, |
| 844 | suspend_shlw_ctr_exit); |
| 845 | |
| 846 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id, |
| 847 | suspend_deep_ctr_exit); |
| 848 | |
| 849 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id, |
| 850 | suspend_shlw_res_exit); |
| 851 | |
| 852 | TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id, |
| 853 | suspend_deep_res_exit); |
| 854 | } |
| 855 | |
| 856 | if ((suspend_shlw_ctr_exit < suspend_shlw_ctr_temp) || |
| 857 | (suspend_deep_ctr_exit < suspend_deep_ctr_temp) || |
| 858 | (suspend_shlw_res_exit < suspend_shlw_res_temp) || |
| 859 | (suspend_deep_res_exit < suspend_deep_res_temp)) { |
| 860 | pr_err("Wrong s0ix counters detected\n"); |
| 861 | goto out; |
| 862 | } |
| 863 | |
Chakravarty, Souvik K | 0946a05 | 2017-11-24 19:04:42 +0530 | [diff] [blame] | 864 | /* |
| 865 | * Due to some design limitations in the firmware, sometimes the |
| 866 | * counters do not get updated by the time we reach here. As a |
| 867 | * workaround, we try to see if this was a genuine case of sleep |
| 868 | * failure or not by cross-checking from PMC GCR registers directly. |
| 869 | */ |
| 870 | if (suspend_shlw_ctr_exit == suspend_shlw_ctr_temp && |
| 871 | suspend_deep_ctr_exit == suspend_deep_ctr_temp) { |
| 872 | ret = intel_pmc_gcr_read64(PMC_GCR_TELEM_SHLW_S0IX_REG, |
| 873 | &suspend_shlw_res_exit); |
| 874 | if (ret < 0) |
| 875 | goto out; |
| 876 | |
| 877 | ret = intel_pmc_gcr_read64(PMC_GCR_TELEM_DEEP_S0IX_REG, |
| 878 | &suspend_deep_res_exit); |
| 879 | if (ret < 0) |
| 880 | goto out; |
| 881 | |
| 882 | if (suspend_shlw_res_exit > suspend_shlw_res_temp) |
| 883 | suspend_shlw_ctr_exit++; |
| 884 | |
| 885 | if (suspend_deep_res_exit > suspend_deep_res_temp) |
| 886 | suspend_deep_ctr_exit++; |
| 887 | } |
| 888 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 889 | suspend_shlw_ctr_exit -= suspend_shlw_ctr_temp; |
| 890 | suspend_deep_ctr_exit -= suspend_deep_ctr_temp; |
| 891 | suspend_shlw_res_exit -= suspend_shlw_res_temp; |
| 892 | suspend_deep_res_exit -= suspend_deep_res_temp; |
| 893 | |
Chakravarty, Souvik K | ffd623d | 2017-11-24 19:04:43 +0530 | [diff] [blame] | 894 | if (suspend_shlw_ctr_exit != 0) { |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 895 | conf->suspend_stats.shlw_ctr += |
| 896 | suspend_shlw_ctr_exit; |
| 897 | |
| 898 | conf->suspend_stats.shlw_res += |
| 899 | suspend_shlw_res_exit; |
| 900 | } |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 901 | |
Chakravarty, Souvik K | ffd623d | 2017-11-24 19:04:43 +0530 | [diff] [blame] | 902 | if (suspend_deep_ctr_exit != 0) { |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 903 | conf->suspend_stats.deep_ctr += |
| 904 | suspend_deep_ctr_exit; |
| 905 | |
| 906 | conf->suspend_stats.deep_res += |
| 907 | suspend_deep_res_exit; |
| 908 | } |
| 909 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 910 | out: |
| 911 | suspend_prep_ok = 0; |
| 912 | return NOTIFY_OK; |
| 913 | } |
| 914 | |
| 915 | static int pm_notification(struct notifier_block *this, |
| 916 | unsigned long event, void *ptr) |
| 917 | { |
| 918 | switch (event) { |
| 919 | case PM_SUSPEND_PREPARE: |
| 920 | return pm_suspend_prep_cb(); |
| 921 | case PM_POST_SUSPEND: |
| 922 | return pm_suspend_exit_cb(); |
| 923 | } |
| 924 | |
| 925 | return NOTIFY_DONE; |
| 926 | } |
| 927 | |
| 928 | static struct notifier_block pm_notifier = { |
| 929 | .notifier_call = pm_notification, |
| 930 | }; |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 931 | |
| 932 | static int __init telemetry_debugfs_init(void) |
| 933 | { |
| 934 | const struct x86_cpu_id *id; |
Dan Carpenter | 7a3a51a | 2017-06-30 10:52:18 +0300 | [diff] [blame] | 935 | int err; |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 936 | struct dentry *f; |
| 937 | |
| 938 | /* Only APL supported for now */ |
| 939 | id = x86_match_cpu(telemetry_debugfs_cpu_ids); |
| 940 | if (!id) |
| 941 | return -ENODEV; |
| 942 | |
| 943 | debugfs_conf = (struct telemetry_debugfs_conf *)id->driver_data; |
| 944 | |
| 945 | err = telemetry_pltconfig_valid(); |
Rajneesh Bhardwaj | 8d98b1e | 2018-10-06 12:21:13 +0530 | [diff] [blame^] | 946 | if (err < 0) { |
| 947 | pr_info("Invalid pltconfig, ensure IPC1 device is enabled in BIOS\n"); |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 948 | return -ENODEV; |
Rajneesh Bhardwaj | 8d98b1e | 2018-10-06 12:21:13 +0530 | [diff] [blame^] | 949 | } |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 950 | |
| 951 | err = telemetry_debugfs_check_evts(); |
Rajneesh Bhardwaj | 8d98b1e | 2018-10-06 12:21:13 +0530 | [diff] [blame^] | 952 | if (err < 0) { |
| 953 | pr_info("telemetry_debugfs_check_evts failed\n"); |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 954 | return -EINVAL; |
Rajneesh Bhardwaj | 8d98b1e | 2018-10-06 12:21:13 +0530 | [diff] [blame^] | 955 | } |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 956 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 957 | register_pm_notifier(&pm_notifier); |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 958 | |
Dan Carpenter | 7a3a51a | 2017-06-30 10:52:18 +0300 | [diff] [blame] | 959 | err = -ENOMEM; |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 960 | debugfs_conf->telemetry_dbg_dir = debugfs_create_dir("telemetry", NULL); |
Dan Carpenter | 7a3a51a | 2017-06-30 10:52:18 +0300 | [diff] [blame] | 961 | if (!debugfs_conf->telemetry_dbg_dir) |
Priyalee Kushwaha | 74a1eb5 | 2017-06-03 10:21:24 -0700 | [diff] [blame] | 962 | goto out_pm; |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 963 | |
| 964 | f = debugfs_create_file("pss_info", S_IFREG | S_IRUGO, |
| 965 | debugfs_conf->telemetry_dbg_dir, NULL, |
| 966 | &telem_pss_ops); |
| 967 | if (!f) { |
| 968 | pr_err("pss_sample_info debugfs register failed\n"); |
| 969 | goto out; |
| 970 | } |
| 971 | |
| 972 | f = debugfs_create_file("ioss_info", S_IFREG | S_IRUGO, |
| 973 | debugfs_conf->telemetry_dbg_dir, NULL, |
| 974 | &telem_ioss_ops); |
| 975 | if (!f) { |
| 976 | pr_err("ioss_sample_info debugfs register failed\n"); |
| 977 | goto out; |
| 978 | } |
| 979 | |
| 980 | f = debugfs_create_file("soc_states", S_IFREG | S_IRUGO, |
| 981 | debugfs_conf->telemetry_dbg_dir, |
| 982 | NULL, &telem_socstate_ops); |
| 983 | if (!f) { |
| 984 | pr_err("ioss_sample_info debugfs register failed\n"); |
| 985 | goto out; |
| 986 | } |
| 987 | |
Rajneesh Bhardwaj | bc8c47a | 2017-06-23 22:22:35 +0530 | [diff] [blame] | 988 | f = debugfs_create_file("s0ix_residency_usec", S_IFREG | S_IRUGO, |
| 989 | debugfs_conf->telemetry_dbg_dir, |
| 990 | NULL, &telem_s0ix_fops); |
| 991 | if (!f) { |
| 992 | pr_err("s0ix_residency_usec debugfs register failed\n"); |
| 993 | goto out; |
| 994 | } |
| 995 | |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 996 | f = debugfs_create_file("pss_trace_verbosity", S_IFREG | S_IRUGO, |
| 997 | debugfs_conf->telemetry_dbg_dir, NULL, |
| 998 | &telem_pss_trc_verb_ops); |
| 999 | if (!f) { |
| 1000 | pr_err("pss_trace_verbosity debugfs register failed\n"); |
| 1001 | goto out; |
| 1002 | } |
| 1003 | |
| 1004 | f = debugfs_create_file("ioss_trace_verbosity", S_IFREG | S_IRUGO, |
| 1005 | debugfs_conf->telemetry_dbg_dir, NULL, |
| 1006 | &telem_ioss_trc_verb_ops); |
| 1007 | if (!f) { |
| 1008 | pr_err("ioss_trace_verbosity debugfs register failed\n"); |
| 1009 | goto out; |
| 1010 | } |
| 1011 | |
| 1012 | return 0; |
| 1013 | |
| 1014 | out: |
| 1015 | debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir); |
| 1016 | debugfs_conf->telemetry_dbg_dir = NULL; |
Priyalee Kushwaha | 74a1eb5 | 2017-06-03 10:21:24 -0700 | [diff] [blame] | 1017 | out_pm: |
| 1018 | unregister_pm_notifier(&pm_notifier); |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 1019 | |
| 1020 | return err; |
| 1021 | } |
| 1022 | |
| 1023 | static void __exit telemetry_debugfs_exit(void) |
| 1024 | { |
| 1025 | debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir); |
| 1026 | debugfs_conf->telemetry_dbg_dir = NULL; |
Priyalee Kushwaha | 74a1eb5 | 2017-06-03 10:21:24 -0700 | [diff] [blame] | 1027 | unregister_pm_notifier(&pm_notifier); |
Souvik Kumar Chakravarty | 87bee29 | 2016-01-12 16:05:14 +0530 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | late_initcall(telemetry_debugfs_init); |
| 1031 | module_exit(telemetry_debugfs_exit); |
| 1032 | |
| 1033 | MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>"); |
| 1034 | MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface"); |
| 1035 | MODULE_VERSION(DRIVER_VERSION); |
Andy Shevchenko | 917f450 | 2018-09-26 18:27:40 +0300 | [diff] [blame] | 1036 | MODULE_LICENSE("GPL v2"); |