xref: /openbmc/linux/drivers/hwtracing/intel_th/intel_th.h (revision 4d02ceff32f35f3ea745be6114503c2d2505da99)
139f40346SAlexander Shishkin /*
239f40346SAlexander Shishkin  * Intel(R) Trace Hub data structures
339f40346SAlexander Shishkin  *
439f40346SAlexander Shishkin  * Copyright (C) 2014-2015 Intel Corporation.
539f40346SAlexander Shishkin  *
639f40346SAlexander Shishkin  * This program is free software; you can redistribute it and/or modify it
739f40346SAlexander Shishkin  * under the terms and conditions of the GNU General Public License,
839f40346SAlexander Shishkin  * version 2, as published by the Free Software Foundation.
939f40346SAlexander Shishkin  *
1039f40346SAlexander Shishkin  * This program is distributed in the hope it will be useful, but WITHOUT
1139f40346SAlexander Shishkin  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1239f40346SAlexander Shishkin  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
1339f40346SAlexander Shishkin  * more details.
1439f40346SAlexander Shishkin  */
1539f40346SAlexander Shishkin 
1639f40346SAlexander Shishkin #ifndef __INTEL_TH_H__
1739f40346SAlexander Shishkin #define __INTEL_TH_H__
1839f40346SAlexander Shishkin 
1939f40346SAlexander Shishkin /* intel_th_device device types */
2039f40346SAlexander Shishkin enum {
2139f40346SAlexander Shishkin 	/* Devices that generate trace data */
2239f40346SAlexander Shishkin 	INTEL_TH_SOURCE = 0,
2339f40346SAlexander Shishkin 	/* Output ports (MSC, PTI) */
2439f40346SAlexander Shishkin 	INTEL_TH_OUTPUT,
2539f40346SAlexander Shishkin 	/* Switch, the Global Trace Hub (GTH) */
2639f40346SAlexander Shishkin 	INTEL_TH_SWITCH,
2739f40346SAlexander Shishkin };
2839f40346SAlexander Shishkin 
2939f40346SAlexander Shishkin /**
3039f40346SAlexander Shishkin  * struct intel_th_output - descriptor INTEL_TH_OUTPUT type devices
3139f40346SAlexander Shishkin  * @port:	output port number, assigned by the switch
3239f40346SAlexander Shishkin  * @type:	GTH_{MSU,CTP,PTI}
33*4d02ceffSAlexander Shishkin  * @scratchpad:	scratchpad bits to flag when this output is enabled
3439f40346SAlexander Shishkin  * @multiblock:	true for multiblock output configuration
3539f40346SAlexander Shishkin  * @active:	true when this output is enabled
3639f40346SAlexander Shishkin  *
3739f40346SAlexander Shishkin  * Output port descriptor, used by switch driver to tell which output
3839f40346SAlexander Shishkin  * port this output device corresponds to. Filled in at output device's
3939f40346SAlexander Shishkin  * probe time by switch::assign(). Passed from output device driver to
4039f40346SAlexander Shishkin  * switch related code to enable/disable its port.
4139f40346SAlexander Shishkin  */
4239f40346SAlexander Shishkin struct intel_th_output {
4339f40346SAlexander Shishkin 	int		port;
4439f40346SAlexander Shishkin 	unsigned int	type;
45*4d02ceffSAlexander Shishkin 	unsigned int	scratchpad;
4639f40346SAlexander Shishkin 	bool		multiblock;
4739f40346SAlexander Shishkin 	bool		active;
4839f40346SAlexander Shishkin };
4939f40346SAlexander Shishkin 
5039f40346SAlexander Shishkin /**
5139f40346SAlexander Shishkin  * struct intel_th_device - device on the intel_th bus
5239f40346SAlexander Shishkin  * @dev:		device
5339f40346SAlexander Shishkin  * @resource:		array of resources available to this device
5439f40346SAlexander Shishkin  * @num_resources:	number of resources in @resource array
5539f40346SAlexander Shishkin  * @type:		INTEL_TH_{SOURCE,OUTPUT,SWITCH}
5639f40346SAlexander Shishkin  * @id:			device instance or -1
5739f40346SAlexander Shishkin  * @output:		output descriptor for INTEL_TH_OUTPUT devices
5839f40346SAlexander Shishkin  * @name:		device name to match the driver
5939f40346SAlexander Shishkin  */
6039f40346SAlexander Shishkin struct intel_th_device {
6139f40346SAlexander Shishkin 	struct device	dev;
6239f40346SAlexander Shishkin 	struct resource	*resource;
6339f40346SAlexander Shishkin 	unsigned int	num_resources;
6439f40346SAlexander Shishkin 	unsigned int	type;
6539f40346SAlexander Shishkin 	int		id;
6639f40346SAlexander Shishkin 
6739f40346SAlexander Shishkin 	/* INTEL_TH_OUTPUT specific */
6839f40346SAlexander Shishkin 	struct intel_th_output	output;
6939f40346SAlexander Shishkin 
7039f40346SAlexander Shishkin 	char		name[];
7139f40346SAlexander Shishkin };
7239f40346SAlexander Shishkin 
7339f40346SAlexander Shishkin #define to_intel_th_device(_d)				\
7439f40346SAlexander Shishkin 	container_of((_d), struct intel_th_device, dev)
7539f40346SAlexander Shishkin 
7639f40346SAlexander Shishkin /**
7739f40346SAlexander Shishkin  * intel_th_device_get_resource() - obtain @num'th resource of type @type
7839f40346SAlexander Shishkin  * @thdev:	the device to search the resource for
7939f40346SAlexander Shishkin  * @type:	resource type
8039f40346SAlexander Shishkin  * @num:	number of the resource
8139f40346SAlexander Shishkin  */
8239f40346SAlexander Shishkin static inline struct resource *
8339f40346SAlexander Shishkin intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type,
8439f40346SAlexander Shishkin 			     unsigned int num)
8539f40346SAlexander Shishkin {
8639f40346SAlexander Shishkin 	int i;
8739f40346SAlexander Shishkin 
8839f40346SAlexander Shishkin 	for (i = 0; i < thdev->num_resources; i++)
8939f40346SAlexander Shishkin 		if (resource_type(&thdev->resource[i]) == type && !num--)
9039f40346SAlexander Shishkin 			return &thdev->resource[i];
9139f40346SAlexander Shishkin 
9239f40346SAlexander Shishkin 	return NULL;
9339f40346SAlexander Shishkin }
9439f40346SAlexander Shishkin 
9539f40346SAlexander Shishkin /**
9639f40346SAlexander Shishkin  * intel_th_output_assigned() - if an output device is assigned to a switch port
9739f40346SAlexander Shishkin  * @thdev:	the output device
9839f40346SAlexander Shishkin  *
9939f40346SAlexander Shishkin  * Return:	true if the device is INTEL_TH_OUTPUT *and* is assigned a port
10039f40346SAlexander Shishkin  */
10139f40346SAlexander Shishkin static inline bool
10239f40346SAlexander Shishkin intel_th_output_assigned(struct intel_th_device *thdev)
10339f40346SAlexander Shishkin {
10439f40346SAlexander Shishkin 	return thdev->type == INTEL_TH_OUTPUT &&
10539f40346SAlexander Shishkin 		thdev->output.port >= 0;
10639f40346SAlexander Shishkin }
10739f40346SAlexander Shishkin 
10839f40346SAlexander Shishkin /**
10939f40346SAlexander Shishkin  * struct intel_th_driver - driver for an intel_th_device device
11039f40346SAlexander Shishkin  * @driver:	generic driver
11139f40346SAlexander Shishkin  * @probe:	probe method
11239f40346SAlexander Shishkin  * @remove:	remove method
11339f40346SAlexander Shishkin  * @assign:	match a given output type device against available outputs
11439f40346SAlexander Shishkin  * @unassign:	deassociate an output type device from an output port
11539f40346SAlexander Shishkin  * @enable:	enable tracing for a given output device
11639f40346SAlexander Shishkin  * @disable:	disable tracing for a given output device
11739f40346SAlexander Shishkin  * @fops:	file operations for device nodes
11839f40346SAlexander Shishkin  *
11939f40346SAlexander Shishkin  * Callbacks @probe and @remove are required for all device types.
12039f40346SAlexander Shishkin  * Switch device driver needs to fill in @assign, @enable and @disable
12139f40346SAlexander Shishkin  * callbacks.
12239f40346SAlexander Shishkin  */
12339f40346SAlexander Shishkin struct intel_th_driver {
12439f40346SAlexander Shishkin 	struct device_driver	driver;
12539f40346SAlexander Shishkin 	int			(*probe)(struct intel_th_device *thdev);
12639f40346SAlexander Shishkin 	void			(*remove)(struct intel_th_device *thdev);
12739f40346SAlexander Shishkin 	/* switch (GTH) ops */
12839f40346SAlexander Shishkin 	int			(*assign)(struct intel_th_device *thdev,
12939f40346SAlexander Shishkin 					  struct intel_th_device *othdev);
13039f40346SAlexander Shishkin 	void			(*unassign)(struct intel_th_device *thdev,
13139f40346SAlexander Shishkin 					    struct intel_th_device *othdev);
13239f40346SAlexander Shishkin 	void			(*enable)(struct intel_th_device *thdev,
13339f40346SAlexander Shishkin 					  struct intel_th_output *output);
13439f40346SAlexander Shishkin 	void			(*disable)(struct intel_th_device *thdev,
13539f40346SAlexander Shishkin 					   struct intel_th_output *output);
13639f40346SAlexander Shishkin 	/* output ops */
13739f40346SAlexander Shishkin 	void			(*irq)(struct intel_th_device *thdev);
13839f40346SAlexander Shishkin 	int			(*activate)(struct intel_th_device *thdev);
13939f40346SAlexander Shishkin 	void			(*deactivate)(struct intel_th_device *thdev);
14039f40346SAlexander Shishkin 	/* file_operations for those who want a device node */
14139f40346SAlexander Shishkin 	const struct file_operations *fops;
14239f40346SAlexander Shishkin 
14339f40346SAlexander Shishkin 	/* source ops */
14439f40346SAlexander Shishkin 	int			(*set_output)(struct intel_th_device *thdev,
14539f40346SAlexander Shishkin 					      unsigned int master);
14639f40346SAlexander Shishkin };
14739f40346SAlexander Shishkin 
14839f40346SAlexander Shishkin #define to_intel_th_driver(_d)					\
14939f40346SAlexander Shishkin 	container_of((_d), struct intel_th_driver, driver)
15039f40346SAlexander Shishkin 
15139f40346SAlexander Shishkin static inline struct intel_th_device *
15239f40346SAlexander Shishkin to_intel_th_hub(struct intel_th_device *thdev)
15339f40346SAlexander Shishkin {
15439f40346SAlexander Shishkin 	struct device *parent = thdev->dev.parent;
15539f40346SAlexander Shishkin 
15639f40346SAlexander Shishkin 	if (!parent)
15739f40346SAlexander Shishkin 		return NULL;
15839f40346SAlexander Shishkin 
15939f40346SAlexander Shishkin 	return to_intel_th_device(parent);
16039f40346SAlexander Shishkin }
16139f40346SAlexander Shishkin 
16239f40346SAlexander Shishkin struct intel_th *
16339f40346SAlexander Shishkin intel_th_alloc(struct device *dev, struct resource *devres,
16439f40346SAlexander Shishkin 	       unsigned int ndevres, int irq);
16539f40346SAlexander Shishkin void intel_th_free(struct intel_th *th);
16639f40346SAlexander Shishkin 
16739f40346SAlexander Shishkin int intel_th_driver_register(struct intel_th_driver *thdrv);
16839f40346SAlexander Shishkin void intel_th_driver_unregister(struct intel_th_driver *thdrv);
16939f40346SAlexander Shishkin 
17039f40346SAlexander Shishkin int intel_th_trace_enable(struct intel_th_device *thdev);
17139f40346SAlexander Shishkin int intel_th_trace_disable(struct intel_th_device *thdev);
17239f40346SAlexander Shishkin int intel_th_set_output(struct intel_th_device *thdev,
17339f40346SAlexander Shishkin 			unsigned int master);
17439f40346SAlexander Shishkin 
17539f40346SAlexander Shishkin enum {
17639f40346SAlexander Shishkin 	TH_MMIO_CONFIG = 0,
17739f40346SAlexander Shishkin 	TH_MMIO_SW = 2,
17839f40346SAlexander Shishkin 	TH_MMIO_END,
17939f40346SAlexander Shishkin };
18039f40346SAlexander Shishkin 
18139f40346SAlexander Shishkin #define TH_SUBDEVICE_MAX	6
18239f40346SAlexander Shishkin #define TH_POSSIBLE_OUTPUTS	8
18339f40346SAlexander Shishkin #define TH_CONFIGURABLE_MASTERS 256
18439f40346SAlexander Shishkin #define TH_MSC_MAX		2
18539f40346SAlexander Shishkin 
18639f40346SAlexander Shishkin /**
18739f40346SAlexander Shishkin  * struct intel_th - Intel TH controller
18839f40346SAlexander Shishkin  * @dev:	driver core's device
18939f40346SAlexander Shishkin  * @thdev:	subdevices
19039f40346SAlexander Shishkin  * @hub:	"switch" subdevice (GTH)
19139f40346SAlexander Shishkin  * @id:		this Intel TH controller's device ID in the system
19239f40346SAlexander Shishkin  * @major:	device node major for output devices
19339f40346SAlexander Shishkin  */
19439f40346SAlexander Shishkin struct intel_th {
19539f40346SAlexander Shishkin 	struct device		*dev;
19639f40346SAlexander Shishkin 
19739f40346SAlexander Shishkin 	struct intel_th_device	*thdev[TH_SUBDEVICE_MAX];
19839f40346SAlexander Shishkin 	struct intel_th_device	*hub;
19939f40346SAlexander Shishkin 
20039f40346SAlexander Shishkin 	int			id;
20139f40346SAlexander Shishkin 	int			major;
20239f40346SAlexander Shishkin #ifdef CONFIG_INTEL_TH_DEBUG
20339f40346SAlexander Shishkin 	struct dentry		*dbg;
20439f40346SAlexander Shishkin #endif
20539f40346SAlexander Shishkin };
20639f40346SAlexander Shishkin 
20739f40346SAlexander Shishkin /*
20839f40346SAlexander Shishkin  * Register windows
20939f40346SAlexander Shishkin  */
21039f40346SAlexander Shishkin enum {
21139f40346SAlexander Shishkin 	/* Global Trace Hub (GTH) */
21239f40346SAlexander Shishkin 	REG_GTH_OFFSET		= 0x0000,
21339f40346SAlexander Shishkin 	REG_GTH_LENGTH		= 0x2000,
21439f40346SAlexander Shishkin 
21539f40346SAlexander Shishkin 	/* Software Trace Hub (STH) [0x4000..0x4fff] */
21639f40346SAlexander Shishkin 	REG_STH_OFFSET		= 0x4000,
21739f40346SAlexander Shishkin 	REG_STH_LENGTH		= 0x2000,
21839f40346SAlexander Shishkin 
21939f40346SAlexander Shishkin 	/* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */
22039f40346SAlexander Shishkin 	REG_MSU_OFFSET		= 0xa0000,
22139f40346SAlexander Shishkin 	REG_MSU_LENGTH		= 0x02000,
22239f40346SAlexander Shishkin 
22339f40346SAlexander Shishkin 	/* Internal MSU trace buffer [0x80000..0x9ffff] */
22439f40346SAlexander Shishkin 	BUF_MSU_OFFSET		= 0x80000,
22539f40346SAlexander Shishkin 	BUF_MSU_LENGTH		= 0x20000,
22639f40346SAlexander Shishkin 
22739f40346SAlexander Shishkin 	/* PTI output == same window as GTH */
22839f40346SAlexander Shishkin 	REG_PTI_OFFSET		= REG_GTH_OFFSET,
22939f40346SAlexander Shishkin 	REG_PTI_LENGTH		= REG_GTH_LENGTH,
23039f40346SAlexander Shishkin 
23139f40346SAlexander Shishkin 	/* DCI Handler (DCIH) == some window as MSU */
23239f40346SAlexander Shishkin 	REG_DCIH_OFFSET		= REG_MSU_OFFSET,
23339f40346SAlexander Shishkin 	REG_DCIH_LENGTH		= REG_MSU_LENGTH,
23439f40346SAlexander Shishkin };
23539f40346SAlexander Shishkin 
23639f40346SAlexander Shishkin /*
23739f40346SAlexander Shishkin  * GTH, output ports configuration
23839f40346SAlexander Shishkin  */
23939f40346SAlexander Shishkin enum {
24039f40346SAlexander Shishkin 	GTH_NONE = 0,
24139f40346SAlexander Shishkin 	GTH_MSU,	/* memory/usb */
24239f40346SAlexander Shishkin 	GTH_CTP,	/* Common Trace Port */
24339f40346SAlexander Shishkin 	GTH_PTI = 4,	/* MIPI-PTI */
24439f40346SAlexander Shishkin };
24539f40346SAlexander Shishkin 
246*4d02ceffSAlexander Shishkin /*
247*4d02ceffSAlexander Shishkin  * Scratchpad bits: tell firmware and external debuggers
248*4d02ceffSAlexander Shishkin  * what we are up to.
249*4d02ceffSAlexander Shishkin  */
250*4d02ceffSAlexander Shishkin enum {
251*4d02ceffSAlexander Shishkin 	/* Memory is the primary destination */
252*4d02ceffSAlexander Shishkin 	SCRPD_MEM_IS_PRIM_DEST		= BIT(0),
253*4d02ceffSAlexander Shishkin 	/* XHCI DbC is the primary destination */
254*4d02ceffSAlexander Shishkin 	SCRPD_DBC_IS_PRIM_DEST		= BIT(1),
255*4d02ceffSAlexander Shishkin 	/* PTI is the primary destination */
256*4d02ceffSAlexander Shishkin 	SCRPD_PTI_IS_PRIM_DEST		= BIT(2),
257*4d02ceffSAlexander Shishkin 	/* BSSB is the primary destination */
258*4d02ceffSAlexander Shishkin 	SCRPD_BSSB_IS_PRIM_DEST		= BIT(3),
259*4d02ceffSAlexander Shishkin 	/* PTI is the alternate destination */
260*4d02ceffSAlexander Shishkin 	SCRPD_PTI_IS_ALT_DEST		= BIT(4),
261*4d02ceffSAlexander Shishkin 	/* BSSB is the alternate destination */
262*4d02ceffSAlexander Shishkin 	SCRPD_BSSB_IS_ALT_DEST		= BIT(5),
263*4d02ceffSAlexander Shishkin 	/* DeepSx exit occurred */
264*4d02ceffSAlexander Shishkin 	SCRPD_DEEPSX_EXIT		= BIT(6),
265*4d02ceffSAlexander Shishkin 	/* S4 exit occurred */
266*4d02ceffSAlexander Shishkin 	SCRPD_S4_EXIT			= BIT(7),
267*4d02ceffSAlexander Shishkin 	/* S5 exit occurred */
268*4d02ceffSAlexander Shishkin 	SCRPD_S5_EXIT			= BIT(8),
269*4d02ceffSAlexander Shishkin 	/* MSU controller 0/1 is enabled */
270*4d02ceffSAlexander Shishkin 	SCRPD_MSC0_IS_ENABLED		= BIT(9),
271*4d02ceffSAlexander Shishkin 	SCRPD_MSC1_IS_ENABLED		= BIT(10),
272*4d02ceffSAlexander Shishkin 	/* Sx exit occurred */
273*4d02ceffSAlexander Shishkin 	SCRPD_SX_EXIT			= BIT(11),
274*4d02ceffSAlexander Shishkin 	/* Trigger Unit is enabled */
275*4d02ceffSAlexander Shishkin 	SCRPD_TRIGGER_IS_ENABLED	= BIT(12),
276*4d02ceffSAlexander Shishkin 	SCRPD_ODLA_IS_ENABLED		= BIT(13),
277*4d02ceffSAlexander Shishkin 	SCRPD_SOCHAP_IS_ENABLED		= BIT(14),
278*4d02ceffSAlexander Shishkin 	SCRPD_STH_IS_ENABLED		= BIT(15),
279*4d02ceffSAlexander Shishkin 	SCRPD_DCIH_IS_ENABLED		= BIT(16),
280*4d02ceffSAlexander Shishkin 	SCRPD_VER_IS_ENABLED		= BIT(17),
281*4d02ceffSAlexander Shishkin 	/* External debugger is using Intel TH */
282*4d02ceffSAlexander Shishkin 	SCRPD_DEBUGGER_IN_USE		= BIT(24),
283*4d02ceffSAlexander Shishkin };
284*4d02ceffSAlexander Shishkin 
28539f40346SAlexander Shishkin #endif
286