Linux Audio

Check our new training course

Loading...
v6.2
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
 
 
 
 
 
 
 
  4 */
  5
  6#ifndef _CORESIGHT_PRIV_H
  7#define _CORESIGHT_PRIV_H
  8
  9#include <linux/amba/bus.h>
 10#include <linux/bitops.h>
 11#include <linux/io.h>
 12#include <linux/coresight.h>
 13#include <linux/pm_runtime.h>
 14
 15/*
 16 * Coresight management registers (0xf00-0xfcc)
 17 * 0xfa0 - 0xfa4: Management	registers in PFTv1.0
 18 *		  Trace		registers in PFTv1.1
 19 */
 20#define CORESIGHT_ITCTRL	0xf00
 21#define CORESIGHT_CLAIMSET	0xfa0
 22#define CORESIGHT_CLAIMCLR	0xfa4
 23#define CORESIGHT_LAR		0xfb0
 24#define CORESIGHT_LSR		0xfb4
 25#define CORESIGHT_DEVARCH	0xfbc
 26#define CORESIGHT_AUTHSTATUS	0xfb8
 27#define CORESIGHT_DEVID		0xfc8
 28#define CORESIGHT_DEVTYPE	0xfcc
 29
 30
 31/*
 32 * Coresight device CLAIM protocol.
 33 * See PSCI - ARM DEN 0022D, Section: 6.8.1 Debug and Trace save and restore.
 34 */
 35#define CORESIGHT_CLAIM_SELF_HOSTED	BIT(1)
 36
 37#define TIMEOUT_US		100
 38#define BMVAL(val, lsb, msb)	((val & GENMASK(msb, lsb)) >> lsb)
 39
 40#define ETM_MODE_EXCL_KERN	BIT(30)
 41#define ETM_MODE_EXCL_USER	BIT(31)
 42struct cs_pair_attribute {
 43	struct device_attribute attr;
 44	u32 lo_off;
 45	u32 hi_off;
 46};
 47
 48struct cs_off_attribute {
 49	struct device_attribute attr;
 50	u32 off;
 51};
 52
 53extern ssize_t coresight_simple_show32(struct device *_dev,
 54				     struct device_attribute *attr, char *buf);
 55extern ssize_t coresight_simple_show_pair(struct device *_dev,
 56				     struct device_attribute *attr, char *buf);
 57
 58#define coresight_simple_reg32(name, offset)				\
 59	(&((struct cs_off_attribute[]) {				\
 60	   {								\
 61		__ATTR(name, 0444, coresight_simple_show32, NULL),	\
 62		offset							\
 63	   }								\
 64	})[0].attr.attr)
 65
 66#define coresight_simple_reg64(name, lo_off, hi_off)			\
 67	(&((struct cs_pair_attribute[]) {				\
 68	   {								\
 69		__ATTR(name, 0444, coresight_simple_show_pair, NULL),	\
 70		lo_off, hi_off						\
 71	   }								\
 72	})[0].attr.attr)
 
 
 
 
 
 73
 74extern const u32 coresight_barrier_pkt[4];
 75#define CORESIGHT_BARRIER_PKT_SIZE (sizeof(coresight_barrier_pkt))
 76
 77enum etm_addr_type {
 78	ETM_ADDR_TYPE_NONE,
 79	ETM_ADDR_TYPE_SINGLE,
 80	ETM_ADDR_TYPE_RANGE,
 81	ETM_ADDR_TYPE_START,
 82	ETM_ADDR_TYPE_STOP,
 83};
 84
 85enum cs_mode {
 86	CS_MODE_DISABLED,
 87	CS_MODE_SYSFS,
 88	CS_MODE_PERF,
 89};
 90
 91/**
 92 * struct cs_buffer - keep track of a recording session' specifics
 93 * @cur:	index of the current buffer
 94 * @nr_pages:	max number of pages granted to us
 95 * @pid:	PID this cs_buffer belongs to
 96 * @offset:	offset within the current buffer
 97 * @data_size:	how much we collected in this run
 98 * @snapshot:	is this run in snapshot mode
 99 * @data_pages:	a handle the ring buffer
100 */
101struct cs_buffers {
102	unsigned int		cur;
103	unsigned int		nr_pages;
104	pid_t			pid;
105	unsigned long		offset;
106	local_t			data_size;
107	bool			snapshot;
108	void			**data_pages;
109};
110
111static inline void coresight_insert_barrier_packet(void *buf)
112{
113	if (buf)
114		memcpy(buf, coresight_barrier_pkt, CORESIGHT_BARRIER_PKT_SIZE);
115}
116
117static inline void CS_LOCK(void __iomem *addr)
118{
119	do {
120		/* Wait for things to settle */
121		mb();
122		writel_relaxed(0x0, addr + CORESIGHT_LAR);
123	} while (0);
124}
125
126static inline void CS_UNLOCK(void __iomem *addr)
127{
128	do {
129		writel_relaxed(CORESIGHT_UNLOCK, addr + CORESIGHT_LAR);
130		/* Make sure everyone has seen this */
131		mb();
132	} while (0);
133}
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135void coresight_disable_path(struct list_head *path);
136int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data);
137struct coresight_device *coresight_get_sink(struct list_head *path);
138struct coresight_device *
139coresight_get_enabled_sink(struct coresight_device *source);
140struct coresight_device *coresight_get_sink_by_id(u32 id);
141struct coresight_device *
142coresight_find_default_sink(struct coresight_device *csdev);
143struct list_head *coresight_build_path(struct coresight_device *csdev,
144				       struct coresight_device *sink);
145void coresight_release_path(struct list_head *path);
146int coresight_add_sysfs_link(struct coresight_sysfs_link *info);
147void coresight_remove_sysfs_link(struct coresight_sysfs_link *info);
148int coresight_create_conns_sysfs_group(struct coresight_device *csdev);
149void coresight_remove_conns_sysfs_group(struct coresight_device *csdev);
150int coresight_make_links(struct coresight_device *orig,
151			 struct coresight_connection *conn,
152			 struct coresight_device *target);
153void coresight_remove_links(struct coresight_device *orig,
154			    struct coresight_connection *conn);
155
156#if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X)
157extern int etm_readl_cp14(u32 off, unsigned int *val);
158extern int etm_writel_cp14(u32 off, u32 val);
159#else
160static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
161static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
162#endif
163
164struct cti_assoc_op {
165	void (*add)(struct coresight_device *csdev);
166	void (*remove)(struct coresight_device *csdev);
167};
168
169extern void coresight_set_cti_ops(const struct cti_assoc_op *cti_op);
170extern void coresight_remove_cti_ops(void);
171
172/*
173 * Macros and inline functions to handle CoreSight UCI data and driver
174 * private data in AMBA ID table entries, and extract data values.
175 */
176
177/* coresight AMBA ID, no UCI, no driver data: id table entry */
178#define CS_AMBA_ID(pid)			\
179	{				\
180		.id	= pid,		\
181		.mask	= 0x000fffff,	\
182	}
183
184/* coresight AMBA ID, UCI with driver data only: id table entry. */
185#define CS_AMBA_ID_DATA(pid, dval)				\
186	{							\
187		.id	= pid,					\
188		.mask	= 0x000fffff,				\
189		.data	=  (void *)&(struct amba_cs_uci_id)	\
190			{				\
191				.data = (void *)dval,	\
192			}				\
193	}
194
195/* coresight AMBA ID, full UCI structure: id table entry. */
196#define CS_AMBA_UCI_ID(pid, uci_ptr)		\
197	{					\
198		.id	= pid,			\
199		.mask	= 0x000fffff,		\
200		.data	= (void *)uci_ptr	\
201	}
202
203/* extract the data value from a UCI structure given amba_id pointer. */
204static inline void *coresight_get_uci_data(const struct amba_id *id)
205{
206	struct amba_cs_uci_id *uci_id = id->data;
207
208	if (!uci_id)
209		return NULL;
210
211	return uci_id->data;
212}
213
214void coresight_release_platform_data(struct coresight_device *csdev,
215				     struct coresight_platform_data *pdata);
216struct coresight_device *
217coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode);
218void coresight_set_assoc_ectdev_mutex(struct coresight_device *csdev,
219				      struct coresight_device *ect_csdev);
220
221void coresight_set_percpu_sink(int cpu, struct coresight_device *csdev);
222struct coresight_device *coresight_get_percpu_sink(int cpu);
223
224#endif
v4.17
  1/* Copyright (c) 2011-2012, 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_PRIV_H
 14#define _CORESIGHT_PRIV_H
 15
 
 16#include <linux/bitops.h>
 17#include <linux/io.h>
 18#include <linux/coresight.h>
 19#include <linux/pm_runtime.h>
 20
 21/*
 22 * Coresight management registers (0xf00-0xfcc)
 23 * 0xfa0 - 0xfa4: Management	registers in PFTv1.0
 24 *		  Trace		registers in PFTv1.1
 25 */
 26#define CORESIGHT_ITCTRL	0xf00
 27#define CORESIGHT_CLAIMSET	0xfa0
 28#define CORESIGHT_CLAIMCLR	0xfa4
 29#define CORESIGHT_LAR		0xfb0
 30#define CORESIGHT_LSR		0xfb4
 
 31#define CORESIGHT_AUTHSTATUS	0xfb8
 32#define CORESIGHT_DEVID		0xfc8
 33#define CORESIGHT_DEVTYPE	0xfcc
 34
 
 
 
 
 
 
 
 35#define TIMEOUT_US		100
 36#define BMVAL(val, lsb, msb)	((val & GENMASK(msb, lsb)) >> lsb)
 37
 38#define ETM_MODE_EXCL_KERN	BIT(30)
 39#define ETM_MODE_EXCL_USER	BIT(31)
 
 
 
 
 
 
 
 
 
 
 40
 41typedef u32 (*coresight_read_fn)(const struct device *, u32 offset);
 42#define __coresight_simple_func(type, func, name, lo_off, hi_off)	\
 43static ssize_t name##_show(struct device *_dev,				\
 44			   struct device_attribute *attr, char *buf)	\
 45{									\
 46	type *drvdata = dev_get_drvdata(_dev->parent);			\
 47	coresight_read_fn fn = func;					\
 48	u64 val;							\
 49	pm_runtime_get_sync(_dev->parent);				\
 50	if (fn)								\
 51		val = (u64)fn(_dev->parent, lo_off);			\
 52	else								\
 53		val = coresight_read_reg_pair(drvdata->base,		\
 54						 lo_off, hi_off);	\
 55	pm_runtime_put_sync(_dev->parent);				\
 56	return scnprintf(buf, PAGE_SIZE, "0x%llx\n", val);		\
 57}									\
 58static DEVICE_ATTR_RO(name)
 59
 60#define coresight_simple_func(type, func, name, offset)			\
 61	__coresight_simple_func(type, func, name, offset, -1)
 62#define coresight_simple_reg32(type, name, offset)			\
 63	__coresight_simple_func(type, NULL, name, offset, -1)
 64#define coresight_simple_reg64(type, name, lo_off, hi_off)		\
 65	__coresight_simple_func(type, NULL, name, lo_off, hi_off)
 66
 67extern const u32 barrier_pkt[5];
 
 68
 69enum etm_addr_type {
 70	ETM_ADDR_TYPE_NONE,
 71	ETM_ADDR_TYPE_SINGLE,
 72	ETM_ADDR_TYPE_RANGE,
 73	ETM_ADDR_TYPE_START,
 74	ETM_ADDR_TYPE_STOP,
 75};
 76
 77enum cs_mode {
 78	CS_MODE_DISABLED,
 79	CS_MODE_SYSFS,
 80	CS_MODE_PERF,
 81};
 82
 83/**
 84 * struct cs_buffer - keep track of a recording session' specifics
 85 * @cur:	index of the current buffer
 86 * @nr_pages:	max number of pages granted to us
 
 87 * @offset:	offset within the current buffer
 88 * @data_size:	how much we collected in this run
 89 * @snapshot:	is this run in snapshot mode
 90 * @data_pages:	a handle the ring buffer
 91 */
 92struct cs_buffers {
 93	unsigned int		cur;
 94	unsigned int		nr_pages;
 
 95	unsigned long		offset;
 96	local_t			data_size;
 97	bool			snapshot;
 98	void			**data_pages;
 99};
