2018-05-10 02:06:04 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-11-04 02:07:36 +08:00
|
|
|
/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
|
2016-02-18 08:52:03 +08:00
|
|
|
*
|
|
|
|
* Description: CoreSight Trace Memory Controller driver
|
2014-11-04 02:07:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/device.h>
|
2019-04-26 03:53:06 +08:00
|
|
|
#include <linux/idr.h>
|
2014-11-04 02:07:36 +08:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/miscdevice.h>
|
2019-04-26 03:53:06 +08:00
|
|
|
#include <linux/mutex.h>
|
2018-07-12 03:40:19 +08:00
|
|
|
#include <linux/property.h>
|
2014-11-04 02:07:36 +08:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/spinlock.h>
|
2015-05-20 00:55:13 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2014-11-04 02:07:36 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/coresight.h>
|
|
|
|
#include <linux/amba/bus.h>
|
|
|
|
|
|
|
|
#include "coresight-priv.h"
|
2016-05-04 01:33:48 +08:00
|
|
|
#include "coresight-tmc.h"
|
2014-11-04 02:07:36 +08:00
|
|
|
|
2019-06-20 03:53:04 +08:00
|
|
|
DEFINE_CORESIGHT_DEVLIST(etb_devs, "tmc_etb");
|
|
|
|
DEFINE_CORESIGHT_DEVLIST(etf_devs, "tmc_etf");
|
|
|
|
DEFINE_CORESIGHT_DEVLIST(etr_devs, "tmc_etr");
|
|
|
|
|
2016-05-04 01:33:50 +08:00
|
|
|
void tmc_wait_for_tmcready(struct tmc_drvdata *drvdata)
|
2014-11-04 02:07:36 +08:00
|
|
|
{
|
2021-02-02 02:13:27 +08:00
|
|
|
struct coresight_device *csdev = drvdata->csdev;
|
|
|
|
struct csdev_access *csa = &csdev->access;
|
|
|
|
|
2014-11-04 02:07:36 +08:00
|
|
|
/* Ensure formatter, unformatter and hardware fifo are empty */
|
2021-02-02 02:13:27 +08:00
|
|
|
if (coresight_timeout(csa, TMC_STS, TMC_STS_TMCREADY_BIT, 1)) {
|
|
|
|
dev_err(&csdev->dev,
|
2016-08-26 05:19:00 +08:00
|
|
|
"timeout while waiting for TMC to be Ready\n");
|
2014-11-04 02:07:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 01:33:50 +08:00
|
|
|
void tmc_flush_and_stop(struct tmc_drvdata *drvdata)
|
2014-11-04 02:07:36 +08:00
|
|
|
{
|
2021-02-02 02:13:27 +08:00
|
|
|
struct coresight_device *csdev = drvdata->csdev;
|
|
|
|
struct csdev_access *csa = &csdev->access;
|
2014-11-04 02:07:36 +08:00
|
|
|
u32 ffcr;
|
|
|
|
|
|
|
|
ffcr = readl_relaxed(drvdata->base + TMC_FFCR);
|
|
|
|
ffcr |= TMC_FFCR_STOP_ON_FLUSH;
|
|
|
|
writel_relaxed(ffcr, drvdata->base + TMC_FFCR);
|
2016-05-04 01:33:49 +08:00
|
|
|
ffcr |= BIT(TMC_FFCR_FLUSHMAN_BIT);
|
2014-11-04 02:07:36 +08:00
|
|
|
writel_relaxed(ffcr, drvdata->base + TMC_FFCR);
|
|
|
|
/* Ensure flush completes */
|
2021-02-02 02:13:27 +08:00
|
|
|
if (coresight_timeout(csa, TMC_FFCR, TMC_FFCR_FLUSHMAN_BIT, 0)) {
|
|
|
|
dev_err(&csdev->dev,
|
2016-08-26 05:19:00 +08:00
|
|
|
"timeout while waiting for completion of Manual Flush\n");
|
2014-11-04 02:07:36 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 01:33:44 +08:00
|
|
|
tmc_wait_for_tmcready(drvdata);
|
2014-11-04 02:07:36 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 01:33:50 +08:00
|
|
|
void tmc_enable_hw(struct tmc_drvdata *drvdata)
|
2014-11-04 02:07:36 +08:00
|
|
|
{
|
|
|
|
writel_relaxed(TMC_CTL_CAPT_EN, drvdata->base + TMC_CTL);
|
|
|
|
}
|
|
|
|
|
2016-05-04 01:33:50 +08:00
|
|
|
void tmc_disable_hw(struct tmc_drvdata *drvdata)
|
2014-11-04 02:07:36 +08:00
|
|
|
{
|
|
|
|
writel_relaxed(0x0, drvdata->base + TMC_CTL);
|
|
|
|
}
|
|
|
|
|
2019-08-30 04:28:40 +08:00
|
|
|
u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata)
|
|
|
|
{
|
|
|
|
u32 mask = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When moving RRP or an offset address forward, the new values must
|
|
|
|
* be byte-address aligned to the width of the trace memory databus
|
|
|
|
* _and_ to a frame boundary (16 byte), whichever is the biggest. For
|
|
|
|
* example, for 32-bit, 64-bit and 128-bit wide trace memory, the four
|
|
|
|
* LSBs must be 0s. For 256-bit wide trace memory, the five LSBs must
|
|
|
|
* be 0s.
|
|
|
|
*/
|
|
|
|
switch (drvdata->memwidth) {
|
|
|
|
case TMC_MEM_INTF_WIDTH_32BITS:
|
|
|
|
case TMC_MEM_INTF_WIDTH_64BITS:
|
|
|
|
case TMC_MEM_INTF_WIDTH_128BITS:
|
|
|
|
mask = GENMASK(31, 4);
|
|
|
|
break;
|
|
|
|
case TMC_MEM_INTF_WIDTH_256BITS:
|
|
|
|
mask = GENMASK(31, 5);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2014-11-04 02:07:36 +08:00
|
|
|
static int tmc_read_prepare(struct tmc_drvdata *drvdata)
|
|
|
|
{
|
2016-05-04 01:33:46 +08:00
|
|
|
int ret = 0;
|
2014-11-04 02:07:36 +08:00
|
|
|
|
2016-05-04 01:33:46 +08:00
|
|
|
switch (drvdata->config_type) {
|
|
|
|
case TMC_CONFIG_TYPE_ETB:
|
|
|
|
case TMC_CONFIG_TYPE_ETF:
|
2016-05-04 01:33:51 +08:00
|
|
|
ret = tmc_read_prepare_etb(drvdata);
|
2016-05-04 01:33:46 +08:00
|
|
|
break;
|
|
|
|
case TMC_CONFIG_TYPE_ETR:
|
2016-05-04 01:33:51 +08:00
|
|
|
ret = tmc_read_prepare_etr(drvdata);
|
2016-05-04 01:33:46 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
2014-11-04 02:07:36 +08:00
|
|
|
}
|
2016-05-04 01:33:46 +08:00
|
|
|
|
2016-05-04 01:33:51 +08:00
|
|
|
if (!ret)
|
2019-06-20 01:29:12 +08:00
|
|
|
dev_dbg(&drvdata->csdev->dev, "TMC read start\n");
|
2016-05-04 01:33:51 +08:00
|
|
|
|
2014-11-04 02:07:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-04 01:33:53 +08:00
|
|
|
static int tmc_read_unprepare(struct tmc_drvdata *drvdata)
|
2014-11-04 02:07:36 +08:00
|
|
|
{
|
2016-05-04 01:33:51 +08:00
|
|
|
int ret = 0;
|
2014-11-04 02:07:36 +08:00
|
|
|
|
2016-05-04 01:33:46 +08:00
|
|
|
switch (drvdata->config_type) {
|
|
|
|
case TMC_CONFIG_TYPE_ETB:
|
|
|
|
case TMC_CONFIG_TYPE_ETF:
|
2016-05-04 01:33:51 +08:00
|
|
|
ret = tmc_read_unprepare_etb(drvdata);
|
2016-05-04 01:33:46 +08:00
|
|
|
break;
|
|
|
|
case TMC_CONFIG_TYPE_ETR:
|
2016-05-04 01:33:51 +08:00
|
|
|
ret = tmc_read_unprepare_etr(drvdata);
|
2016-05-04 01:33:46 +08:00
|
|
|
break;
|
|
|
|
default:
|
2016-05-04 01:33:51 +08:00
|
|
|
ret = -EINVAL;
|
2014-11-04 02:07:36 +08:00
|
|
|
}
|
2016-05-04 01:33:46 +08:00
|
|
|
|
2016-05-04 01:33:51 +08:00
|
|
|
if (!ret)
|
2019-06-20 01:29:12 +08:00
|
|
|
dev_dbg(&drvdata->csdev->dev, "TMC read end\n");
|
2016-05-04 01:33:53 +08:00
|
|
|
|
|
|
|
return ret;
|
2014-11-04 02:07:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tmc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2016-05-04 01:33:53 +08:00
|
|
|
int ret;
|
2014-11-04 02:07:36 +08:00
|
|
|
struct tmc_drvdata *drvdata = container_of(file->private_data,
|
|
|
|
struct tmc_drvdata, miscdev);
|
|
|
|
|
|
|
|
ret = tmc_read_prepare(drvdata);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-05-04 01:33:53 +08:00
|
|
|
|
2014-11-04 02:07:36 +08:00
|
|
|
nonseekable_open(inode, file);
|
|
|
|
|
2019-06-20 01:29:12 +08:00
|
|
|
dev_dbg(&drvdata->csdev->dev, "%s: successfully opened\n", __func__);
|
2014-11-04 02:07:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-12 03:40:15 +08:00
|
|
|
static inline ssize_t tmc_get_sysfs_trace(struct tmc_drvdata *drvdata,
|
|
|
|
loff_t pos, size_t len, char **bufpp)
|
|
|
|
{
|
|
|
|
switch (drvdata->config_type) {
|
|
|
|
case TMC_CONFIG_TYPE_ETB:
|
|
|
|
case TMC_CONFIG_TYPE_ETF:
|
|
|
|
return tmc_etb_get_sysfs_trace(drvdata, pos, len, bufpp);
|
|
|
|
case TMC_CONFIG_TYPE_ETR:
|
|
|
|
return tmc_etr_get_sysfs_trace(drvdata, pos, len, bufpp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-11-04 02:07:36 +08:00
|
|
|
static ssize_t tmc_read(struct file *file, char __user *data, size_t len,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
2018-07-12 03:40:15 +08:00
|
|
|
char *bufp;
|
|
|
|
ssize_t actual;
|
2014-11-04 02:07:36 +08:00
|
|
|
struct tmc_drvdata *drvdata = container_of(file->private_data,
|
|
|
|
struct tmc_drvdata, miscdev);
|
2018-07-12 03:40:15 +08:00
|
|
|
actual = tmc_get_sysfs_trace(drvdata, *ppos, len, &bufp);
|
|
|
|
if (actual <= 0)
|
|
|
|
return 0;
|
2014-11-04 02:07:36 +08:00
|
|
|
|
2018-07-12 03:40:15 +08:00
|
|
|
if (copy_to_user(data, bufp, actual)) {
|
2019-06-20 01:29:12 +08:00
|
|
|
dev_dbg(&drvdata->csdev->dev,
|
|
|
|
"%s: copy_to_user failed\n", __func__);
|
2014-11-04 02:07:36 +08:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2018-07-12 03:40:15 +08:00
|
|
|
*ppos += actual;
|
2019-06-20 01:29:12 +08:00
|
|
|
dev_dbg(&drvdata->csdev->dev, "%zu bytes copied\n", actual);
|
2014-11-04 02:07:36 +08:00
|
|
|
|
2018-07-12 03:40:15 +08:00
|
|
|
return actual;
|
2014-11-04 02:07:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tmc_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
2016-05-04 01:33:53 +08:00
|
|
|
int ret;
|
2014-11-04 02:07:36 +08:00
|
|
|
struct tmc_drvdata *drvdata = container_of(file->private_data,
|
|
|
|
struct tmc_drvdata, miscdev);
|
|
|
|
|
2016-05-04 01:33:53 +08:00
|
|
|
ret = tmc_read_unprepare(drvdata);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-11-04 02:07:36 +08:00
|
|
|
|
2019-06-20 01:29:12 +08:00
|
|
|
dev_dbg(&drvdata->csdev->dev, "%s: released\n", __func__);
|
2014-11-04 02:07:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations tmc_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = tmc_open,
|
|
|
|
.read = tmc_read,
|
|
|
|
.release = tmc_release,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
};
|
|
|
|
|
2016-05-04 01:33:57 +08:00
|
|
|
static enum tmc_mem_intf_width tmc_get_memwidth(u32 devid)
|
|
|
|
{
|
|
|
|
enum tmc_mem_intf_width memwidth;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Excerpt from the TRM:
|
|
|
|
*
|
|
|
|
* DEVID::MEMWIDTH[10:8]
|
|
|
|
* 0x2 Memory interface databus is 32 bits wide.
|
|
|
|
* 0x3 Memory interface databus is 64 bits wide.
|
|
|
|
* 0x4 Memory interface databus is 128 bits wide.
|
|
|
|
* 0x5 Memory interface databus is 256 bits wide.
|
|
|
|
*/
|
|
|
|
switch (BMVAL(devid, 8, 10)) {
|
|
|
|
case 0x2:
|
|
|
|
memwidth = TMC_MEM_INTF_WIDTH_32BITS;
|
|
|
|
break;
|
|
|
|
case 0x3:
|
|
|
|
memwidth = TMC_MEM_INTF_WIDTH_64BITS;
|
|
|
|
break;
|
|
|
|
case 0x4:
|
|
|
|
memwidth = TMC_MEM_INTF_WIDTH_128BITS;
|
|
|
|
break;
|
|
|
|
case 0x5:
|
|
|
|
memwidth = TMC_MEM_INTF_WIDTH_256BITS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
memwidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return memwidth;
|
|
|
|
}
|
|
|
|
|
2017-08-03 00:22:06 +08:00
|
|
|
#define coresight_tmc_reg(name, offset) \
|
|
|
|
coresight_simple_reg32(struct tmc_drvdata, name, offset)
|
|
|
|
#define coresight_tmc_reg64(name, lo_off, hi_off) \
|
|
|
|
coresight_simple_reg64(struct tmc_drvdata, name, lo_off, hi_off)
|
|
|
|
|
|
|
|
coresight_tmc_reg(rsz, TMC_RSZ);
|
|
|
|
coresight_tmc_reg(sts, TMC_STS);
|
|
|
|
coresight_tmc_reg(trg, TMC_TRG);
|
|
|
|
coresight_tmc_reg(ctl, TMC_CTL);
|
|
|
|
coresight_tmc_reg(ffsr, TMC_FFSR);
|
|
|
|
coresight_tmc_reg(ffcr, TMC_FFCR);
|
|
|
|
coresight_tmc_reg(mode, TMC_MODE);
|
|
|
|
coresight_tmc_reg(pscr, TMC_PSCR);
|
2017-08-03 00:22:08 +08:00
|
|
|
coresight_tmc_reg(axictl, TMC_AXICTL);
|
2019-08-30 04:28:31 +08:00
|
|
|
coresight_tmc_reg(authstatus, TMC_AUTHSTATUS);
|
2017-08-03 00:22:06 +08:00
|
|
|
coresight_tmc_reg(devid, CORESIGHT_DEVID);
|
|
|
|
coresight_tmc_reg64(rrp, TMC_RRP, TMC_RRPHI);
|
|
|
|
coresight_tmc_reg64(rwp, TMC_RWP, TMC_RWPHI);
|
2017-08-03 00:22:08 +08:00
|
|
|
coresight_tmc_reg64(dba, TMC_DBALO, TMC_DBAHI);
|
2016-05-04 01:33:43 +08:00
|
|
|
|
|
|
|
static struct attribute *coresight_tmc_mgmt_attrs[] = {
|
|
|
|
&dev_attr_rsz.attr,
|
|
|
|
&dev_attr_sts.attr,
|
|
|
|
&dev_attr_rrp.attr,
|
|
|
|
&dev_attr_rwp.attr,
|
|
|
|
&dev_attr_trg.attr,
|
|
|
|
&dev_attr_ctl.attr,
|
|
|
|
&dev_attr_ffsr.attr,
|
|
|
|
&dev_attr_ffcr.attr,
|
|
|
|
&dev_attr_mode.attr,
|
|
|
|
&dev_attr_pscr.attr,
|
|
|
|
&dev_attr_devid.attr,
|
2017-08-03 00:22:08 +08:00
|
|
|
&dev_attr_dba.attr,
|
|
|
|
&dev_attr_axictl.attr,
|
2019-08-30 04:28:31 +08:00
|
|
|
&dev_attr_authstatus.attr,
|
2016-05-04 01:33:43 +08:00
|
|
|
NULL,
|
|
|
|
};
|
2015-03-31 04:13:40 +08:00
|
|
|
|
2016-09-09 06:50:39 +08:00
|
|
|
static ssize_t trigger_cntr_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2014-11-04 02:07:36 +08:00
|
|
|
{
|
|
|
|
struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);
|
|
|
|
unsigned long val = drvdata->trigger_cntr;
|
|
|
|
|
|
|
|
return sprintf(buf, "%#lx\n", val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t trigger_cntr_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long val;
|
|
|
|
struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);
|
|
|
|
|
|
|
|
ret = kstrtoul(buf, 16, &val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
drvdata->trigger_cntr = val;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RW(trigger_cntr);
|
|
|
|
|
2018-07-12 03:40:24 +08:00
|
|
|
static ssize_t buffer_size_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);
|
|
|
|
|
|
|
|
return sprintf(buf, "%#x\n", drvdata->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t buffer_size_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long val;
|
|
|
|
struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);
|
|
|
|
|
|
|
|
/* Only permitted for TMC-ETRs */
|
|
|
|
if (drvdata->config_type != TMC_CONFIG_TYPE_ETR)
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
ret = kstrtoul(buf, 0, &val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
/* The buffer size should be page aligned */
|
|
|
|
if (val & (PAGE_SIZE - 1))
|
|
|
|
return -EINVAL;
|
|
|
|
drvdata->size = val;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR_RW(buffer_size);
|
|
|
|
|
2016-05-04 01:33:43 +08:00
|
|
|
static struct attribute *coresight_tmc_attrs[] = {
|
2014-11-04 02:07:36 +08:00
|
|
|
&dev_attr_trigger_cntr.attr,
|
2018-07-12 03:40:24 +08:00
|
|
|
&dev_attr_buffer_size.attr,
|
2014-11-04 02:07:36 +08:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2016-05-04 01:33:43 +08:00
|
|
|
static const struct attribute_group coresight_tmc_group = {
|
|
|
|
.attrs = coresight_tmc_attrs,
|
2014-11-04 02:07:36 +08:00
|
|
|
};
|
|
|
|
|
2016-05-04 01:33:43 +08:00
|
|
|
static const struct attribute_group coresight_tmc_mgmt_group = {
|
|
|
|
.attrs = coresight_tmc_mgmt_attrs,
|
|
|
|
.name = "mgmt",
|
|
|
|
};
|
|
|
|
|
2020-05-19 02:02:35 +08:00
|
|
|
static const struct attribute_group *coresight_tmc_groups[] = {
|
2016-05-04 01:33:43 +08:00
|
|
|
&coresight_tmc_group,
|
|
|
|
&coresight_tmc_mgmt_group,
|
2014-11-04 02:07:36 +08:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2019-06-20 01:29:12 +08:00
|
|
|
static inline bool tmc_etr_can_use_sg(struct device *dev)
|
2018-07-12 03:40:19 +08:00
|
|
|
{
|
2019-06-20 01:29:12 +08:00
|
|
|
return fwnode_property_present(dev->fwnode, "arm,scatter-gather");
|
2018-07-12 03:40:19 +08:00
|
|
|
}
|
|
|
|
|
2019-08-30 04:28:31 +08:00
|
|
|
static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata)
|
|
|
|
{
|
|
|
|
u32 auth = readl_relaxed(drvdata->base + TMC_AUTHSTATUS);
|
|
|
|
|
|
|
|
return (auth & TMC_AUTH_NSID_MASK) == 0x3;
|
|
|
|
}
|
|
|
|
|
2017-08-03 00:22:11 +08:00
|
|
|
/* Detect and initialise the capabilities of a TMC ETR */
|
2019-06-20 01:29:12 +08:00
|
|
|
static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps)
|
2017-08-03 00:22:11 +08:00
|
|
|
{
|
2019-04-26 03:52:41 +08:00
|
|
|
int rc;
|
2017-08-03 00:22:13 +08:00
|
|
|
u32 dma_mask = 0;
|
2019-06-20 01:29:12 +08:00
|
|
|
struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
|
2017-08-03 00:22:13 +08:00
|
|
|
|
2019-08-30 04:28:31 +08:00
|
|
|
if (!tmc_etr_has_non_secure_access(drvdata))
|
|
|
|
return -EACCES;
|
|
|
|
|
2017-08-03 00:22:11 +08:00
|
|
|
/* Set the unadvertised capabilities */
|
|
|
|
tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps);
|
|
|
|
|
2019-06-20 01:29:12 +08:00
|
|
|
if (!(devid & TMC_DEVID_NOSCAT) && tmc_etr_can_use_sg(parent))
|
2017-08-03 00:22:12 +08:00
|
|
|
tmc_etr_set_cap(drvdata, TMC_ETR_SG);
|
2017-08-03 00:22:13 +08:00
|
|
|
|
|
|
|
/* Check if the AXI address width is available */
|
|
|
|
if (devid & TMC_DEVID_AXIAW_VALID)
|
|
|
|
dma_mask = ((devid >> TMC_DEVID_AXIAW_SHIFT) &
|
|
|
|
TMC_DEVID_AXIAW_MASK);
|
|
|
|
|
2017-08-03 00:22:11 +08:00
|
|
|
/*
|
2017-08-03 00:22:13 +08:00
|
|
|
* Unless specified in the device configuration, ETR uses a 40-bit
|
|
|
|
* AXI master in place of the embedded SRAM of ETB/ETF.
|
2017-08-03 00:22:11 +08:00
|
|
|
*/
|
2017-08-03 00:22:13 +08:00
|
|
|
switch (dma_mask) {
|
|
|
|
case 32:
|
|
|
|
case 40:
|
|
|
|
case 44:
|
|
|
|
case 48:
|
|
|
|
case 52:
|
2019-06-20 01:29:12 +08:00
|
|
|
dev_info(parent, "Detected dma mask %dbits\n", dma_mask);
|
2017-08-03 00:22:13 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dma_mask = 40;
|
|
|
|
}
|
|
|
|
|
2019-06-20 01:29:12 +08:00
|
|
|
rc = dma_set_mask_and_coherent(parent, DMA_BIT_MASK(dma_mask));
|
2019-04-26 03:52:41 +08:00
|
|
|
if (rc)
|
2019-06-20 01:29:12 +08:00
|
|
|
dev_err(parent, "Failed to setup DMA mask: %d\n", rc);
|
2019-04-26 03:52:41 +08:00
|
|
|
return rc;
|
2017-08-03 00:22:11 +08:00
|
|
|
}
|
|
|
|
|
2019-06-20 01:29:22 +08:00
|
|
|
static u32 tmc_etr_get_default_buffer_size(struct device *dev)
|
|
|
|
{
|
|
|
|
u32 size;
|
|
|
|
|
|
|
|
if (fwnode_property_read_u32(dev->fwnode, "arm,buffer-size", &size))
|
|
|
|
size = SZ_1M;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2021-09-01 21:10:49 +08:00
|
|
|
static u32 tmc_etr_get_max_burst_size(struct device *dev)
|
|
|
|
{
|
|
|
|
u32 burst_size;
|
|
|
|
|
|
|
|
if (fwnode_property_read_u32(dev->fwnode, "arm,max-burst-size",
|
|
|
|
&burst_size))
|
|
|
|
return TMC_AXICTL_WR_BURST_16;
|
|
|
|
|
|
|
|
/* Only permissible values are 0 to 15 */
|
|
|
|
if (burst_size > 0xF)
|
|
|
|
burst_size = TMC_AXICTL_WR_BURST_16;
|
|
|
|
|
|
|
|
return burst_size;
|
|
|
|
}
|
|
|
|
|
2014-11-04 02:07:36 +08:00
|
|
|
static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
u32 devid;
|
|
|
|
void __iomem *base;
|
|
|
|
struct device *dev = &adev->dev;
|
|
|
|
struct coresight_platform_data *pdata = NULL;
|
|
|
|
struct tmc_drvdata *drvdata;
|
|
|
|
struct resource *res = &adev->res;
|
2016-08-26 05:19:05 +08:00
|
|
|
struct coresight_desc desc = { 0 };
|
2019-06-20 03:53:04 +08:00
|
|
|
struct coresight_dev_list *dev_list = NULL;
|
2019-06-20 03:52:54 +08:00
|
|
|
|
2016-08-26 05:18:55 +08:00
|
|
|
ret = -ENOMEM;
|
2014-11-04 02:07:36 +08:00
|
|
|
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
|
|
|
|
if (!drvdata)
|
2016-08-26 05:18:55 +08:00
|
|
|
goto out;
|
|
|
|
|
2014-11-04 02:07:36 +08:00
|
|
|
dev_set_drvdata(dev, drvdata);
|
|
|
|
|
|
|
|
/* Validity for the resource is already checked by the AMBA core */
|
|
|
|
base = devm_ioremap_resource(dev, res);
|
2016-08-26 05:18:55 +08:00
|
|
|
if (IS_ERR(base)) {
|
|
|
|
ret = PTR_ERR(base);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-11-04 02:07:36 +08:00
|
|
|
|
|
|
|
drvdata->base = base;
|
2021-02-02 02:13:25 +08:00
|
|
|
desc.access = CSDEV_ACCESS_IOMEM(base);
|
2014-11-04 02:07:36 +08:00
|
|
|
|
|
|
|
spin_lock_init(&drvdata->spinlock);
|
|
|
|
|
|
|
|
devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID);
|
|
|
|
drvdata->config_type = BMVAL(devid, 6, 7);
|
2016-05-04 01:33:57 +08:00
|
|
|
drvdata->memwidth = tmc_get_memwidth(devid);
|
2019-04-26 03:53:08 +08:00
|
|
|
/* This device is not associated with a session */
|
|
|
|
drvdata->pid = -1;
|
2014-11-04 02:07:36 +08:00
|
|
|
|
2021-09-01 21:10:49 +08:00
|
|
|
if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) {
|
2019-06-20 01:29:22 +08:00
|
|
|
drvdata->size = tmc_etr_get_default_buffer_size(dev);
|
2021-09-01 21:10:49 +08:00
|
|
|
drvdata->max_burst_size = tmc_etr_get_max_burst_size(dev);
|
|
|
|
} else {
|
2014-11-04 02:07:36 +08:00
|
|
|
drvdata->size = readl_relaxed(drvdata->base + TMC_RSZ) * 4;
|
2021-09-01 21:10:49 +08:00
|
|
|
}
|
2014-11-04 02:07:36 +08:00
|
|
|
|
2016-08-26 05:19:05 +08:00
|
|
|
desc.dev = dev;
|
|
|
|
desc.groups = coresight_tmc_groups;
|
2014-11-04 02:07:36 +08:00
|
|
|
|
2017-08-03 00:22:10 +08:00
|
|
|
switch (drvdata->config_type) {
|
|
|
|
case TMC_CONFIG_TYPE_ETB:
|
2016-08-26 05:19:05 +08:00
|
|
|
desc.type = CORESIGHT_DEV_TYPE_SINK;
|
|
|
|
desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
|
|
|
|
desc.ops = &tmc_etb_cs_ops;
|
2019-06-20 03:53:04 +08:00
|
|
|
dev_list = &etb_devs;
|
2017-08-03 00:22:10 +08:00
|
|
|
break;
|
|
|
|
case TMC_CONFIG_TYPE_ETR:
|
2016-08-26 05:19:05 +08:00
|
|
|
desc.type = CORESIGHT_DEV_TYPE_SINK;
|
2020-07-17 01:57:44 +08:00
|
|
|
desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM;
|
2016-08-26 05:19:05 +08:00
|
|
|
desc.ops = &tmc_etr_cs_ops;
|
2019-06-20 01:29:12 +08:00
|
|
|
ret = tmc_etr_setup_caps(dev, devid,
|
ARM: 8838/1: drivers: amba: Updates to component identification for driver matching.
The CoreSight specification (ARM IHI 0029E), updates the ID register
requirements for components on an AMBA bus, to cover both traditional
ARM Primecell type devices, and newer CoreSight and other components.
The Peripheral ID (PID) / Component ID (CID) pair is extended in certain
cases to uniquely identify components. CoreSight components related to
a single function can share Peripheral ID values, and must be further
identified using a Unique Component Identifier (UCI). e.g. the ETM, CTI,
PMU and Debug hardware of the A35 all share the same PID.
Bits 15:12 of the CID are defined to be the device class.
Class 0xF remains for PrimeCell and legacy components.
Class 0x9 defines the component as CoreSight (CORESIGHT_CID above)
Class 0x0, 0x1, 0xB, 0xE define components that do not have driver support
at present.
Class 0x2-0x8,0xA and 0xD-0xD are presently reserved.
The specification futher defines which classes of device use the standard
CID/PID pair, and when additional ID registers are required.
This patch introduces the amba_cs_uci_id structure which will be used in
all coresight drivers for indentification via the private data pointer in
the amba_id structure.
Existing drivers that currently use the amba_id->data pointer for private
data are updated to use the amba_cs_uci_id->data pointer. Macros and
inline functions are added to simplify this code.
Signed-off-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Tested-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2019-02-13 21:41:49 +08:00
|
|
|
coresight_get_uci_data(id));
|
2017-06-06 04:15:09 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
2019-04-26 03:53:06 +08:00
|
|
|
idr_init(&drvdata->idr);
|
|
|
|
mutex_init(&drvdata->idr_mutex);
|
2019-06-20 03:53:04 +08:00
|
|
|
dev_list = &etr_devs;
|
2017-08-03 00:22:10 +08:00
|
|
|
break;
|
|
|
|
case TMC_CONFIG_TYPE_ETF:
|
2016-08-26 05:19:05 +08:00
|
|
|
desc.type = CORESIGHT_DEV_TYPE_LINKSINK;
|
2020-07-17 01:57:44 +08:00
|
|
|
desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
|
2016-08-26 05:19:05 +08:00
|
|
|
desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_FIFO;
|
|
|
|
desc.ops = &tmc_etf_cs_ops;
|
2019-06-20 03:53:04 +08:00
|
|
|
dev_list = &etf_devs;
|
2017-08-03 00:22:10 +08:00
|
|
|
break;
|
|
|
|
default:
|
2019-06-20 03:52:57 +08:00
|
|
|
pr_err("%s: Unsupported TMC config\n", desc.name);
|
2017-08-03 00:22:10 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2014-11-04 02:07:36 +08:00
|
|
|
}
|
|
|
|
|
2019-06-20 03:53:04 +08:00
|
|
|
desc.name = coresight_alloc_device_name(dev_list, dev);
|
|
|
|
if (!desc.name) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-06-20 03:53:00 +08:00
|
|
|
pdata = coresight_get_platform_data(dev);
|
|
|
|
if (IS_ERR(pdata)) {
|
|
|
|
ret = PTR_ERR(pdata);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
adev->dev.platform_data = pdata;
|
|
|
|
desc.pdata = pdata;
|
|
|
|
|
2016-08-26 05:19:05 +08:00
|
|
|
drvdata->csdev = coresight_register(&desc);
|
2014-11-04 02:07:36 +08:00
|
|
|
if (IS_ERR(drvdata->csdev)) {
|
|
|
|
ret = PTR_ERR(drvdata->csdev);
|
2016-08-26 05:18:55 +08:00
|
|
|
goto out;
|
2014-11-04 02:07:36 +08:00
|
|
|
}
|
|
|
|
|
2019-06-20 03:52:57 +08:00
|
|
|
drvdata->miscdev.name = desc.name;
|
2014-11-04 02:07:36 +08:00
|
|
|
drvdata->miscdev.minor = MISC_DYNAMIC_MINOR;
|
|
|
|
drvdata->miscdev.fops = &tmc_fops;
|
|
|
|
ret = misc_register(&drvdata->miscdev);
|
|
|
|
if (ret)
|
2016-08-26 05:18:55 +08:00
|
|
|
coresight_unregister(drvdata->csdev);
|
2019-04-26 03:52:50 +08:00
|
|
|
else
|
|
|
|
pm_runtime_put(&adev->dev);
|
2016-08-26 05:18:55 +08:00
|
|
|
out:
|
2014-11-04 02:07:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-17 01:57:41 +08:00
|
|
|
static void tmc_shutdown(struct amba_device *adev)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct tmc_drvdata *drvdata = amba_get_drvdata(adev);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&drvdata->spinlock, flags);
|
|
|
|
|
|
|
|
if (drvdata->mode == CS_MODE_DISABLED)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (drvdata->config_type == TMC_CONFIG_TYPE_ETR)
|
|
|
|
tmc_etr_disable_hw(drvdata);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not care about coresight unregister here unlike remove
|
|
|
|
* callback which is required for making coresight modular since
|
|
|
|
* the system is going down after this.
|
|
|
|
*/
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&drvdata->spinlock, flags);
|
|
|
|
}
|
|
|
|
|
2021-01-27 00:58:34 +08:00
|
|
|
static void tmc_remove(struct amba_device *adev)
|
2020-09-29 00:35:01 +08:00
|
|
|
{
|
|
|
|
struct tmc_drvdata *drvdata = dev_get_drvdata(&adev->dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since misc_open() holds a refcount on the f_ops, which is
|
|
|
|
* etb fops in this case, device is there until last file
|
|
|
|
* handler to this device is closed.
|
|
|
|
*/
|
|
|
|
misc_deregister(&drvdata->miscdev);
|
|
|
|
coresight_unregister(drvdata->csdev);
|
|
|
|
}
|
|
|
|
|
2017-08-25 00:36:04 +08:00
|
|
|
static const struct amba_id tmc_ids[] = {
|
ARM: 8838/1: drivers: amba: Updates to component identification for driver matching.
The CoreSight specification (ARM IHI 0029E), updates the ID register
requirements for components on an AMBA bus, to cover both traditional
ARM Primecell type devices, and newer CoreSight and other components.
The Peripheral ID (PID) / Component ID (CID) pair is extended in certain
cases to uniquely identify components. CoreSight components related to
a single function can share Peripheral ID values, and must be further
identified using a Unique Component Identifier (UCI). e.g. the ETM, CTI,
PMU and Debug hardware of the A35 all share the same PID.
Bits 15:12 of the CID are defined to be the device class.
Class 0xF remains for PrimeCell and legacy components.
Class 0x9 defines the component as CoreSight (CORESIGHT_CID above)
Class 0x0, 0x1, 0xB, 0xE define components that do not have driver support
at present.
Class 0x2-0x8,0xA and 0xD-0xD are presently reserved.
The specification futher defines which classes of device use the standard
CID/PID pair, and when additional ID registers are required.
This patch introduces the amba_cs_uci_id structure which will be used in
all coresight drivers for indentification via the private data pointer in
the amba_id structure.
Existing drivers that currently use the amba_id->data pointer for private
data are updated to use the amba_cs_uci_id->data pointer. Macros and
inline functions are added to simplify this code.
Signed-off-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Tested-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2019-02-13 21:41:49 +08:00
|
|
|
CS_AMBA_ID(0x000bb961),
|
|
|
|
/* Coresight SoC 600 TMC-ETR/ETS */
|
|
|
|
CS_AMBA_ID_DATA(0x000bb9e8, (unsigned long)CORESIGHT_SOC_600_ETR_CAPS),
|
|
|
|
/* Coresight SoC 600 TMC-ETB */
|
|
|
|
CS_AMBA_ID(0x000bb9e9),
|
|
|
|
/* Coresight SoC 600 TMC-ETF */
|
|
|
|
CS_AMBA_ID(0x000bb9ea),
|
2014-11-04 02:07:36 +08:00
|
|
|
{ 0, 0},
|
|
|
|
};
|
|
|
|
|
2020-09-29 00:35:01 +08:00
|
|
|
MODULE_DEVICE_TABLE(amba, tmc_ids);
|
|
|
|
|
2014-11-04 02:07:36 +08:00
|
|
|
static struct amba_driver tmc_driver = {
|
|
|
|
.drv = {
|
|
|
|
.name = "coresight-tmc",
|
|
|
|
.owner = THIS_MODULE,
|
2016-02-03 05:14:00 +08:00
|
|
|
.suppress_bind_attrs = true,
|
2014-11-04 02:07:36 +08:00
|
|
|
},
|
|
|
|
.probe = tmc_probe,
|
2020-07-17 01:57:41 +08:00
|
|
|
.shutdown = tmc_shutdown,
|
2020-09-29 00:35:01 +08:00
|
|
|
.remove = tmc_remove,
|
2014-11-04 02:07:36 +08:00
|
|
|
.id_table = tmc_ids,
|
|
|
|
};
|
2020-09-29 00:35:01 +08:00
|
|
|
|
|
|
|
module_amba_driver(tmc_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
|
|
|
|
MODULE_DESCRIPTION("Arm CoreSight Trace Memory Controller driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|