xref: /linux/drivers/hwtracing/intel_th/msu.h (revision 976e3645923bdd2fe7893aae33fd7a21098bfb28)
1*fac7b714SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2ba82664cSAlexander Shishkin /*
3ba82664cSAlexander Shishkin  * Intel(R) Trace Hub Memory Storage Unit (MSU) data structures
4ba82664cSAlexander Shishkin  *
5ba82664cSAlexander Shishkin  * Copyright (C) 2014-2015 Intel Corporation.
6ba82664cSAlexander Shishkin  */
7ba82664cSAlexander Shishkin 
8ba82664cSAlexander Shishkin #ifndef __INTEL_TH_MSU_H__
9ba82664cSAlexander Shishkin #define __INTEL_TH_MSU_H__
10ba82664cSAlexander Shishkin 
11ba82664cSAlexander Shishkin enum {
12ba82664cSAlexander Shishkin 	REG_MSU_MSUPARAMS	= 0x0000,
13ba82664cSAlexander Shishkin 	REG_MSU_MSUSTS		= 0x0008,
14aac8da65SAlexander Shishkin 	REG_MSU_MINTCTL		= 0x0004, /* MSU-global interrupt control */
15ba82664cSAlexander Shishkin 	REG_MSU_MSC0CTL		= 0x0100, /* MSC0 control */
16ba82664cSAlexander Shishkin 	REG_MSU_MSC0STS		= 0x0104, /* MSC0 status */
17ba82664cSAlexander Shishkin 	REG_MSU_MSC0BAR		= 0x0108, /* MSC0 output base address */
18ba82664cSAlexander Shishkin 	REG_MSU_MSC0SIZE	= 0x010c, /* MSC0 output size */
19ba82664cSAlexander Shishkin 	REG_MSU_MSC0MWP		= 0x0110, /* MSC0 write pointer */
20ba82664cSAlexander Shishkin 	REG_MSU_MSC0NWSA	= 0x011c, /* MSC0 next window start address */
21ba82664cSAlexander Shishkin 
22ba82664cSAlexander Shishkin 	REG_MSU_MSC1CTL		= 0x0200, /* MSC1 control */
23ba82664cSAlexander Shishkin 	REG_MSU_MSC1STS		= 0x0204, /* MSC1 status */
24ba82664cSAlexander Shishkin 	REG_MSU_MSC1BAR		= 0x0208, /* MSC1 output base address */
25ba82664cSAlexander Shishkin 	REG_MSU_MSC1SIZE	= 0x020c, /* MSC1 output size */
26ba82664cSAlexander Shishkin 	REG_MSU_MSC1MWP		= 0x0210, /* MSC1 write pointer */
27ba82664cSAlexander Shishkin 	REG_MSU_MSC1NWSA	= 0x021c, /* MSC1 next window start address */
28ba82664cSAlexander Shishkin };
29ba82664cSAlexander Shishkin 
30ba82664cSAlexander Shishkin /* MSUSTS bits */
31ba82664cSAlexander Shishkin #define MSUSTS_MSU_INT	BIT(0)
32aac8da65SAlexander Shishkin #define MSUSTS_MSC0BLAST	BIT(16)
33aac8da65SAlexander Shishkin #define MSUSTS_MSC1BLAST	BIT(24)
34ba82664cSAlexander Shishkin 
35ba82664cSAlexander Shishkin /* MSCnCTL bits */
36ba82664cSAlexander Shishkin #define MSC_EN		BIT(0)
37ba82664cSAlexander Shishkin #define MSC_WRAPEN	BIT(1)
38ba82664cSAlexander Shishkin #define MSC_RD_HDR_OVRD	BIT(2)
39ba82664cSAlexander Shishkin #define MSC_MODE	(BIT(4) | BIT(5))
40ba82664cSAlexander Shishkin #define MSC_LEN		(BIT(8) | BIT(9) | BIT(10))
41ba82664cSAlexander Shishkin 
42aac8da65SAlexander Shishkin /* MINTCTL bits */
43aac8da65SAlexander Shishkin #define MICDE		BIT(0)
44aac8da65SAlexander Shishkin #define M0BLIE		BIT(16)
45aac8da65SAlexander Shishkin #define M1BLIE		BIT(24)
46aac8da65SAlexander Shishkin 
47ba82664cSAlexander Shishkin /* MSCnSTS bits */
48ba82664cSAlexander Shishkin #define MSCSTS_WRAPSTAT	BIT(1)	/* Wrap occurred */
49ba82664cSAlexander Shishkin #define MSCSTS_PLE	BIT(2)	/* Pipeline Empty */
50ba82664cSAlexander Shishkin 
51ba82664cSAlexander Shishkin /*
52ba82664cSAlexander Shishkin  * Multiblock/multiwindow block descriptor
53ba82664cSAlexander Shishkin  */
54ba82664cSAlexander Shishkin struct msc_block_desc {
55ba82664cSAlexander Shishkin 	u32	sw_tag;
56ba82664cSAlexander Shishkin 	u32	block_sz;
57ba82664cSAlexander Shishkin 	u32	next_blk;
58ba82664cSAlexander Shishkin 	u32	next_win;
59ba82664cSAlexander Shishkin 	u32	res0[4];
60ba82664cSAlexander Shishkin 	u32	hw_tag;
61ba82664cSAlexander Shishkin 	u32	valid_dw;
62ba82664cSAlexander Shishkin 	u32	ts_low;
63ba82664cSAlexander Shishkin 	u32	ts_high;
64ba82664cSAlexander Shishkin 	u32	res1[4];
65ba82664cSAlexander Shishkin } __packed;
66ba82664cSAlexander Shishkin 
67ba82664cSAlexander Shishkin #define MSC_BDESC	sizeof(struct msc_block_desc)
68ba82664cSAlexander Shishkin #define DATA_IN_PAGE	(PAGE_SIZE - MSC_BDESC)
69ba82664cSAlexander Shishkin 
70ba82664cSAlexander Shishkin /* MSC multiblock sw tag bits */
71ba82664cSAlexander Shishkin #define MSC_SW_TAG_LASTBLK	BIT(0)
72ba82664cSAlexander Shishkin #define MSC_SW_TAG_LASTWIN	BIT(1)
73ba82664cSAlexander Shishkin 
74ba82664cSAlexander Shishkin /* MSC multiblock hw tag bits */
75ba82664cSAlexander Shishkin #define MSC_HW_TAG_TRIGGER	BIT(0)
76ba82664cSAlexander Shishkin #define MSC_HW_TAG_BLOCKWRAP	BIT(1)
77ba82664cSAlexander Shishkin #define MSC_HW_TAG_WINWRAP	BIT(2)
78ba82664cSAlexander Shishkin #define MSC_HW_TAG_ENDBIT	BIT(3)
79ba82664cSAlexander Shishkin 
msc_data_sz(struct msc_block_desc * bdesc)80ba82664cSAlexander Shishkin static inline unsigned long msc_data_sz(struct msc_block_desc *bdesc)
81ba82664cSAlexander Shishkin {
82ba82664cSAlexander Shishkin 	if (!bdesc->valid_dw)
83ba82664cSAlexander Shishkin 		return 0;
84ba82664cSAlexander Shishkin 
85ba82664cSAlexander Shishkin 	return bdesc->valid_dw * 4 - MSC_BDESC;
86ba82664cSAlexander Shishkin }
87ba82664cSAlexander Shishkin 
msc_total_sz(struct msc_block_desc * bdesc)88615c164dSAlexander Shishkin static inline unsigned long msc_total_sz(struct msc_block_desc *bdesc)
89615c164dSAlexander Shishkin {
90615c164dSAlexander Shishkin 	return bdesc->valid_dw * 4;
91615c164dSAlexander Shishkin }
92615c164dSAlexander Shishkin 
msc_block_sz(struct msc_block_desc * bdesc)93615c164dSAlexander Shishkin static inline unsigned long msc_block_sz(struct msc_block_desc *bdesc)
94615c164dSAlexander Shishkin {
95615c164dSAlexander Shishkin 	return bdesc->block_sz * 64 - MSC_BDESC;
96615c164dSAlexander Shishkin }
97615c164dSAlexander Shishkin 
msc_block_wrapped(struct msc_block_desc * bdesc)98ba82664cSAlexander Shishkin static inline bool msc_block_wrapped(struct msc_block_desc *bdesc)
99ba82664cSAlexander Shishkin {
1004840572dSAlexander Shishkin 	if (bdesc->hw_tag & (MSC_HW_TAG_BLOCKWRAP | MSC_HW_TAG_WINWRAP))
101ba82664cSAlexander Shishkin 		return true;
102ba82664cSAlexander Shishkin 
103ba82664cSAlexander Shishkin 	return false;
104ba82664cSAlexander Shishkin }
105ba82664cSAlexander Shishkin 
msc_block_last_written(struct msc_block_desc * bdesc)106ba82664cSAlexander Shishkin static inline bool msc_block_last_written(struct msc_block_desc *bdesc)
107ba82664cSAlexander Shishkin {
108ba82664cSAlexander Shishkin 	if ((bdesc->hw_tag & MSC_HW_TAG_ENDBIT) ||
109615c164dSAlexander Shishkin 	    (msc_data_sz(bdesc) != msc_block_sz(bdesc)))
110ba82664cSAlexander Shishkin 		return true;
111ba82664cSAlexander Shishkin 
112ba82664cSAlexander Shishkin 	return false;
113ba82664cSAlexander Shishkin }
114ba82664cSAlexander Shishkin 
115ba82664cSAlexander Shishkin /* waiting for Pipeline Empty bit(s) to assert for MSC */
116ba82664cSAlexander Shishkin #define MSC_PLE_WAITLOOP_DEPTH	10000
117ba82664cSAlexander Shishkin 
118ba82664cSAlexander Shishkin #endif /* __INTEL_TH_MSU_H__ */
119