2014-11-04 02:07:35 +08:00
|
|
|
/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 and
|
|
|
|
* only version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CORESIGHT_PRIV_H
|
|
|
|
#define _CORESIGHT_PRIV_H
|
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/coresight.h>
|
2016-08-26 05:19:02 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2014-11-04 02:07:35 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Coresight management registers (0xf00-0xfcc)
|
|
|
|
* 0xfa0 - 0xfa4: Management registers in PFTv1.0
|
|
|
|
* Trace registers in PFTv1.1
|
|
|
|
*/
|
|
|
|
#define CORESIGHT_ITCTRL 0xf00
|
|
|
|
#define CORESIGHT_CLAIMSET 0xfa0
|
|
|
|
#define CORESIGHT_CLAIMCLR 0xfa4
|
|
|
|
#define CORESIGHT_LAR 0xfb0
|
|
|
|
#define CORESIGHT_LSR 0xfb4
|
|
|
|
#define CORESIGHT_AUTHSTATUS 0xfb8
|
|
|
|
#define CORESIGHT_DEVID 0xfc8
|
|
|
|
#define CORESIGHT_DEVTYPE 0xfcc
|
|
|
|
|
|
|
|
#define TIMEOUT_US 100
|
|
|
|
#define BMVAL(val, lsb, msb) ((val & GENMASK(msb, lsb)) >> lsb)
|
|
|
|
|
2016-02-18 08:51:56 +08:00
|
|
|
#define ETM_MODE_EXCL_KERN BIT(30)
|
|
|
|
#define ETM_MODE_EXCL_USER BIT(31)
|
|
|
|
|
2016-08-26 05:19:09 +08:00
|
|
|
typedef u32 (*coresight_read_fn)(const struct device *, u32 offset);
|
2017-08-03 00:22:05 +08:00
|
|
|
#define __coresight_simple_func(type, func, name, lo_off, hi_off) \
|
2016-04-06 01:53:50 +08:00
|
|
|
static ssize_t name##_show(struct device *_dev, \
|
|
|
|
struct device_attribute *attr, char *buf) \
|
|
|
|
{ \
|
|
|
|
type *drvdata = dev_get_drvdata(_dev->parent); \
|
2016-08-26 05:19:09 +08:00
|
|
|
coresight_read_fn fn = func; \
|
2017-08-03 00:22:05 +08:00
|
|
|
u64 val; \
|
2016-08-26 05:19:02 +08:00
|
|
|
pm_runtime_get_sync(_dev->parent); \
|
2016-08-26 05:19:09 +08:00
|
|
|
if (fn) \
|
2017-08-03 00:22:05 +08:00
|
|
|
val = (u64)fn(_dev->parent, lo_off); \
|
2016-08-26 05:19:09 +08:00
|
|
|
else \
|
2017-08-03 00:22:05 +08:00
|
|
|
val = coresight_read_reg_pair(drvdata->base, \
|
|
|
|
lo_off, hi_off); \
|
2016-08-26 05:19:02 +08:00
|
|
|
pm_runtime_put_sync(_dev->parent); \
|
2017-08-03 00:22:05 +08:00
|
|
|
return scnprintf(buf, PAGE_SIZE, "0x%llx\n", val); \
|
2016-04-06 01:53:50 +08:00
|
|
|
} \
|
|
|
|
static DEVICE_ATTR_RO(name)
|
|
|
|
|
2017-08-03 00:22:05 +08:00
|
|
|
#define coresight_simple_func(type, func, name, offset) \
|
|
|
|
__coresight_simple_func(type, func, name, offset, -1)
|
|
|
|
#define coresight_simple_reg32(type, name, offset) \
|
|
|
|
__coresight_simple_func(type, NULL, name, offset, -1)
|
|
|
|
#define coresight_simple_reg64(type, name, lo_off, hi_off) \
|
|
|
|
__coresight_simple_func(type, NULL, name, lo_off, hi_off)
|
|
|
|
|
2017-08-03 00:21:57 +08:00
|
|
|
extern const u32 barrier_pkt[5];
|
|
|
|
|
2016-08-26 05:19:11 +08:00
|
|
|
enum etm_addr_type {
|
|
|
|
ETM_ADDR_TYPE_NONE,
|
|
|
|
ETM_ADDR_TYPE_SINGLE,
|
|
|
|
ETM_ADDR_TYPE_RANGE,
|
|
|
|
ETM_ADDR_TYPE_START,
|
|
|
|
ETM_ADDR_TYPE_STOP,
|
|
|
|
};
|
|
|
|
|
2016-02-18 08:51:52 +08:00
|
|
|
enum cs_mode {
|
|
|
|
CS_MODE_DISABLED,
|
|
|
|
CS_MODE_SYSFS,
|
|
|
|
CS_MODE_PERF,
|
|
|
|
};
|
|
|
|
|
2016-05-04 01:33:58 +08:00
|
|
|
/**
|
|
|
|
* struct cs_buffer - keep track of a recording session' specifics
|
|
|
|
* @cur: index of the current buffer
|
|
|
|
* @nr_pages: max number of pages granted to us
|
|
|
|
* @offset: offset within the current buffer
|
|
|
|
* @data_size: how much we collected in this run
|
|
|
|
* @snapshot: is this run in snapshot mode
|
|
|
|
* @data_pages: a handle the ring buffer
|
|
|
|
*/
|
|
|
|
struct cs_buffers {
|
|
|
|
unsigned int cur;
|
|
|
|
unsigned int nr_pages;
|
|
|
|
unsigned long offset;
|
|
|
|
local_t data_size;
|
|
|
|
bool snapshot;
|
|
|
|
void **data_pages;
|
|
|
|
};
|
|
|
|
|
2014-11-04 02:07:35 +08:00
|
|
|
static inline void CS_LOCK(void __iomem *addr)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
/* Wait for things to settle */
|
|
|
|
mb();
|
|
|
|
writel_relaxed(0x0, addr + CORESIGHT_LAR);
|
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void CS_UNLOCK(void __iomem *addr)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
writel_relaxed(CORESIGHT_UNLOCK, addr + CORESIGHT_LAR);
|
2014-11-13 16:42:47 +08:00
|
|
|
/* Make sure everyone has seen this */
|
2014-11-04 02:07:35 +08:00
|
|
|
mb();
|
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
|
2017-08-03 00:22:05 +08:00
|
|
|
static inline u64
|
|
|
|
coresight_read_reg_pair(void __iomem *addr, s32 lo_offset, s32 hi_offset)
|
|
|
|
{
|
|
|
|
u64 val;
|
|
|
|
|
|
|
|
val = readl_relaxed(addr + lo_offset);
|
|
|
|
val |= (hi_offset < 0) ? 0 :
|
|
|
|
(u64)readl_relaxed(addr + hi_offset) << 32;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2017-08-03 00:22:07 +08:00
|
|
|
static inline void coresight_write_reg_pair(void __iomem *addr, u64 val,
|
|
|
|
s32 lo_offset, s32 hi_offset)
|
|
|
|
{
|
|
|
|
writel_relaxed((u32)val, addr + lo_offset);
|
|
|
|
if (hi_offset >= 0)
|
|
|
|
writel_relaxed((u32)(val >> 32), addr + hi_offset);
|
|
|
|
}
|
|
|
|
|
2016-02-18 08:51:45 +08:00
|
|
|
void coresight_disable_path(struct list_head *path);
|
2016-02-18 08:51:59 +08:00
|
|
|
int coresight_enable_path(struct list_head *path, u32 mode);
|
2016-02-18 08:51:46 +08:00
|
|
|
struct coresight_device *coresight_get_sink(struct list_head *path);
|
2016-11-30 00:47:14 +08:00
|
|
|
struct coresight_device *coresight_get_enabled_sink(bool reset);
|
|
|
|
struct list_head *coresight_build_path(struct coresight_device *csdev,
|
|
|
|
struct coresight_device *sink);
|
2016-02-18 08:51:45 +08:00
|
|
|
void coresight_release_path(struct list_head *path);
|
|
|
|
|
2014-11-04 02:07:35 +08:00
|
|
|
#ifdef CONFIG_CORESIGHT_SOURCE_ETM3X
|
|
|
|
extern int etm_readl_cp14(u32 off, unsigned int *val);
|
|
|
|
extern int etm_writel_cp14(u32 off, u32 val);
|
|
|
|
#else
|
|
|
|
static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
|
2015-01-27 00:22:25 +08:00
|
|
|
static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
|
2014-11-04 02:07:35 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|