xref: /openbmc/linux/drivers/hwtracing/intel_th/intel_th.h (revision 5376be63ff4ff357d40dbe75c925d7cd5aef19a9)
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}
334d02ceffSAlexander 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;
454d02ceffSAlexander 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
57c49a7591SAlexander Shishkin  * @host_mode:		Intel TH is controlled by an external debug host
5839f40346SAlexander Shishkin  * @output:		output descriptor for INTEL_TH_OUTPUT devices
5939f40346SAlexander Shishkin  * @name:		device name to match the driver
6039f40346SAlexander Shishkin  */
6139f40346SAlexander Shishkin struct intel_th_device {
6239f40346SAlexander Shishkin 	struct device	dev;
6339f40346SAlexander Shishkin 	struct resource	*resource;
6439f40346SAlexander Shishkin 	unsigned int	num_resources;
6539f40346SAlexander Shishkin 	unsigned int	type;
6639f40346SAlexander Shishkin 	int		id;
6739f40346SAlexander Shishkin 
68c49a7591SAlexander Shishkin 	/* INTEL_TH_SWITCH specific */
69c49a7591SAlexander Shishkin 	bool			host_mode;
70c49a7591SAlexander Shishkin 
7139f40346SAlexander Shishkin 	/* INTEL_TH_OUTPUT specific */
7239f40346SAlexander Shishkin 	struct intel_th_output	output;
7339f40346SAlexander Shishkin 
7439f40346SAlexander Shishkin 	char		name[];
7539f40346SAlexander Shishkin };
7639f40346SAlexander Shishkin 
7739f40346SAlexander Shishkin #define to_intel_th_device(_d)				\
7839f40346SAlexander Shishkin 	container_of((_d), struct intel_th_device, dev)
7939f40346SAlexander Shishkin 
8039f40346SAlexander Shishkin /**
8139f40346SAlexander Shishkin  * intel_th_device_get_resource() - obtain @num'th resource of type @type
8239f40346SAlexander Shishkin  * @thdev:	the device to search the resource for
8339f40346SAlexander Shishkin  * @type:	resource type
8439f40346SAlexander Shishkin  * @num:	number of the resource
8539f40346SAlexander Shishkin  */
8639f40346SAlexander Shishkin static inline struct resource *
8739f40346SAlexander Shishkin intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type,
8839f40346SAlexander Shishkin 			     unsigned int num)
8939f40346SAlexander Shishkin {
9039f40346SAlexander Shishkin 	int i;
9139f40346SAlexander Shishkin 
9239f40346SAlexander Shishkin 	for (i = 0; i < thdev->num_resources; i++)
9339f40346SAlexander Shishkin 		if (resource_type(&thdev->resource[i]) == type && !num--)
9439f40346SAlexander Shishkin 			return &thdev->resource[i];
9539f40346SAlexander Shishkin 
9639f40346SAlexander Shishkin 	return NULL;
9739f40346SAlexander Shishkin }
9839f40346SAlexander Shishkin 
99*5376be63SAlexander Shishkin /*
100*5376be63SAlexander Shishkin  * GTH, output ports configuration
101*5376be63SAlexander Shishkin  */
102*5376be63SAlexander Shishkin enum {
103*5376be63SAlexander Shishkin 	GTH_NONE = 0,
104*5376be63SAlexander Shishkin 	GTH_MSU,	/* memory/usb */
105*5376be63SAlexander Shishkin 	GTH_CTP,	/* Common Trace Port */
106*5376be63SAlexander Shishkin 	GTH_PTI = 4,	/* MIPI-PTI */
107*5376be63SAlexander Shishkin };
108*5376be63SAlexander Shishkin 
10939f40346SAlexander Shishkin /**
11039f40346SAlexander Shishkin  * intel_th_output_assigned() - if an output device is assigned to a switch port
11139f40346SAlexander Shishkin  * @thdev:	the output device
11239f40346SAlexander Shishkin  *
11339f40346SAlexander Shishkin  * Return:	true if the device is INTEL_TH_OUTPUT *and* is assigned a port
11439f40346SAlexander Shishkin  */
11539f40346SAlexander Shishkin static inline bool
11639f40346SAlexander Shishkin intel_th_output_assigned(struct intel_th_device *thdev)
11739f40346SAlexander Shishkin {
11839f40346SAlexander Shishkin 	return thdev->type == INTEL_TH_OUTPUT &&
119*5376be63SAlexander Shishkin 		(thdev->output.port >= 0 ||
120*5376be63SAlexander Shishkin 		 thdev->output.type == GTH_NONE);
12139f40346SAlexander Shishkin }
12239f40346SAlexander Shishkin 
12339f40346SAlexander Shishkin /**
12439f40346SAlexander Shishkin  * struct intel_th_driver - driver for an intel_th_device device
12539f40346SAlexander Shishkin  * @driver:	generic driver
12639f40346SAlexander Shishkin  * @probe:	probe method
12739f40346SAlexander Shishkin  * @remove:	remove method
12839f40346SAlexander Shishkin  * @assign:	match a given output type device against available outputs
12939f40346SAlexander Shishkin  * @unassign:	deassociate an output type device from an output port
13039f40346SAlexander Shishkin  * @enable:	enable tracing for a given output device
13139f40346SAlexander Shishkin  * @disable:	disable tracing for a given output device
132bd581f23SAlexander Shishkin  * @irq:	interrupt callback
133bd581f23SAlexander Shishkin  * @activate:	enable tracing on the output's side
134bd581f23SAlexander Shishkin  * @deactivate:	disable tracing on the output's side
13539f40346SAlexander Shishkin  * @fops:	file operations for device nodes
136b5edbf1eSAlexander Shishkin  * @attr_group:	attributes provided by the driver
13739f40346SAlexander Shishkin  *
13839f40346SAlexander Shishkin  * Callbacks @probe and @remove are required for all device types.
13939f40346SAlexander Shishkin  * Switch device driver needs to fill in @assign, @enable and @disable
14039f40346SAlexander Shishkin  * callbacks.
14139f40346SAlexander Shishkin  */
14239f40346SAlexander Shishkin struct intel_th_driver {
14339f40346SAlexander Shishkin 	struct device_driver	driver;
14439f40346SAlexander Shishkin 	int			(*probe)(struct intel_th_device *thdev);
14539f40346SAlexander Shishkin 	void			(*remove)(struct intel_th_device *thdev);
14639f40346SAlexander Shishkin 	/* switch (GTH) ops */
14739f40346SAlexander Shishkin 	int			(*assign)(struct intel_th_device *thdev,
14839f40346SAlexander Shishkin 					  struct intel_th_device *othdev);
14939f40346SAlexander Shishkin 	void			(*unassign)(struct intel_th_device *thdev,
15039f40346SAlexander Shishkin 					    struct intel_th_device *othdev);
15139f40346SAlexander Shishkin 	void			(*enable)(struct intel_th_device *thdev,
15239f40346SAlexander Shishkin 					  struct intel_th_output *output);
15339f40346SAlexander Shishkin 	void			(*disable)(struct intel_th_device *thdev,
15439f40346SAlexander Shishkin 					   struct intel_th_output *output);
15539f40346SAlexander Shishkin 	/* output ops */
15639f40346SAlexander Shishkin 	void			(*irq)(struct intel_th_device *thdev);
15739f40346SAlexander Shishkin 	int			(*activate)(struct intel_th_device *thdev);
15839f40346SAlexander Shishkin 	void			(*deactivate)(struct intel_th_device *thdev);
15939f40346SAlexander Shishkin 	/* file_operations for those who want a device node */
16039f40346SAlexander Shishkin 	const struct file_operations *fops;
161b5edbf1eSAlexander Shishkin 	/* optional attributes */
162b5edbf1eSAlexander Shishkin 	struct attribute_group	*attr_group;
16339f40346SAlexander Shishkin 
16439f40346SAlexander Shishkin 	/* source ops */
16539f40346SAlexander Shishkin 	int			(*set_output)(struct intel_th_device *thdev,
16639f40346SAlexander Shishkin 					      unsigned int master);
16739f40346SAlexander Shishkin };
16839f40346SAlexander Shishkin 
16939f40346SAlexander Shishkin #define to_intel_th_driver(_d)					\
17039f40346SAlexander Shishkin 	container_of((_d), struct intel_th_driver, driver)
17139f40346SAlexander Shishkin 
172f18a9531SAlexander Shishkin #define to_intel_th_driver_or_null(_d)		\
173f18a9531SAlexander Shishkin 	((_d) ? to_intel_th_driver(_d) : NULL)
174f18a9531SAlexander Shishkin 
17539f40346SAlexander Shishkin static inline struct intel_th_device *
17639f40346SAlexander Shishkin to_intel_th_hub(struct intel_th_device *thdev)
17739f40346SAlexander Shishkin {
17839f40346SAlexander Shishkin 	struct device *parent = thdev->dev.parent;
17939f40346SAlexander Shishkin 
18039f40346SAlexander Shishkin 	if (!parent)
18139f40346SAlexander Shishkin 		return NULL;
18239f40346SAlexander Shishkin 
18339f40346SAlexander Shishkin 	return to_intel_th_device(parent);
18439f40346SAlexander Shishkin }
18539f40346SAlexander Shishkin 
18639f40346SAlexander Shishkin struct intel_th *
18739f40346SAlexander Shishkin intel_th_alloc(struct device *dev, struct resource *devres,
18839f40346SAlexander Shishkin 	       unsigned int ndevres, int irq);
18939f40346SAlexander Shishkin void intel_th_free(struct intel_th *th);
19039f40346SAlexander Shishkin 
19139f40346SAlexander Shishkin int intel_th_driver_register(struct intel_th_driver *thdrv);
19239f40346SAlexander Shishkin void intel_th_driver_unregister(struct intel_th_driver *thdrv);
19339f40346SAlexander Shishkin 
19439f40346SAlexander Shishkin int intel_th_trace_enable(struct intel_th_device *thdev);
19539f40346SAlexander Shishkin int intel_th_trace_disable(struct intel_th_device *thdev);
19639f40346SAlexander Shishkin int intel_th_set_output(struct intel_th_device *thdev,
19739f40346SAlexander Shishkin 			unsigned int master);
19839f40346SAlexander Shishkin 
19939f40346SAlexander Shishkin enum {
20039f40346SAlexander Shishkin 	TH_MMIO_CONFIG = 0,
20139f40346SAlexander Shishkin 	TH_MMIO_SW = 2,
20239f40346SAlexander Shishkin 	TH_MMIO_END,
20339f40346SAlexander Shishkin };
20439f40346SAlexander Shishkin 
20539f40346SAlexander Shishkin #define TH_SUBDEVICE_MAX	6
20639f40346SAlexander Shishkin #define TH_POSSIBLE_OUTPUTS	8
20739f40346SAlexander Shishkin #define TH_CONFIGURABLE_MASTERS 256
20839f40346SAlexander Shishkin #define TH_MSC_MAX		2
20939f40346SAlexander Shishkin 
21039f40346SAlexander Shishkin /**
21139f40346SAlexander Shishkin  * struct intel_th - Intel TH controller
21239f40346SAlexander Shishkin  * @dev:	driver core's device
21339f40346SAlexander Shishkin  * @thdev:	subdevices
21439f40346SAlexander Shishkin  * @hub:	"switch" subdevice (GTH)
21539f40346SAlexander Shishkin  * @id:		this Intel TH controller's device ID in the system
21639f40346SAlexander Shishkin  * @major:	device node major for output devices
21739f40346SAlexander Shishkin  */
21839f40346SAlexander Shishkin struct intel_th {
21939f40346SAlexander Shishkin 	struct device		*dev;
22039f40346SAlexander Shishkin 
22139f40346SAlexander Shishkin 	struct intel_th_device	*thdev[TH_SUBDEVICE_MAX];
22239f40346SAlexander Shishkin 	struct intel_th_device	*hub;
22339f40346SAlexander Shishkin 
22439f40346SAlexander Shishkin 	int			id;
22539f40346SAlexander Shishkin 	int			major;
226a36aa80fSAlexander Shishkin #ifdef CONFIG_MODULES
227a36aa80fSAlexander Shishkin 	struct work_struct	request_module_work;
228a36aa80fSAlexander Shishkin #endif /* CONFIG_MODULES */
22939f40346SAlexander Shishkin #ifdef CONFIG_INTEL_TH_DEBUG
23039f40346SAlexander Shishkin 	struct dentry		*dbg;
23139f40346SAlexander Shishkin #endif
23239f40346SAlexander Shishkin };
23339f40346SAlexander Shishkin 
23439f40346SAlexander Shishkin /*
23539f40346SAlexander Shishkin  * Register windows
23639f40346SAlexander Shishkin  */
23739f40346SAlexander Shishkin enum {
23839f40346SAlexander Shishkin 	/* Global Trace Hub (GTH) */
23939f40346SAlexander Shishkin 	REG_GTH_OFFSET		= 0x0000,
24039f40346SAlexander Shishkin 	REG_GTH_LENGTH		= 0x2000,
24139f40346SAlexander Shishkin 
24239f40346SAlexander Shishkin 	/* Software Trace Hub (STH) [0x4000..0x4fff] */
24339f40346SAlexander Shishkin 	REG_STH_OFFSET		= 0x4000,
24439f40346SAlexander Shishkin 	REG_STH_LENGTH		= 0x2000,
24539f40346SAlexander Shishkin 
24639f40346SAlexander Shishkin 	/* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */
24739f40346SAlexander Shishkin 	REG_MSU_OFFSET		= 0xa0000,
24839f40346SAlexander Shishkin 	REG_MSU_LENGTH		= 0x02000,
24939f40346SAlexander Shishkin 
25039f40346SAlexander Shishkin 	/* Internal MSU trace buffer [0x80000..0x9ffff] */
25139f40346SAlexander Shishkin 	BUF_MSU_OFFSET		= 0x80000,
25239f40346SAlexander Shishkin 	BUF_MSU_LENGTH		= 0x20000,
25339f40346SAlexander Shishkin 
25439f40346SAlexander Shishkin 	/* PTI output == same window as GTH */
25539f40346SAlexander Shishkin 	REG_PTI_OFFSET		= REG_GTH_OFFSET,
25639f40346SAlexander Shishkin 	REG_PTI_LENGTH		= REG_GTH_LENGTH,
25739f40346SAlexander Shishkin 
25839f40346SAlexander Shishkin 	/* DCI Handler (DCIH) == some window as MSU */
25939f40346SAlexander Shishkin 	REG_DCIH_OFFSET		= REG_MSU_OFFSET,
26039f40346SAlexander Shishkin 	REG_DCIH_LENGTH		= REG_MSU_LENGTH,
26139f40346SAlexander Shishkin };
26239f40346SAlexander Shishkin 
26339f40346SAlexander Shishkin /*
2644d02ceffSAlexander Shishkin  * Scratchpad bits: tell firmware and external debuggers
2654d02ceffSAlexander Shishkin  * what we are up to.
2664d02ceffSAlexander Shishkin  */
2674d02ceffSAlexander Shishkin enum {
2684d02ceffSAlexander Shishkin 	/* Memory is the primary destination */
2694d02ceffSAlexander Shishkin 	SCRPD_MEM_IS_PRIM_DEST		= BIT(0),
2704d02ceffSAlexander Shishkin 	/* XHCI DbC is the primary destination */
2714d02ceffSAlexander Shishkin 	SCRPD_DBC_IS_PRIM_DEST		= BIT(1),
2724d02ceffSAlexander Shishkin 	/* PTI is the primary destination */
2734d02ceffSAlexander Shishkin 	SCRPD_PTI_IS_PRIM_DEST		= BIT(2),
2744d02ceffSAlexander Shishkin 	/* BSSB is the primary destination */
2754d02ceffSAlexander Shishkin 	SCRPD_BSSB_IS_PRIM_DEST		= BIT(3),
2764d02ceffSAlexander Shishkin 	/* PTI is the alternate destination */
2774d02ceffSAlexander Shishkin 	SCRPD_PTI_IS_ALT_DEST		= BIT(4),
2784d02ceffSAlexander Shishkin 	/* BSSB is the alternate destination */
2794d02ceffSAlexander Shishkin 	SCRPD_BSSB_IS_ALT_DEST		= BIT(5),
2804d02ceffSAlexander Shishkin 	/* DeepSx exit occurred */
2814d02ceffSAlexander Shishkin 	SCRPD_DEEPSX_EXIT		= BIT(6),
2824d02ceffSAlexander Shishkin 	/* S4 exit occurred */
2834d02ceffSAlexander Shishkin 	SCRPD_S4_EXIT			= BIT(7),
2844d02ceffSAlexander Shishkin 	/* S5 exit occurred */
2854d02ceffSAlexander Shishkin 	SCRPD_S5_EXIT			= BIT(8),
2864d02ceffSAlexander Shishkin 	/* MSU controller 0/1 is enabled */
2874d02ceffSAlexander Shishkin 	SCRPD_MSC0_IS_ENABLED		= BIT(9),
2884d02ceffSAlexander Shishkin 	SCRPD_MSC1_IS_ENABLED		= BIT(10),
2894d02ceffSAlexander Shishkin 	/* Sx exit occurred */
2904d02ceffSAlexander Shishkin 	SCRPD_SX_EXIT			= BIT(11),
2914d02ceffSAlexander Shishkin 	/* Trigger Unit is enabled */
2924d02ceffSAlexander Shishkin 	SCRPD_TRIGGER_IS_ENABLED	= BIT(12),
2934d02ceffSAlexander Shishkin 	SCRPD_ODLA_IS_ENABLED		= BIT(13),
2944d02ceffSAlexander Shishkin 	SCRPD_SOCHAP_IS_ENABLED		= BIT(14),
2954d02ceffSAlexander Shishkin 	SCRPD_STH_IS_ENABLED		= BIT(15),
2964d02ceffSAlexander Shishkin 	SCRPD_DCIH_IS_ENABLED		= BIT(16),
2974d02ceffSAlexander Shishkin 	SCRPD_VER_IS_ENABLED		= BIT(17),
2984d02ceffSAlexander Shishkin 	/* External debugger is using Intel TH */
2994d02ceffSAlexander Shishkin 	SCRPD_DEBUGGER_IN_USE		= BIT(24),
3004d02ceffSAlexander Shishkin };
3014d02ceffSAlexander Shishkin 
30239f40346SAlexander Shishkin #endif
303