coresight: etm3x: splitting struct etm_drvdata
[firefly-linux-kernel-4.4.55.git] / drivers / hwtracing / coresight / coresight-etm.h
1 /* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12
13 #ifndef _CORESIGHT_CORESIGHT_ETM_H
14 #define _CORESIGHT_CORESIGHT_ETM_H
15
16 #include <linux/spinlock.h>
17 #include "coresight-priv.h"
18
19 /*
20  * Device registers:
21  * 0x000 - 0x2FC: Trace         registers
22  * 0x300 - 0x314: Management    registers
23  * 0x318 - 0xEFC: Trace         registers
24  *
25  * Coresight registers
26  * 0xF00 - 0xF9C: Management    registers
27  * 0xFA0 - 0xFA4: Management    registers in PFTv1.0
28  *                Trace         registers in PFTv1.1
29  * 0xFA8 - 0xFFC: Management    registers
30  */
31
32 /* Trace registers (0x000-0x2FC) */
33 #define ETMCR                   0x000
34 #define ETMCCR                  0x004
35 #define ETMTRIGGER              0x008
36 #define ETMSR                   0x010
37 #define ETMSCR                  0x014
38 #define ETMTSSCR                0x018
39 #define ETMTECR2                0x01c
40 #define ETMTEEVR                0x020
41 #define ETMTECR1                0x024
42 #define ETMFFLR                 0x02c
43 #define ETMACVRn(n)             (0x040 + (n * 4))
44 #define ETMACTRn(n)             (0x080 + (n * 4))
45 #define ETMCNTRLDVRn(n)         (0x140 + (n * 4))
46 #define ETMCNTENRn(n)           (0x150 + (n * 4))
47 #define ETMCNTRLDEVRn(n)        (0x160 + (n * 4))
48 #define ETMCNTVRn(n)            (0x170 + (n * 4))
49 #define ETMSQ12EVR              0x180
50 #define ETMSQ21EVR              0x184
51 #define ETMSQ23EVR              0x188
52 #define ETMSQ31EVR              0x18c
53 #define ETMSQ32EVR              0x190
54 #define ETMSQ13EVR              0x194
55 #define ETMSQR                  0x19c
56 #define ETMEXTOUTEVRn(n)        (0x1a0 + (n * 4))
57 #define ETMCIDCVRn(n)           (0x1b0 + (n * 4))
58 #define ETMCIDCMR               0x1bc
59 #define ETMIMPSPEC0             0x1c0
60 #define ETMIMPSPEC1             0x1c4
61 #define ETMIMPSPEC2             0x1c8
62 #define ETMIMPSPEC3             0x1cc
63 #define ETMIMPSPEC4             0x1d0
64 #define ETMIMPSPEC5             0x1d4
65 #define ETMIMPSPEC6             0x1d8
66 #define ETMIMPSPEC7             0x1dc
67 #define ETMSYNCFR               0x1e0
68 #define ETMIDR                  0x1e4
69 #define ETMCCER                 0x1e8
70 #define ETMEXTINSELR            0x1ec
71 #define ETMTESSEICR             0x1f0
72 #define ETMEIBCR                0x1f4
73 #define ETMTSEVR                0x1f8
74 #define ETMAUXCR                0x1fc
75 #define ETMTRACEIDR             0x200
76 #define ETMVMIDCVR              0x240
77 /* Management registers (0x300-0x314) */
78 #define ETMOSLAR                0x300
79 #define ETMOSLSR                0x304
80 #define ETMOSSRR                0x308
81 #define ETMPDCR                 0x310
82 #define ETMPDSR                 0x314
83 #define ETM_MAX_ADDR_CMP        16
84 #define ETM_MAX_CNTR            4
85 #define ETM_MAX_CTXID_CMP       3
86
87 /* Register definition */
88 /* ETMCR - 0x00 */
89 #define ETMCR_PWD_DWN           BIT(0)
90 #define ETMCR_STALL_MODE        BIT(7)
91 #define ETMCR_ETM_PRG           BIT(10)
92 #define ETMCR_ETM_EN            BIT(11)
93 #define ETMCR_CYC_ACC           BIT(12)
94 #define ETMCR_CTXID_SIZE        (BIT(14)|BIT(15))
95 #define ETMCR_TIMESTAMP_EN      BIT(28)
96 /* ETMCCR - 0x04 */
97 #define ETMCCR_FIFOFULL         BIT(23)
98 /* ETMPDCR - 0x310 */
99 #define ETMPDCR_PWD_UP          BIT(3)
100 /* ETMTECR1 - 0x024 */
101 #define ETMTECR1_ADDR_COMP_1    BIT(0)
102 #define ETMTECR1_INC_EXC        BIT(24)
103 #define ETMTECR1_START_STOP     BIT(25)
104 /* ETMCCER - 0x1E8 */
105 #define ETMCCER_TIMESTAMP       BIT(22)
106
107 #define ETM_MODE_EXCLUDE        BIT(0)
108 #define ETM_MODE_CYCACC         BIT(1)
109 #define ETM_MODE_STALL          BIT(2)
110 #define ETM_MODE_TIMESTAMP      BIT(3)
111 #define ETM_MODE_CTXID          BIT(4)
112 #define ETM_MODE_ALL            0x1f
113
114 #define ETM_SQR_MASK            0x3
115 #define ETM_TRACEID_MASK        0x3f
116 #define ETM_EVENT_MASK          0x1ffff
117 #define ETM_SYNC_MASK           0xfff
118 #define ETM_ALL_MASK            0xffffffff
119
120 #define ETMSR_PROG_BIT          1
121 #define ETM_SEQ_STATE_MAX_VAL   (0x2)
122 #define PORT_SIZE_MASK          (GENMASK(21, 21) | GENMASK(6, 4))
123
124 #define ETM_HARD_WIRE_RES_A     /* Hard wired, always true */   \
125                                 ((0x0f << 0)    |               \
126                                 /* Resource index A */          \
127                                 (0x06 << 4))
128
129 #define ETM_ADD_COMP_0          /* Single addr comparator 1 */  \
130                                 ((0x00 << 7)    |               \
131                                 /* Resource index B */          \
132                                 (0x00 << 11))
133
134 #define ETM_EVENT_NOT_A         BIT(14) /* NOT(A) */
135
136 #define ETM_DEFAULT_EVENT_VAL   (ETM_HARD_WIRE_RES_A    |       \
137                                  ETM_ADD_COMP_0         |       \
138                                  ETM_EVENT_NOT_A)
139
140 /**
141  * struct etm_config - configuration information related to an ETM
142  * @mode:       controls various modes supported by this ETM/PTM.
143  * @ctrl:       used in conjunction with @mode.
144  * @trigger_event: setting for register ETMTRIGGER.
145  * @startstop_ctrl: setting for register ETMTSSCR.
146  * @enable_event: setting for register ETMTEEVR.
147  * @enable_ctrl1: setting for register ETMTECR1.
148  * @fifofull_level: setting for register ETMFFLR.
149  * @addr_idx:   index for the address comparator selection.
150  * @addr_val:   value for address comparator register.
151  * @addr_acctype: access type for address comparator register.
152  * @addr_type:  current status of the comparator register.
153  * @cntr_idx:   index for the counter register selection.
154  * @cntr_rld_val: reload value of a counter register.
155  * @cntr_event: control for counter enable register.
156  * @cntr_rld_event: value for counter reload event register.
157  * @cntr_val:   counter value register.
158  * @seq_12_event: event causing the transition from 1 to 2.
159  * @seq_21_event: event causing the transition from 2 to 1.
160  * @seq_23_event: event causing the transition from 2 to 3.
161  * @seq_31_event: event causing the transition from 3 to 1.
162  * @seq_32_event: event causing the transition from 3 to 2.
163  * @seq_13_event: event causing the transition from 1 to 3.
164  * @seq_curr_state: current value of the sequencer register.
165  * @ctxid_idx: index for the context ID registers.
166  * @ctxid_pid: value for the context ID to trigger on.
167  * @ctxid_vpid: Virtual PID seen by users if PID namespace is enabled, otherwise
168  *              the same value of ctxid_pid.
169  * @ctxid_mask: mask applicable to all the context IDs.
170  * @sync_freq:  Synchronisation frequency.
171  * @timestamp_event: Defines an event that requests the insertion
172  *                   of a timestamp into the trace stream.
173  */
174 struct etm_config {
175         u32                             mode;
176         u32                             ctrl;
177         u32                             trigger_event;
178         u32                             startstop_ctrl;
179         u32                             enable_event;
180         u32                             enable_ctrl1;
181         u32                             fifofull_level;
182         u8                              addr_idx;
183         u32                             addr_val[ETM_MAX_ADDR_CMP];
184         u32                             addr_acctype[ETM_MAX_ADDR_CMP];
185         u32                             addr_type[ETM_MAX_ADDR_CMP];
186         u8                              cntr_idx;
187         u32                             cntr_rld_val[ETM_MAX_CNTR];
188         u32                             cntr_event[ETM_MAX_CNTR];
189         u32                             cntr_rld_event[ETM_MAX_CNTR];
190         u32                             cntr_val[ETM_MAX_CNTR];
191         u32                             seq_12_event;
192         u32                             seq_21_event;
193         u32                             seq_23_event;
194         u32                             seq_31_event;
195         u32                             seq_32_event;
196         u32                             seq_13_event;
197         u32                             seq_curr_state;
198         u8                              ctxid_idx;
199         u32                             ctxid_pid[ETM_MAX_CTXID_CMP];
200         u32                             ctxid_vpid[ETM_MAX_CTXID_CMP];
201         u32                             ctxid_mask;
202         u32                             sync_freq;
203         u32                             timestamp_event;
204 };
205
206 /**
207  * struct etm_drvdata - specifics associated to an ETM component
208  * @base:       memory mapped base address for this component.
209  * @dev:        the device entity associated to this component.
210  * @atclk:      optional clock for the core parts of the ETM.
211  * @csdev:      component vitals needed by the framework.
212  * @spinlock:   only one at a time pls.
213  * @cpu:        the cpu this component is affined to.
214  * @port_size:  port size as reported by ETMCR bit 4-6 and 21.
215  * @arch:       ETM/PTM version number.
216  * @use_cpu14:  true if management registers need to be accessed via CP14.
217  * @enable:     is this ETM/PTM currently tracing.
218  * @sticky_enable: true if ETM base configuration has been done.
219  * @boot_enable:true if we should start tracing at boot time.
220  * @os_unlock:  true if access to management registers is allowed.
221  * @nr_addr_cmp:Number of pairs of address comparators as found in ETMCCR.
222  * @nr_cntr:    Number of counters as found in ETMCCR bit 13-15.
223  * @nr_ext_inp: Number of external input as found in ETMCCR bit 17-19.
224  * @nr_ext_out: Number of external output as found in ETMCCR bit 20-22.
225  * @nr_ctxid_cmp: Number of contextID comparators as found in ETMCCR bit 24-25.
226  * @etmccr:     value of register ETMCCR.
227  * @etmccer:    value of register ETMCCER.
228  * @traceid:    value of the current ID for this component.
229  * @config:     structure holding configuration parameters.
230  */
231 struct etm_drvdata {
232         void __iomem                    *base;
233         struct device                   *dev;
234         struct clk                      *atclk;
235         struct coresight_device         *csdev;
236         spinlock_t                      spinlock;
237         int                             cpu;
238         int                             port_size;
239         u8                              arch;
240         bool                            use_cp14;
241         bool                            enable;
242         bool                            sticky_enable;
243         bool                            boot_enable;
244         bool                            os_unlock;
245         u8                              nr_addr_cmp;
246         u8                              nr_cntr;
247         u8                              nr_ext_inp;
248         u8                              nr_ext_out;
249         u8                              nr_ctxid_cmp;
250         u32                             etmccr;
251         u32                             etmccer;
252         u32                             traceid;
253         struct etm_config               config;
254 };
255
256 enum etm_addr_type {
257         ETM_ADDR_TYPE_NONE,
258         ETM_ADDR_TYPE_SINGLE,
259         ETM_ADDR_TYPE_RANGE,
260         ETM_ADDR_TYPE_START,
261         ETM_ADDR_TYPE_STOP,
262 };
263
264 static inline void etm_writel(struct etm_drvdata *drvdata,
265                               u32 val, u32 off)
266 {
267         if (drvdata->use_cp14) {
268                 if (etm_writel_cp14(off, val)) {
269                         dev_err(drvdata->dev,
270                                 "invalid CP14 access to ETM reg: %#x", off);
271                 }
272         } else {
273                 writel_relaxed(val, drvdata->base + off);
274         }
275 }
276
277 static inline unsigned int etm_readl(struct etm_drvdata *drvdata, u32 off)
278 {
279         u32 val;
280
281         if (drvdata->use_cp14) {
282                 if (etm_readl_cp14(off, &val)) {
283                         dev_err(drvdata->dev,
284                                 "invalid CP14 access to ETM reg: %#x", off);
285                 }
286         } else {
287                 val = readl_relaxed(drvdata->base + off);
288         }
289
290         return val;
291 }
292
293 extern const struct attribute_group *coresight_etm_groups[];
294 int etm_get_trace_id(struct etm_drvdata *drvdata);
295 void etm_set_default(struct etm_config *config);
296 struct etm_config *get_etm_config(struct etm_drvdata *drvdata);
297 #endif