18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Intel SOC Telemetry Driver Header File
48c2ecf20Sopenharmony_ci * Copyright (C) 2015, Intel Corporation.
58c2ecf20Sopenharmony_ci * All Rights Reserved.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef INTEL_TELEMETRY_H
88c2ecf20Sopenharmony_ci#define INTEL_TELEMETRY_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#define TELEM_MAX_EVENTS_SRAM		28
118c2ecf20Sopenharmony_ci#define TELEM_MAX_OS_ALLOCATED_EVENTS	20
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <asm/intel_scu_ipc.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cienum telemetry_unit {
168c2ecf20Sopenharmony_ci	TELEM_PSS = 0,
178c2ecf20Sopenharmony_ci	TELEM_IOSS,
188c2ecf20Sopenharmony_ci	TELEM_UNIT_NONE
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct telemetry_evtlog {
228c2ecf20Sopenharmony_ci	u32 telem_evtid;
238c2ecf20Sopenharmony_ci	u64 telem_evtlog;
248c2ecf20Sopenharmony_ci};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistruct telemetry_evtconfig {
278c2ecf20Sopenharmony_ci	/* Array of Event-IDs to Enable */
288c2ecf20Sopenharmony_ci	u32 *evtmap;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	/* Number of Events (<29) in evtmap */
318c2ecf20Sopenharmony_ci	u8 num_evts;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	/* Sampling period */
348c2ecf20Sopenharmony_ci	u8 period;
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistruct telemetry_evtmap {
388c2ecf20Sopenharmony_ci	const char *name;
398c2ecf20Sopenharmony_ci	u32 evt_id;
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct telemetry_unit_config {
438c2ecf20Sopenharmony_ci	struct telemetry_evtmap *telem_evts;
448c2ecf20Sopenharmony_ci	void __iomem *regmap;
458c2ecf20Sopenharmony_ci	u8 ssram_evts_used;
468c2ecf20Sopenharmony_ci	u8 curr_period;
478c2ecf20Sopenharmony_ci	u8 max_period;
488c2ecf20Sopenharmony_ci	u8 min_period;
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistruct telemetry_plt_config {
528c2ecf20Sopenharmony_ci	struct telemetry_unit_config pss_config;
538c2ecf20Sopenharmony_ci	struct telemetry_unit_config ioss_config;
548c2ecf20Sopenharmony_ci	struct mutex telem_trace_lock;
558c2ecf20Sopenharmony_ci	struct mutex telem_lock;
568c2ecf20Sopenharmony_ci	struct intel_pmc_dev *pmc;
578c2ecf20Sopenharmony_ci	struct intel_scu_ipc_dev *scu;
588c2ecf20Sopenharmony_ci	bool telem_in_use;
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistruct telemetry_core_ops {
628c2ecf20Sopenharmony_ci	int (*get_sampling_period)(u8 *pss_min_period, u8 *pss_max_period,
638c2ecf20Sopenharmony_ci				   u8 *ioss_min_period, u8 *ioss_max_period);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	int (*get_eventconfig)(struct telemetry_evtconfig *pss_evtconfig,
668c2ecf20Sopenharmony_ci			       struct telemetry_evtconfig *ioss_evtconfig,
678c2ecf20Sopenharmony_ci			       int pss_len, int ioss_len);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	int (*update_events)(struct telemetry_evtconfig pss_evtconfig,
708c2ecf20Sopenharmony_ci			     struct telemetry_evtconfig ioss_evtconfig);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	int (*set_sampling_period)(u8 pss_period, u8 ioss_period);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	int (*get_trace_verbosity)(enum telemetry_unit telem_unit,
758c2ecf20Sopenharmony_ci				   u32 *verbosity);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	int (*set_trace_verbosity)(enum telemetry_unit telem_unit,
788c2ecf20Sopenharmony_ci				   u32 verbosity);
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	int (*raw_read_eventlog)(enum telemetry_unit telem_unit,
818c2ecf20Sopenharmony_ci				 struct telemetry_evtlog *evtlog,
828c2ecf20Sopenharmony_ci				 int len, int log_all_evts);
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	int (*read_eventlog)(enum telemetry_unit telem_unit,
858c2ecf20Sopenharmony_ci			     struct telemetry_evtlog *evtlog,
868c2ecf20Sopenharmony_ci			     int len, int log_all_evts);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	int (*add_events)(u8 num_pss_evts, u8 num_ioss_evts,
898c2ecf20Sopenharmony_ci			  u32 *pss_evtmap, u32 *ioss_evtmap);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	int (*reset_events)(void);
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ciint telemetry_set_pltdata(const struct telemetry_core_ops *ops,
958c2ecf20Sopenharmony_ci			  struct telemetry_plt_config *pltconfig);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciint telemetry_clear_pltdata(void);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistruct telemetry_plt_config *telemetry_get_pltdata(void);
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ciint telemetry_get_evtname(enum telemetry_unit telem_unit,
1028c2ecf20Sopenharmony_ci			  const char **name, int len);
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ciint telemetry_update_events(struct telemetry_evtconfig pss_evtconfig,
1058c2ecf20Sopenharmony_ci			    struct telemetry_evtconfig ioss_evtconfig);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciint telemetry_add_events(u8 num_pss_evts, u8 num_ioss_evts,
1088c2ecf20Sopenharmony_ci			 u32 *pss_evtmap, u32 *ioss_evtmap);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ciint telemetry_reset_events(void);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ciint telemetry_get_eventconfig(struct telemetry_evtconfig *pss_config,
1138c2ecf20Sopenharmony_ci			      struct telemetry_evtconfig *ioss_config,
1148c2ecf20Sopenharmony_ci			      int pss_len, int ioss_len);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ciint telemetry_read_events(enum telemetry_unit telem_unit,
1178c2ecf20Sopenharmony_ci			  struct telemetry_evtlog *evtlog, int len);
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ciint telemetry_raw_read_events(enum telemetry_unit telem_unit,
1208c2ecf20Sopenharmony_ci			      struct telemetry_evtlog *evtlog, int len);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ciint telemetry_read_eventlog(enum telemetry_unit telem_unit,
1238c2ecf20Sopenharmony_ci			    struct telemetry_evtlog *evtlog, int len);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ciint telemetry_raw_read_eventlog(enum telemetry_unit telem_unit,
1268c2ecf20Sopenharmony_ci				struct telemetry_evtlog *evtlog, int len);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ciint telemetry_get_sampling_period(u8 *pss_min_period, u8 *pss_max_period,
1298c2ecf20Sopenharmony_ci				  u8 *ioss_min_period, u8 *ioss_max_period);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ciint telemetry_set_sampling_period(u8 pss_period, u8 ioss_period);
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ciint telemetry_set_trace_verbosity(enum telemetry_unit telem_unit,
1348c2ecf20Sopenharmony_ci				  u32 verbosity);
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ciint telemetry_get_trace_verbosity(enum telemetry_unit telem_unit,
1378c2ecf20Sopenharmony_ci				  u32 *verbosity);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#endif /* INTEL_TELEMETRY_H */
140