100
 
 
 
 
 
 
101static inline void CS_LOCK(void __iomem *addr)
102{
103	do {
104		/* Wait for things to settle */
105		mb();
106		writel_relaxed(0x0, addr + CORESIGHT_LAR);
107	} while (0);
108}
109
110static inline void CS_UNLOCK(void __iomem *addr)
111{
112	do {
113		writel_relaxed(CORESIGHT_UNLOCK, addr + CORESIGHT_LAR);
114		/* Make sure everyone has seen this */
115		mb();
116	} while (0);
117}
118
119static inline u64
120coresight_read_reg_pair(void __iomem *addr, s32 lo_offset, s32 hi_offset)
121{
122	u64 val;
123
124	val = readl_relaxed(addr + lo_offset);
125	val |= (hi_offset < 0) ? 0 :
126	       (u64)readl_relaxed(addr + hi_offset) << 32;
127	return val;
128}
129
130static inline void coresight_write_reg_pair(void __iomem *addr, u64 val,
131						 s32 lo_offset, s32 hi_offset)
132{
133	writel_relaxed((u32)val, addr + lo_offset);
134	if (hi_offset >= 0)
135		writel_relaxed((u32)(val >> 32), addr + hi_offset);
136}
137
138void coresight_disable_path(struct list_head *path);
139int coresight_enable_path(struct list_head *path, u32 mode);
140struct coresight_device *coresight_get_sink(struct list_head *path);
141struct coresight_device *coresight_get_enabled_sink(bool reset);
 
 
 
 
142struct list_head *coresight_build_path(struct coresight_device *csdev,
143				       struct coresight_device *sink);
144void coresight_release_path(struct list_head *path);
 
 
 
 
 
 
 
 
 
145
146#ifdef CONFIG_CORESIGHT_SOURCE_ETM3X
147extern int etm_readl_cp14(u32 off, unsigned int *val);
148extern int etm_writel_cp14(u32 off, u32 val);
149#else
150static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
151static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
152#endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
154#endif