blob: cd536730735ac403e0b153de2df9c9cba3025314 [file] [log] [blame]
Satyajit Desaie30e3c52016-08-22 11:22:51 -07001#ifndef __LINUX_CORESIGHT_STM_H
2#define __LINUX_CORESIGHT_STM_H
Pratik Patel237483a2016-05-03 11:33:40 -06003
Satyajit Desaie30e3c52016-08-22 11:22:51 -07004#include <asm/local.h>
5#include <linux/stm.h>
6#include <linux/bitmap.h>
Pratik Patel237483a2016-05-03 11:33:40 -06007#include <uapi/linux/coresight-stm.h>
8
Satyajit Desaie30e3c52016-08-22 11:22:51 -07009#define BYTES_PER_CHANNEL 256
10
11enum stm_pkt_type {
12 STM_PKT_TYPE_DATA = 0x98,
13 STM_PKT_TYPE_FLAG = 0xE8,
14 STM_PKT_TYPE_TRIG = 0xF8,
15};
16
17#define stm_channel_off(type, opts) (type & ~opts)
18
19#define stm_channel_addr(drvdata, ch) (drvdata->chs.base + \
20 (ch * BYTES_PER_CHANNEL))
21
22#define stm_log_inv(entity_id, proto_id, data, size) \
23 stm_trace(STM_FLAG_NONE, entity_id, proto_id, data, size)
24
25#define stm_log_inv_ts(entity_id, proto_id, data, size) \
26 stm_trace(STM_FLAG_TIMESTAMPED, entity_id, proto_id, \
27 data, size)
28
29#define stm_log_gtd(entity_id, proto_id, data, size) \
30 stm_trace(STM_FLAG_GUARANTEED, entity_id, proto_id, \
31 data, size)
32
33#define stm_log_gtd_ts(entity_id, proto_id, data, size) \
34 stm_trace(STM_FLAG_GUARANTEED | STM_OPTION_TIMESTAMPED, \
35 entity_id, proto_id, data, size)
36
37#define stm_log(entity_id, data, size) \
38 stm_log_inv_ts(entity_id, 0, data, size)
39
40/**
41 * struct channel_space - central management entity for extended ports
42 * @base: memory mapped base address where channels start.
Kyle Yan65be4a52016-10-31 15:05:00 -070043 * @phys: physical base address of channel region.
Satyajit Desaie30e3c52016-08-22 11:22:51 -070044 * @guaraneed: is the channel delivery guaranteed.
45 * @bitmap: channel info for OST packet
46 */
47struct channel_space {
48 void __iomem *base;
Kyle Yan65be4a52016-10-31 15:05:00 -070049 phys_addr_t phys;
Satyajit Desaie30e3c52016-08-22 11:22:51 -070050 unsigned long *guaranteed;
51 unsigned long *bitmap;
52};
53
54/**
55 * struct stm_drvdata - specifics associated to an STM component
56 * @base: memory mapped base address for this component.
57 * @dev: the device entity associated to this component.
58 * @atclk: optional clock for the core parts of the STM.
59 * @csdev: component vitals needed by the framework.
60 * @spinlock: only one at a time pls.
61 * @chs: the channels accociated to this STM.
62 * @entities currently configured OST entities.
63 * @stm: structure associated to the generic STM interface.
64 * @mode: this tracer's mode, i.e sysFS, or disabled.
65 * @traceid: value of the current ID for this component.
66 * @write_bytes: Maximus bytes this STM can write at a time.
67 * @stmsper: settings for register STMSPER.
68 * @stmspscr: settings for register STMSPSCR.
69 * @numsp: the total number of stimulus port support by this STM.
70 * @stmheer: settings for register STMHEER.
71 * @stmheter: settings for register STMHETER.
72 * @stmhebsr: settings for register STMHEBSR.
Satyajit Desai262e85b2017-03-08 17:17:45 -080073 * @ch_alloc_fail_count: Number of ch allocation failures over time.
Satyajit Desaie30e3c52016-08-22 11:22:51 -070074 */
75struct stm_drvdata {
76 void __iomem *base;
77 struct device *dev;
78 struct clk *atclk;
79 struct coresight_device *csdev;
80 spinlock_t spinlock;
81 struct channel_space chs;
82 bool enable;
83 DECLARE_BITMAP(entities, OST_ENTITY_MAX);
84 struct stm_data stm;
85 local_t mode;
86 u8 traceid;
87 u32 write_bytes;
88 u32 stmsper;
89 u32 stmspscr;
90 u32 numsp;
91 u32 stmheer;
92 u32 stmheter;
93 u32 stmhebsr;
Satyajit Desai262e85b2017-03-08 17:17:45 -080094 u32 ch_alloc_fail_count;
Satyajit Desaie30e3c52016-08-22 11:22:51 -070095};
96
97#ifdef CONFIG_CORESIGHT_STM
98extern int stm_trace(uint32_t flags, uint8_t entity_id, uint8_t proto_id,
99 const void *data, uint32_t size);
100
101void stm_send(void *addr, const void *data, u32 size, u8 write_bytes);
102#else
103static inline int stm_trace(uint32_t flags, uint8_t entity_id,
104 uint8_t proto_id, const void *data, uint32_t size)
105{
106 return 0;
107}
108static inline void stm_send(void *addr, const void *data, u32 size,
109 u8 write_bytes) {}
110#endif
Pratik Patel237483a2016-05-03 11:33:40 -0600111#endif