hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/platform/x86/intel_telemetry_pltdrv.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Intel SOC Telemetry Platform Driver: Currently supports APL
34 * Copyright (c) 2015, Intel Corporation.
45 * All Rights Reserved.
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms and conditions of the GNU General Public License,
8
- * version 2, as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope it will be useful, but WITHOUT
11
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
- * more details.
146 *
157 * This file provides the platform specific telemetry implementation for APL.
168 * It used the PUNIT and PMC IPC interfaces for configuring the counters.
....@@ -23,7 +15,6 @@
2315
2416 #include <asm/cpu_device_id.h>
2517 #include <asm/intel-family.h>
26
-#include <asm/intel_pmc_ipc.h>
2718 #include <asm/intel_punit_ipc.h>
2819 #include <asm/intel_telemetry.h>
2920
....@@ -43,6 +34,7 @@
4334 #define TELEM_SSRAM_STARTTIME_OFFSET 8
4435 #define TELEM_SSRAM_EVTLOG_OFFSET 16
4536
37
+#define IOSS_TELEM 0xeb
4638 #define IOSS_TELEM_EVENT_READ 0x0
4739 #define IOSS_TELEM_EVENT_WRITE 0x1
4840 #define IOSS_TELEM_INFO_READ 0x2
....@@ -50,9 +42,6 @@
5042 #define IOSS_TELEM_TRACE_CTL_WRITE 0x6
5143 #define IOSS_TELEM_EVENT_CTL_READ 0x7
5244 #define IOSS_TELEM_EVENT_CTL_WRITE 0x8
53
-#define IOSS_TELEM_EVT_CTRL_WRITE_SIZE 0x4
54
-#define IOSS_TELEM_READ_WORD 0x1
55
-#define IOSS_TELEM_WRITE_FOURBYTES 0x4
5645 #define IOSS_TELEM_EVT_WRITE_SIZE 0x3
5746
5847 #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
....@@ -74,9 +63,6 @@
7463 #define TELEM_EXTRACT_VERBOSITY(x, y) ((y) = (((x) >> 27) & 0x3))
7564 #define TELEM_CLEAR_VERBOSITY_BITS(x) ((x) &= ~(BIT(27) | BIT(28)))
7665 #define TELEM_SET_VERBOSITY_BITS(x, y) ((x) |= ((y) << 27))
77
-
78
-#define TELEM_CPU(model, data) \
79
- { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&data }
8066
8167 enum telemetry_action {
8268 TELEM_UPDATE = 0,
....@@ -191,8 +177,8 @@
191177 };
192178
193179 static const struct x86_cpu_id telemetry_cpu_ids[] = {
194
- TELEM_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_config),
195
- TELEM_CPU(INTEL_FAM6_ATOM_GOLDMONT_PLUS, telem_glk_config),
180
+ X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT, &telem_apl_config),
181
+ X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT_PLUS, &telem_glk_config),
196182 {}
197183 };
198184
....@@ -261,17 +247,14 @@
261247 static inline int telemetry_plt_config_ioss_event(u32 evt_id, int index)
262248 {
263249 u32 write_buf;
264
- int ret;
265250
266251 write_buf = evt_id | TELEM_EVENT_ENABLE;
267252 write_buf <<= BITS_PER_BYTE;
268253 write_buf |= index;
269254
270
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
271
- IOSS_TELEM_EVENT_WRITE, (u8 *)&write_buf,
272
- IOSS_TELEM_EVT_WRITE_SIZE, NULL, 0);
273
-
274
- return ret;
255
+ return intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
256
+ IOSS_TELEM_EVENT_WRITE, &write_buf,
257
+ IOSS_TELEM_EVT_WRITE_SIZE, NULL, 0);
275258 }
276259
277260 static inline int telemetry_plt_config_pss_event(u32 evt_id, int index)
....@@ -289,6 +272,7 @@
289272 static int telemetry_setup_iossevtconfig(struct telemetry_evtconfig evtconfig,
290273 enum telemetry_action action)
291274 {
275
+ struct intel_scu_ipc_dev *scu = telm_conf->scu;
292276 u8 num_ioss_evts, ioss_period;
293277 int ret, index, idx;
294278 u32 *ioss_evtmap;
....@@ -299,9 +283,9 @@
299283 ioss_evtmap = evtconfig.evtmap;
300284
301285 /* Get telemetry EVENT CTL */
302
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
286
+ ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
303287 IOSS_TELEM_EVENT_CTL_READ, NULL, 0,
304
- &telem_ctrl, IOSS_TELEM_READ_WORD);
288
+ &telem_ctrl, sizeof(telem_ctrl));
305289 if (ret) {
306290 pr_err("IOSS TELEM_CTRL Read Failed\n");
307291 return ret;
....@@ -310,11 +294,9 @@
310294 /* Disable Telemetry */
311295 TELEM_DISABLE(telem_ctrl);
312296
313
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
314
- IOSS_TELEM_EVENT_CTL_WRITE,
315
- (u8 *)&telem_ctrl,
316
- IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
317
- NULL, 0);
297
+ ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
298
+ IOSS_TELEM_EVENT_CTL_WRITE, &telem_ctrl,
299
+ sizeof(telem_ctrl), NULL, 0);
318300 if (ret) {
319301 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
320302 return ret;
....@@ -326,10 +308,9 @@
326308 /* Clear All Events */
327309 TELEM_CLEAR_EVENTS(telem_ctrl);
328310
329
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
311
+ ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
330312 IOSS_TELEM_EVENT_CTL_WRITE,
331
- (u8 *)&telem_ctrl,
332
- IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
313
+ &telem_ctrl, sizeof(telem_ctrl),
333314 NULL, 0);
334315 if (ret) {
335316 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
....@@ -355,10 +336,9 @@
355336 /* Clear All Events */
356337 TELEM_CLEAR_EVENTS(telem_ctrl);
357338
358
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
339
+ ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
359340 IOSS_TELEM_EVENT_CTL_WRITE,
360
- (u8 *)&telem_ctrl,
361
- IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
341
+ &telem_ctrl, sizeof(telem_ctrl),
362342 NULL, 0);
363343 if (ret) {
364344 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
....@@ -407,10 +387,9 @@
407387 TELEM_ENABLE_PERIODIC(telem_ctrl);
408388 telem_ctrl |= ioss_period;
409389
410
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
390
+ ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
411391 IOSS_TELEM_EVENT_CTL_WRITE,
412
- (u8 *)&telem_ctrl,
413
- IOSS_TELEM_EVT_CTRL_WRITE_SIZE, NULL, 0);
392
+ &telem_ctrl, sizeof(telem_ctrl), NULL, 0);
414393 if (ret) {
415394 pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
416395 return ret;
....@@ -597,8 +576,9 @@
597576 u32 read_buf, events, event_regs;
598577 int ret;
599578
600
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY, IOSS_TELEM_INFO_READ,
601
- NULL, 0, &read_buf, IOSS_TELEM_READ_WORD);
579
+ ret = intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
580
+ IOSS_TELEM_INFO_READ, NULL, 0,
581
+ &read_buf, sizeof(read_buf));
602582 if (ret) {
603583 dev_err(&pdev->dev, "IOSS TELEM_INFO Read Failed\n");
604584 return ret;
....@@ -692,6 +672,8 @@
692672
693673 mutex_lock(&(telm_conf->telem_lock));
694674 if (ioss_period) {
675
+ struct intel_scu_ipc_dev *scu = telm_conf->scu;
676
+
695677 if (TELEM_SAMPLE_PERIOD_INVALID(ioss_period)) {
696678 pr_err("IOSS Sampling Period Out of Range\n");
697679 ret = -EINVAL;
....@@ -699,9 +681,9 @@
699681 }
700682
701683 /* Get telemetry EVENT CTL */
702
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
684
+ ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
703685 IOSS_TELEM_EVENT_CTL_READ, NULL, 0,
704
- &telem_ctrl, IOSS_TELEM_READ_WORD);
686
+ &telem_ctrl, sizeof(telem_ctrl));
705687 if (ret) {
706688 pr_err("IOSS TELEM_CTRL Read Failed\n");
707689 goto out;
....@@ -710,11 +692,10 @@
710692 /* Disable Telemetry */
711693 TELEM_DISABLE(telem_ctrl);
712694
713
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
714
- IOSS_TELEM_EVENT_CTL_WRITE,
715
- (u8 *)&telem_ctrl,
716
- IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
717
- NULL, 0);
695
+ ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
696
+ IOSS_TELEM_EVENT_CTL_WRITE,
697
+ &telem_ctrl, sizeof(telem_ctrl),
698
+ NULL, 0);
718699 if (ret) {
719700 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
720701 goto out;
....@@ -726,11 +707,10 @@
726707 TELEM_ENABLE_PERIODIC(telem_ctrl);
727708 telem_ctrl |= ioss_period;
728709
729
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
730
- IOSS_TELEM_EVENT_CTL_WRITE,
731
- (u8 *)&telem_ctrl,
732
- IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
733
- NULL, 0);
710
+ ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
711
+ IOSS_TELEM_EVENT_CTL_WRITE,
712
+ &telem_ctrl, sizeof(telem_ctrl),
713
+ NULL, 0);
734714 if (ret) {
735715 pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
736716 goto out;
....@@ -1025,9 +1005,9 @@
10251005 break;
10261006
10271007 case TELEM_IOSS:
1028
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
1029
- IOSS_TELEM_TRACE_CTL_READ, NULL, 0, &temp,
1030
- IOSS_TELEM_READ_WORD);
1008
+ ret = intel_scu_ipc_dev_command(telm_conf->scu,
1009
+ IOSS_TELEM, IOSS_TELEM_TRACE_CTL_READ,
1010
+ NULL, 0, &temp, sizeof(temp));
10311011 if (ret) {
10321012 pr_err("IOSS TRACE_CTL Read Failed\n");
10331013 goto out;
....@@ -1079,9 +1059,9 @@
10791059 break;
10801060
10811061 case TELEM_IOSS:
1082
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
1083
- IOSS_TELEM_TRACE_CTL_READ, NULL, 0, &temp,
1084
- IOSS_TELEM_READ_WORD);
1062
+ ret = intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
1063
+ IOSS_TELEM_TRACE_CTL_READ,
1064
+ NULL, 0, &temp, sizeof(temp));
10851065 if (ret) {
10861066 pr_err("IOSS TRACE_CTL Read Failed\n");
10871067 goto out;
....@@ -1090,9 +1070,9 @@
10901070 TELEM_CLEAR_VERBOSITY_BITS(temp);
10911071 TELEM_SET_VERBOSITY_BITS(temp, verbosity);
10921072
1093
- ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
1094
- IOSS_TELEM_TRACE_CTL_WRITE, (u8 *)&temp,
1095
- IOSS_TELEM_WRITE_FOURBYTES, NULL, 0);
1073
+ ret = intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
1074
+ IOSS_TELEM_TRACE_CTL_WRITE,
1075
+ &temp, sizeof(temp), NULL, 0);
10961076 if (ret) {
10971077 pr_err("IOSS TRACE_CTL Verbosity Set Failed\n");
10981078 goto out;
....@@ -1125,9 +1105,9 @@
11251105
11261106 static int telemetry_pltdrv_probe(struct platform_device *pdev)
11271107 {
1128
- struct resource *res0 = NULL, *res1 = NULL;
11291108 const struct x86_cpu_id *id;
1130
- int size, ret = -ENOMEM;
1109
+ void __iomem *mem;
1110
+ int ret;
11311111
11321112 id = x86_match_cpu(telemetry_cpu_ids);
11331113 if (!id)
....@@ -1135,48 +1115,23 @@
11351115
11361116 telm_conf = (struct telemetry_plt_config *)id->driver_data;
11371117
1138
- res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1139
- if (!res0) {
1140
- ret = -EINVAL;
1141
- goto out;
1142
- }
1143
- size = resource_size(res0);
1144
- if (!devm_request_mem_region(&pdev->dev, res0->start, size,
1145
- pdev->name)) {
1146
- ret = -EBUSY;
1147
- goto out;
1148
- }
1149
- telm_conf->pss_config.ssram_base_addr = res0->start;
1150
- telm_conf->pss_config.ssram_size = size;
1118
+ telm_conf->pmc = dev_get_drvdata(pdev->dev.parent);
11511119
1152
- res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1153
- if (!res1) {
1154
- ret = -EINVAL;
1155
- goto out;
1156
- }
1157
- size = resource_size(res1);
1158
- if (!devm_request_mem_region(&pdev->dev, res1->start, size,
1159
- pdev->name)) {
1160
- ret = -EBUSY;
1161
- goto out;
1162
- }
1120
+ mem = devm_platform_ioremap_resource(pdev, 0);
1121
+ if (IS_ERR(mem))
1122
+ return PTR_ERR(mem);
11631123
1164
- telm_conf->ioss_config.ssram_base_addr = res1->start;
1165
- telm_conf->ioss_config.ssram_size = size;
1124
+ telm_conf->pss_config.regmap = mem;
11661125
1167
- telm_conf->pss_config.regmap = ioremap_nocache(
1168
- telm_conf->pss_config.ssram_base_addr,
1169
- telm_conf->pss_config.ssram_size);
1170
- if (!telm_conf->pss_config.regmap) {
1171
- ret = -ENOMEM;
1172
- goto out;
1173
- }
1126
+ mem = devm_platform_ioremap_resource(pdev, 1);
1127
+ if (IS_ERR(mem))
1128
+ return PTR_ERR(mem);
11741129
1175
- telm_conf->ioss_config.regmap = ioremap_nocache(
1176
- telm_conf->ioss_config.ssram_base_addr,
1177
- telm_conf->ioss_config.ssram_size);
1178
- if (!telm_conf->ioss_config.regmap) {
1179
- ret = -ENOMEM;
1130
+ telm_conf->ioss_config.regmap = mem;
1131
+
1132
+ telm_conf->scu = devm_intel_scu_ipc_dev_get(&pdev->dev);
1133
+ if (!telm_conf->scu) {
1134
+ ret = -EPROBE_DEFER;
11801135 goto out;
11811136 }
11821137
....@@ -1196,14 +1151,6 @@
11961151 return 0;
11971152
11981153 out:
1199
- if (res0)
1200
- release_mem_region(res0->start, resource_size(res0));
1201
- if (res1)
1202
- release_mem_region(res1->start, resource_size(res1));
1203
- if (telm_conf->pss_config.regmap)
1204
- iounmap(telm_conf->pss_config.regmap);
1205
- if (telm_conf->ioss_config.regmap)
1206
- iounmap(telm_conf->ioss_config.regmap);
12071154 dev_err(&pdev->dev, "TELEMETRY Setup Failed.\n");
12081155
12091156 return ret;
....@@ -1212,9 +1159,6 @@
12121159 static int telemetry_pltdrv_remove(struct platform_device *pdev)
12131160 {
12141161 telemetry_clear_pltdata();
1215
- iounmap(telm_conf->pss_config.regmap);
1216
- iounmap(telm_conf->ioss_config.regmap);
1217
-
12181162 return 0;
12191163 }
12201164
....@@ -1242,4 +1186,4 @@
12421186 MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
12431187 MODULE_DESCRIPTION("Intel SoC Telemetry Platform Driver");
12441188 MODULE_VERSION(DRIVER_VERSION);
1245
-MODULE_LICENSE("GPL");
1189
+MODULE_LICENSE("GPL v2");