162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Intel SOC Telemetry Driver Header File
462306a36Sopenharmony_ci * Copyright (C) 2015, Intel Corporation.
562306a36Sopenharmony_ci * All Rights Reserved.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef INTEL_TELEMETRY_H
862306a36Sopenharmony_ci#define INTEL_TELEMETRY_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define TELEM_MAX_EVENTS_SRAM		28
1162306a36Sopenharmony_ci#define TELEM_MAX_OS_ALLOCATED_EVENTS	20
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <asm/intel_scu_ipc.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cienum telemetry_unit {
1662306a36Sopenharmony_ci	TELEM_PSS = 0,
1762306a36Sopenharmony_ci	TELEM_IOSS,
1862306a36Sopenharmony_ci	TELEM_UNIT_NONE
1962306a36Sopenharmony_ci};
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_cistruct telemetry_evtlog {
2262306a36Sopenharmony_ci	u32 telem_evtid;
2362306a36Sopenharmony_ci	u64 telem_evtlog;
2462306a36Sopenharmony_ci};
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_cistruct telemetry_evtconfig {
2762306a36Sopenharmony_ci	/* Array of Event-IDs to Enable */
2862306a36Sopenharmony_ci	u32 *evtmap;
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci	/* Number of Events (<29) in evtmap */
3162306a36Sopenharmony_ci	u8 num_evts;
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci	/* Sampling period */
3462306a36Sopenharmony_ci	u8 period;
3562306a36Sopenharmony_ci};
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cistruct telemetry_evtmap {
3862306a36Sopenharmony_ci	const char *name;
3962306a36Sopenharmony_ci	u32 evt_id;
4062306a36Sopenharmony_ci};
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_cistruct telemetry_unit_config {
4362306a36Sopenharmony_ci	struct telemetry_evtmap *telem_evts;
4462306a36Sopenharmony_ci	void __iomem *regmap;
4562306a36Sopenharmony_ci	u8 ssram_evts_used;
4662306a36Sopenharmony_ci	u8 curr_period;
4762306a36Sopenharmony_ci	u8 max_period;
4862306a36Sopenharmony_ci	u8 min_period;
4962306a36Sopenharmony_ci};
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cistruct telemetry_plt_config {
5262306a36Sopenharmony_ci	struct telemetry_unit_config pss_config;
5362306a36Sopenharmony_ci	struct telemetry_unit_config ioss_config;
5462306a36Sopenharmony_ci	struct mutex telem_trace_lock;
5562306a36Sopenharmony_ci	struct mutex telem_lock;
5662306a36Sopenharmony_ci	struct intel_pmc_dev *pmc;
5762306a36Sopenharmony_ci	struct intel_scu_ipc_dev *scu;
5862306a36Sopenharmony_ci	bool telem_in_use;
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistruct telemetry_core_ops {
6262306a36Sopenharmony_ci	int (*get_sampling_period)(u8 *pss_min_period, u8 *pss_max_period,
6362306a36Sopenharmony_ci				   u8 *ioss_min_period, u8 *ioss_max_period);
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci	int (*get_eventconfig)(struct telemetry_evtconfig *pss_evtconfig,
6662306a36Sopenharmony_ci			       struct telemetry_evtconfig *ioss_evtconfig,
6762306a36Sopenharmony_ci			       int pss_len, int ioss_len);
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci	int (*update_events)(struct telemetry_evtconfig pss_evtconfig,
7062306a36Sopenharmony_ci			     struct telemetry_evtconfig ioss_evtconfig);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci	int (*set_sampling_period)(u8 pss_period, u8 ioss_period);
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci	int (*get_trace_verbosity)(enum telemetry_unit telem_unit,
7562306a36Sopenharmony_ci				   u32 *verbosity);
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci	int (*set_trace_verbosity)(enum telemetry_unit telem_unit,
7862306a36Sopenharmony_ci				   u32 verbosity);
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci	int (*raw_read_eventlog)(enum telemetry_unit telem_unit,
8162306a36Sopenharmony_ci				 struct telemetry_evtlog *evtlog,
8262306a36Sopenharmony_ci				 int len, int log_all_evts);
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	int (*read_eventlog)(enum telemetry_unit telem_unit,
8562306a36Sopenharmony_ci			     struct telemetry_evtlog *evtlog,
8662306a36Sopenharmony_ci			     int len, int log_all_evts);
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci	int (*add_events)(u8 num_pss_evts, u8 num_ioss_evts,
8962306a36Sopenharmony_ci			  u32 *pss_evtmap, u32 *ioss_evtmap);
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci	int (*reset_events)(void);
9262306a36Sopenharmony_ci};
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ciint telemetry_set_pltdata(const struct telemetry_core_ops *ops,
9562306a36Sopenharmony_ci			  struct telemetry_plt_config *pltconfig);
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ciint telemetry_clear_pltdata(void);
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_cistruct telemetry_plt_config *telemetry_get_pltdata(void);
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ciint telemetry_get_evtname(enum telemetry_unit telem_unit,
10262306a36Sopenharmony_ci			  const char **name, int len);
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ciint telemetry_update_events(struct telemetry_evtconfig pss_evtconfig,
10562306a36Sopenharmony_ci			    struct telemetry_evtconfig ioss_evtconfig);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ciint telemetry_add_events(u8 num_pss_evts, u8 num_ioss_evts,
10862306a36Sopenharmony_ci			 u32 *pss_evtmap, u32 *ioss_evtmap);
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ciint telemetry_reset_events(void);
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciint telemetry_get_eventconfig(struct telemetry_evtconfig *pss_config,
11362306a36Sopenharmony_ci			      struct telemetry_evtconfig *ioss_config,
11462306a36Sopenharmony_ci			      int pss_len, int ioss_len);
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ciint telemetry_read_events(enum telemetry_unit telem_unit,
11762306a36Sopenharmony_ci			  struct telemetry_evtlog *evtlog, int len);
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ciint telemetry_raw_read_events(enum telemetry_unit telem_unit,
12062306a36Sopenharmony_ci			      struct telemetry_evtlog *evtlog, int len);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ciint telemetry_read_eventlog(enum telemetry_unit telem_unit,
12362306a36Sopenharmony_ci			    struct telemetry_evtlog *evtlog, int len);
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ciint telemetry_raw_read_eventlog(enum telemetry_unit telem_unit,
12662306a36Sopenharmony_ci				struct telemetry_evtlog *evtlog, int len);
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ciint telemetry_get_sampling_period(u8 *pss_min_period, u8 *pss_max_period,
12962306a36Sopenharmony_ci				  u8 *ioss_min_period, u8 *ioss_max_period);
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ciint telemetry_set_sampling_period(u8 pss_period, u8 ioss_period);
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ciint telemetry_set_trace_verbosity(enum telemetry_unit telem_unit,
13462306a36Sopenharmony_ci				  u32 verbosity);
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ciint telemetry_get_trace_verbosity(enum telemetry_unit telem_unit,
13762306a36Sopenharmony_ci				  u32 *verbosity);
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci#endif /* INTEL_TELEMETRY_H */
140