xref: /linux/drivers/hwtracing/intel_th/msu.h (revision 4840572d3d7e66d7b55d3fc3b0f52711fd172eb8)
150352fa7SAlexander Shishkin // 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 /* MSC operating modes (MSC_MODE) */
48ba82664cSAlexander Shishkin enum {
49ba82664cSAlexander Shishkin 	MSC_MODE_SINGLE	= 0,
50ba82664cSAlexander Shishkin 	MSC_MODE_MULTI,
51ba82664cSAlexander Shishkin 	MSC_MODE_EXI,
52ba82664cSAlexander Shishkin 	MSC_MODE_DEBUG,
53ba82664cSAlexander Shishkin };
54ba82664cSAlexander Shishkin 
55ba82664cSAlexander Shishkin /* MSCnSTS bits */
56ba82664cSAlexander Shishkin #define MSCSTS_WRAPSTAT	BIT(1)	/* Wrap occurred */
57ba82664cSAlexander Shishkin #define MSCSTS_PLE	BIT(2)	/* Pipeline Empty */
58ba82664cSAlexander Shishkin 
59ba82664cSAlexander Shishkin /*
60ba82664cSAlexander Shishkin  * Multiblock/multiwindow block descriptor
61ba82664cSAlexander Shishkin  */
62ba82664cSAlexander Shishkin struct msc_block_desc {
63ba82664cSAlexander Shishkin 	u32	sw_tag;
64ba82664cSAlexander Shishkin 	u32	block_sz;
65ba82664cSAlexander Shishkin 	u32	next_blk;
66ba82664cSAlexander Shishkin 	u32	next_win;
67ba82664cSAlexander Shishkin 	u32	res0[4];
68ba82664cSAlexander Shishkin 	u32	hw_tag;
69ba82664cSAlexander Shishkin 	u32	valid_dw;
70ba82664cSAlexander Shishkin 	u32	ts_low;
71ba82664cSAlexander Shishkin 	u32	ts_high;
72ba82664cSAlexander Shishkin 	u32	res1[4];
73ba82664cSAlexander Shishkin } __packed;
74ba82664cSAlexander Shishkin 
75ba82664cSAlexander Shishkin #define MSC_BDESC	sizeof(struct msc_block_desc)
76ba82664cSAlexander Shishkin #define DATA_IN_PAGE	(PAGE_SIZE - MSC_BDESC)
77ba82664cSAlexander Shishkin 
78ba82664cSAlexander Shishkin /* MSC multiblock sw tag bits */
79ba82664cSAlexander Shishkin #define MSC_SW_TAG_LASTBLK	BIT(0)
80ba82664cSAlexander Shishkin #define MSC_SW_TAG_LASTWIN	BIT(1)
81ba82664cSAlexander Shishkin 
82ba82664cSAlexander Shishkin /* MSC multiblock hw tag bits */
83ba82664cSAlexander Shishkin #define MSC_HW_TAG_TRIGGER	BIT(0)
84ba82664cSAlexander Shishkin #define MSC_HW_TAG_BLOCKWRAP	BIT(1)
85ba82664cSAlexander Shishkin #define MSC_HW_TAG_WINWRAP	BIT(2)
86ba82664cSAlexander Shishkin #define MSC_HW_TAG_ENDBIT	BIT(3)
87ba82664cSAlexander Shishkin 
88ba82664cSAlexander Shishkin static inline unsigned long msc_data_sz(struct msc_block_desc *bdesc)
89ba82664cSAlexander Shishkin {
90ba82664cSAlexander Shishkin 	if (!bdesc->valid_dw)
91ba82664cSAlexander Shishkin 		return 0;
92ba82664cSAlexander Shishkin 
93ba82664cSAlexander Shishkin 	return bdesc->valid_dw * 4 - MSC_BDESC;
94ba82664cSAlexander Shishkin }
95ba82664cSAlexander Shishkin 
96ba82664cSAlexander Shishkin static inline bool msc_block_wrapped(struct msc_block_desc *bdesc)
97ba82664cSAlexander Shishkin {
98*4840572dSAlexander Shishkin 	if (bdesc->hw_tag & (MSC_HW_TAG_BLOCKWRAP | MSC_HW_TAG_WINWRAP))
99ba82664cSAlexander Shishkin 		return true;
100ba82664cSAlexander Shishkin 
101ba82664cSAlexander Shishkin 	return false;
102ba82664cSAlexander Shishkin }
103ba82664cSAlexander Shishkin 
104ba82664cSAlexander Shishkin static inline bool msc_block_last_written(struct msc_block_desc *bdesc)
105ba82664cSAlexander Shishkin {
106ba82664cSAlexander Shishkin 	if ((bdesc->hw_tag & MSC_HW_TAG_ENDBIT) ||
107ba82664cSAlexander Shishkin 	    (msc_data_sz(bdesc) != DATA_IN_PAGE))
108ba82664cSAlexander Shishkin 		return true;
109ba82664cSAlexander Shishkin 
110ba82664cSAlexander Shishkin 	return false;
111ba82664cSAlexander Shishkin }
112ba82664cSAlexander Shishkin 
113ba82664cSAlexander Shishkin /* waiting for Pipeline Empty bit(s) to assert for MSC */
114ba82664cSAlexander Shishkin #define MSC_PLE_WAITLOOP_DEPTH	10000
115ba82664cSAlexander Shishkin 
116ba82664cSAlexander Shishkin #endif /* __INTEL_TH_MSU_H__ */
117