Skip to contentSkip to conversation

Add support for UltraSoc System Memory Buffer

PATCH Superseded Qi Liu 2 participants 8 messages Apr 16, 2022 – May 6, 2022

Subsystems (3)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Qi Liu

author
#0 lore raw

v5 cover Add support for UltraSoc System Memory Buffer

Add support for UltraSoc System Memory Buffer.

Change since v4:
- Add a simple document of SMB driver according to Suzuki's comment.
- Address the comments from Suzuki.
- https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v3:
- Modify the file header according to community specifications.
- Address the comments from Mathieu.
- Link:https://lore.kernel.org/linux-arm-kernel/[email protected]/ Change since v2:
- Move ultrasoc driver to drivers/hwtracing/coresight.
- Link:https://lists.linaro.org/pipermail/coresight/2021-November/007310.html

Change since v1:
- Drop the document of UltraSoc according to Mathieu's comment.
- Add comments to explain some private hardware settings.
- Address the comments from Mathieu.
- Link: https://lists.linaro.org/pipermail/coresight/2021-August/006842.html

Change since RFC:
- Move driver to drivers/hwtracing/coresight/ultrasoc.
- Remove ultrasoc-axi-com.c, as AXI-COM doesn't need to be configured in basic tracing function.
- Remove ultrasoc.c as SMB does not need to register with the ultrasoc core.
- Address the comments from Mathieu and Suzuki.
- Link: https://lists.linaro.org/pipermail/coresight/2021-June/006535.html

Qi Liu (2):
drivers/coresight: Add UltraSoc System Memory Buffer driver
Documentation: Add document for UltraSoc SMB drivers

 .../trace/coresight/ultrasoc-smb.rst          |  79 +++
 drivers/hwtracing/coresight/Kconfig           |  10 +
 drivers/hwtracing/coresight/Makefile          |   1 +
 drivers/hwtracing/coresight/ultrasoc-smb.c    | 643 ++++++++++++++++++
 drivers/hwtracing/coresight/ultrasoc-smb.h    | 106 +++
 5 files changed, 839 insertions(+)
 create mode 100644 Documentation/trace/coresight/ultrasoc-smb.rst
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h
Signature · 1 line
2.24.0
author
#1 lore raw

PATCH v5 1/2 drivers/coresight: Add UltraSoc System Memory Buffer driver

This patch adds driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these CPU instructions in system memory.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
 drivers/hwtracing/coresight/Kconfig        |  10 +
 drivers/hwtracing/coresight/Makefile       |   1 +
 drivers/hwtracing/coresight/ultrasoc-smb.c | 643 +++++++++++++++++++++
 drivers/hwtracing/coresight/ultrasoc-smb.h | 106 ++++
 4 files changed, 760 insertions(+)
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h
drivers/hwtracing/coresight/Kconfig +10 -0
index 514a9b8086e3..4380eb1a0a73 100644
@@ -201,4 +201,14 @@ config CORESIGHT_TRBE
 
 	  To compile this driver as a module, choose M here: the module will be
 	  called coresight-trbe.
+config ULTRASOC_SMB
+	tristate "Ultrasoc system memory buffer drivers"
+	depends on ACPI && ARM64 && CORESIGHT_LINKS_AND_SINKS
+	help
+	  This driver provides support for the Ultrasoc system memory buffer (SMB).
+	  SMB is responsible for receiving the trace data from Coresight ETM devices
+	  and storing them to a system buffer.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called ultrasoc-smb.
 endif
drivers/hwtracing/coresight/Makefile +1 -0
index b6c4a48140ec..344dba8d6ff8 100644
@@ -27,3 +27,4 @@ obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o
 obj-$(CONFIG_CORESIGHT_TRBE) += coresight-trbe.o
 coresight-cti-y := coresight-cti-core.o	coresight-cti-platform.o \
 		   coresight-cti-sysfs.o
+obj-$(CONFIG_ULTRASOC_SMB) += ultrasoc-smb.o
drivers/hwtracing/coresight/ultrasoc-smb.c new file +643 -0

643 lines not on this page · raw message

drivers/hwtracing/coresight/ultrasoc-smb.h new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.24.0
maintainer
#2 lore raw

Re: [PATCH v5 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver

Hi Qi Liu

Apologies for the delay. I have some more comments below.

Quoted 99 lines · Qi Liu

This patch adds driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these CPU instructions in system memory.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
  drivers/hwtracing/coresight/Kconfig        |  10 +
  drivers/hwtracing/coresight/Makefile       |   1 +
  drivers/hwtracing/coresight/ultrasoc-smb.c | 643 +++++++++++++++++++++
  drivers/hwtracing/coresight/ultrasoc-smb.h | 106 ++++
  4 files changed, 760 insertions(+)

create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h

drivers/hwtracing/coresight/Kconfig +10 -0
index 514a9b8086e3..4380eb1a0a73 100644
@@ -201,4 +201,14 @@ config CORESIGHT_TRBE
 
  	  To compile this driver as a module, choose M here: the module will be
  	  called coresight-trbe.
+config ULTRASOC_SMB
+	tristate "Ultrasoc system memory buffer drivers"
+	depends on ACPI && ARM64 && CORESIGHT_LINKS_AND_SINKS
+	help
+	  This driver provides support for the Ultrasoc system memory buffer (SMB).
+	  SMB is responsible for receiving the trace data from Coresight ETM devices
+	  and storing them to a system buffer.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called ultrasoc-smb.
  endif
drivers/hwtracing/coresight/Makefile +1 -0
index b6c4a48140ec..344dba8d6ff8 100644
@@ -27,3 +27,4 @@ obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o
  obj-$(CONFIG_CORESIGHT_TRBE) += coresight-trbe.o
  coresight-cti-y := coresight-cti-core.o	coresight-cti-platform.o \
  		   coresight-cti-sysfs.o
+obj-$(CONFIG_ULTRASOC_SMB) += ultrasoc-smb.o
drivers/hwtracing/coresight/ultrasoc-smb.c new file +47 -0
new file mode 100644
index 000000000000..9a93b7fc7bda
@@ -0,0 +1,643 @@
+// SPDX-License-Identifier: MIT/GPL
+/*
+ * Siemens System Memory Buffer driver.
+ * Copyright(c) 2021, HiSilicon Limited.
+ */
+
+#include <linux/acpi.h>
+#include <linux/circ_buf.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+
+#include "ultrasoc-smb.h"
+
+DEFINE_CORESIGHT_DEVLIST(sink_devs, "ultra_smb");
+
+#define ULTRASOC_SMB_DSM_UUID	"82ae1283-7f6a-4cbe-aa06-53e8fb24db18"
+
+static bool smb_buffer_is_empty(struct smb_drv_data *drvdata)
+{
+	u32 buf_status = readl(drvdata->base + SMB_LB_INT_STS);
+
+	return buf_status & BIT(0) ? false : true;
+}
+
+static bool smb_buffer_cmp_pointer(struct smb_drv_data *drvdata)
+{
+	u32 wr_offset, rd_offset;
+
+	wr_offset = readl(drvdata->base + SMB_LB_WR_ADDR);
+	rd_offset = readl(drvdata->base + SMB_LB_RD_ADDR);
+	return wr_offset == rd_offset;
+}
+
+static void smb_reset_buffer_status(struct smb_drv_data *drvdata)
+{
+	writel(0xf, drvdata->base + SMB_LB_INT_STS);
+}
+
+/* Purge data remaining in hardware path in case them influence next trace */
+static void smb_purge_data(struct smb_drv_data *drvdata)
+{
+	writel(0x1, drvdata->base + SMB_LB_PURGE);
+}
+
+static void smb_update_data_size(struct smb_drv_data *drvdata)

drivers/hwtracing/coresight/ultrasoc-smb.c line 57

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+{
+	struct smb_data_buffer *sdb = &drvdata->sdb;
+	u32 write_offset;
+
+	smb_purge_data(drvdata);
+	if (smb_buffer_cmp_pointer(drvdata)) {
+		if (smb_buffer_is_empty(drvdata))
+			sdb->data_size = 0;
+		else
+			sdb->data_size = sdb->buf_size;

What happens when the buffer is full ? Does the sink stop writing ? Or does it keep on overwriting in a circular buffer mode ? If it does keep overwriting, we would need to make sure to update the sdb->rd_offset so that we provide the latest data (in smb_read())? If it doesn't overwrite, I think this logic could be simpler (similar to the tmc-et* circular buffer mode calculation.

drivers/hwtracing/coresight/ultrasoc-smb.c line 70

Quoted 13 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +13 -0
+		return;
+	}
+
+	write_offset = readl(drvdata->base + SMB_LB_WR_ADDR) - sdb->start_addr;
+	sdb->data_size = CIRC_CNT(write_offset, sdb->rd_offset, sdb->buf_size);
+}
+
+static int smb_open(struct inode *inode, struct file *file)
+{
+	struct smb_drv_data *drvdata = container_of(file->private_data,
+					struct smb_drv_data, miscdev);
+
+	if (local_cmpxchg(&drvdata->reading, 0, 1))

I believe this must be done in the smb_read(). Please see my comment for smb_disable()

Quoted 227 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +227 -0
+		return -EBUSY;
+
+	return 0;
+}
+
+static ssize_t smb_read(struct file *file, char __user *data, size_t len,
+			loff_t *ppos)
+{
+	struct smb_drv_data *drvdata = container_of(file->private_data,
+						struct smb_drv_data, miscdev);
+	struct smb_data_buffer *sdb = &drvdata->sdb;
+	struct device *dev = &drvdata->csdev->dev;
+	unsigned long flags;
+	int to_copy = 0;
+
+	spin_lock_irqsave(&drvdata->spinlock, flags);
+
+	if (atomic_read(drvdata->csdev->refcnt)) {
+		spin_unlock_irqrestore(&drvdata->spinlock, flags);
+		return -EBUSY;
+	}
+
+	if (!sdb->data_size) {
+		smb_update_data_size(drvdata);
+		if (!sdb->data_size)
+			goto out;
+	}
+
+	to_copy = min(sdb->data_size, len);
+
+	/* Copy parts of trace data when read pointer wrap around SMB buffer */
+	if (sdb->rd_offset + to_copy > sdb->buf_size)
+		to_copy = sdb->buf_size - sdb->rd_offset;
+
+	if (copy_to_user(data, (void *)sdb->buf_base + sdb->rd_offset,
+			 to_copy)) {
+		dev_dbg(dev, "Failed to copy data to user.\n");
+		to_copy = -EFAULT;
+		goto out;
+	}
+
+	*ppos += to_copy;
+	sdb->data_size -= to_copy;
+	sdb->rd_offset += to_copy;
+	sdb->rd_offset %= sdb->buf_size;
+	writel(sdb->start_addr + sdb->rd_offset,
+	       drvdata->base + SMB_LB_RD_ADDR);
+	dev_dbg(dev, "%d bytes copied.\n", to_copy);
+out:
+	if (!sdb->data_size)
+		smb_reset_buffer_status(drvdata);
+	spin_unlock_irqrestore(&drvdata->spinlock, flags);
+	return to_copy;
+}
+
+static int smb_release(struct inode *inode, struct file *file)
+{
+	struct smb_drv_data *drvdata = container_of(file->private_data,
+						struct smb_drv_data, miscdev);
+	local_set(&drvdata->reading, 0);
+	return 0;
+}
+
+static const struct file_operations smb_fops = {
+	.owner		= THIS_MODULE,
+	.open		= smb_open,
+	.read		= smb_read,
+	.release	= smb_release,
+	.llseek		= no_llseek,
+};
+
+smb_reg(read_pos, SMB_LB_RD_ADDR);
+smb_reg(write_pos, SMB_LB_WR_ADDR);
+smb_reg(buf_status, SMB_LB_INT_STS);
+
+static ssize_t buf_size_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct smb_drv_data *drvdata = dev_get_drvdata(dev->parent);
+
+	return sysfs_emit(buf, "0x%lx\n", drvdata->sdb.buf_size);
+}
+static DEVICE_ATTR_RO(buf_size);
+
+static struct attribute *smb_sink_attrs[] = {
+	&dev_attr_read_pos.attr,
+	&dev_attr_write_pos.attr,
+	&dev_attr_buf_status.attr,
+	&dev_attr_buf_size.attr,
+	NULL,
+};
+
+static const struct attribute_group smb_sink_group = {
+	.attrs = smb_sink_attrs,
+	.name = "mgmt",
+};
+
+static const struct attribute_group *smb_sink_groups[] = {
+	&smb_sink_group,
+	NULL,
+};
+
+static int smb_set_perf_buffer(struct perf_output_handle *handle)
+{
+	struct cs_buffers *buf = etm_perf_sink_config(handle);
+	u32 head;
+
+	if (!buf)
+		return -EINVAL;
+
+	/* Wrap head around to the amount of space we have */
+	head = handle->head & ((buf->nr_pages << PAGE_SHIFT) - 1);
+
+	/* Find the page to write to and offset within that page */
+	buf->cur = head / PAGE_SIZE;
+	buf->offset = head % PAGE_SIZE;
+
+	local_set(&buf->data_size, 0);
+
+	return 0;
+}
+
+static void smb_enable_hw(struct smb_drv_data *drvdata)
+{
+	writel(0x1, drvdata->base + SMB_GLOBAL_EN);
+}
+
+static void smb_disable_hw(struct smb_drv_data *drvdata)
+{
+	writel(0x0, drvdata->base + SMB_GLOBAL_EN);
+}
+
+static int smb_enable_sysfs(struct coresight_device *csdev)
+{
+	struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+	unsigned long flags;
+	int ret = 0;
+
+	spin_lock_irqsave(&drvdata->spinlock, flags);
+	if (drvdata->mode == CS_MODE_PERF) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	if (drvdata->mode == CS_MODE_DISABLED) {
+		smb_enable_hw(drvdata);
+		drvdata->mode = CS_MODE_SYSFS;
+	}
+
+	atomic_inc(csdev->refcnt);
+out:
+	spin_unlock_irqrestore(&drvdata->spinlock, flags);
+	return ret;
+}
+
+static int smb_enable_perf(struct coresight_device *csdev, void *data)
+{
+	struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+	struct device *dev = &drvdata->csdev->dev;
+	struct perf_output_handle *handle = data;
+	struct cs_buffers *buf = etm_perf_sink_config(handle);
+	unsigned long flags;
+	int ret = 0;
+	pid_t pid;
+
+	spin_lock_irqsave(&drvdata->spinlock, flags);
+	if (drvdata->mode == CS_MODE_SYSFS) {
+		dev_dbg(dev, "Device is already in used by sysfs.\n");
+		ret = -EBUSY;
+		goto out;
+	}
+
+	/* Get a handle on the pid of the target process */
+	pid = buf->pid;
+	if (drvdata->pid != -1 && drvdata->pid != pid) { > +		dev_dbg(dev, "Device is already in used by other session.\n");
+		ret = -EBUSY;
+		goto out;
+	}
+
+	/* The sink is already enabled by this session */
+	if (drvdata->pid == pid) {
+		atomic_inc(csdev->refcnt);
+		goto out;
+	}
+
+	ret = smb_set_perf_buffer(handle);
+	if (ret)
+		goto out;
+
+	smb_enable_hw(drvdata);
+	drvdata->pid = pid;
+	drvdata->mode = CS_MODE_PERF;
+	atomic_inc(csdev->refcnt);
+out:
+	spin_unlock_irqrestore(&drvdata->spinlock, flags);
+	return ret;
+}
+
+static int smb_enable(struct coresight_device *csdev, u32 mode, void *data)
+{
+	struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+	int ret;
+
+	/* Do nothing if trace data is reading by other interface now */
+	if (local_read(&drvdata->reading))
+		return -EBUSY;
+ > +	switch (mode) {
+	case CS_MODE_SYSFS:
+		ret = smb_enable_sysfs(csdev);
+		break;
+	case CS_MODE_PERF:
+		ret = smb_enable_perf(csdev, data);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	if (ret)
+		return ret;
+	dev_dbg(&csdev->dev, "Ultrasoc SMB enabled.\n");
+
+	return 0;
+}
+
+static int smb_disable(struct coresight_device *csdev)
+{

drivers/hwtracing/coresight/ultrasoc-smb.c line 309

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+	struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+	unsigned long flags;
+
+	spin_lock_irqsave(&drvdata->spinlock, flags);
+
+	if (local_read(&drvdata->reading)) {
+		spin_unlock_irqrestore(&drvdata->spinlock, flags);
+		return -EBUSY;
+	}
+

This is a bit confusing. So, we don't allow "read" when a session is in progress (via refcnt check in smb_read()). But the flag, drvdata->reading is set as soon as we open(). And we fail the disable if the drvdata->reading is set. I guess, we should move the setting of the drvdata->reading to smb_read() and set it for the first case where we are able to read.
Otherwise we could see, something like:

CPU0: smb_enable() # success, SMB is on
CPU1: open(/dev/usmb0) # -> set drvdata->reading
..
CPU0: smb_disable() # returns EBUSY since drvdata->reading is on.
CPU1: read(fd) # returns EBUSY since there is a refcnt.

Quoted 104 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +104 -0
+	if (atomic_dec_return(csdev->refcnt)) {
+		spin_unlock_irqrestore(&drvdata->spinlock, flags);
+		return -EBUSY;
+	}
+
+	WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED);
+	smb_disable_hw(drvdata);
+	smb_purge_data(drvdata);
+
+	/*
+	 * In perf mode, sink->disable is called after sink->update_buffer, so
+	 * need to synchronize the read pointer to write pointer, to make sure
+	 * these purged data won't influence next trace.
+	 */
+	if (drvdata->mode == CS_MODE_PERF)
+		writel(readl(drvdata->base + SMB_LB_WR_ADDR),
+		       drvdata->base + SMB_LB_RD_ADDR);
+
+	/* Dissociate from the target process. */
+	drvdata->pid = -1;
+	drvdata->mode = CS_MODE_DISABLED;
+	spin_unlock_irqrestore(&drvdata->spinlock, flags);
+
+	dev_dbg(&csdev->dev, "Ultrasoc SMB disabled.\n");
+	return 0;
+}
+
+static void *smb_alloc_buffer(struct coresight_device *csdev,
+			      struct perf_event *event, void **pages,
+			      int nr_pages, bool overwrite)
+{
+	struct cs_buffers *buf;
+	int node;
+
+	node = (event->cpu == -1) ? NUMA_NO_NODE : cpu_to_node(event->cpu);
+	buf = kzalloc_node(sizeof(struct cs_buffers), GFP_KERNEL, node);
+	if (!buf)
+		return NULL;
+
+	buf->snapshot = overwrite;
+	buf->nr_pages = nr_pages;
+	buf->data_pages = pages;
+	buf->pid = task_pid_nr(event->owner);
+
+	return buf;
+}
+
+static void smb_free_buffer(void *config)
+{
+	struct cs_buffers *buf = config;
+
+	kfree(buf);
+}
+
+static void smb_sync_perf_buffer(struct smb_drv_data *drvdata,
+				 struct cs_buffers *buf,
+				 unsigned long data_size)
+{
+	struct smb_data_buffer *sdb = &drvdata->sdb;
+	char **dst_pages = (char **)buf->data_pages;
+	unsigned long page_offset = buf->offset;
+	unsigned int cur = buf->cur;
+	unsigned long to_copy;
+
+	while (data_size) {
+		unsigned long page_space = PAGE_SIZE - page_offset;
+
+		/* Copy parts of trace data when read pointer wrap around */
+		if (sdb->rd_offset + page_space > sdb->buf_size)
+			to_copy = sdb->buf_size - sdb->rd_offset;
+		else
+			to_copy = min(data_size, page_space);
+
+		memcpy_fromio(dst_pages[cur] + page_offset,
+			      sdb->buf_base + sdb->rd_offset, to_copy);
+
+		page_offset += to_copy;
+		if (page_offset >= PAGE_SIZE) {
+			page_offset = 0;
+			cur++;
+			cur %= buf->nr_pages;
+		}
+		data_size -= to_copy;
+		sdb->rd_offset += to_copy;
+		sdb->rd_offset %= sdb->buf_size;
+	}
+
+	sdb->data_size = 0;
+	writel(sdb->start_addr + sdb->rd_offset,
+	       drvdata->base + SMB_LB_RD_ADDR);
+	smb_reset_buffer_status(drvdata);
+}
+
+static unsigned long smb_update_buffer(struct coresight_device *csdev,
+				       struct perf_output_handle *handle,
+				       void *sink_config)
+{
+	struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+	struct smb_data_buffer *sdb = &drvdata->sdb;
+	struct cs_buffers *buf = sink_config;
+	unsigned long data_size = 0;
+	unsigned long flags;
+	bool lost = false;
+

drivers/hwtracing/coresight/ultrasoc-smb.c line 423

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+	if (!buf)
+		return 0;
+
+	spin_lock_irqsave(&drvdata->spinlock, flags);
+
+	/* Don't do anything if another tracer is using this sink. */
+	if (atomic_read(csdev->refcnt) != 1)
+		goto out;
+
+	smb_update_data_size(drvdata);

Are we allowed to call this when the SMB is ON ? In perf mode, we call the update_buffer() before disabling the "sink". So, care must be taken to stop the SMB if needed to make sure the registers are read properly.

Rest looks fine to me.

Suzuki

author
#3 lore raw

Re: [PATCH v5 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver

Hi Suzuki,

thanks for your review, some replies below.

Quoted 115 lines · Suzuki K Poulose

Hi Qi Liu

Apologies for the delay. I have some more comments below.

Quoted 112 lines · Qi Liu

This patch adds driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these CPU instructions in system memory.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
  drivers/hwtracing/coresight/Kconfig        |  10 + drivers/hwtracing/coresight/Makefile       |   1 + drivers/hwtracing/coresight/ultrasoc-smb.c | 643 +++++++++++++++++++++ drivers/hwtracing/coresight/ultrasoc-smb.h | 106 ++++

  4 files changed, 760 insertions(+)

  create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h

drivers/hwtracing/coresight/Kconfig +0 -0
index 514a9b8086e3..4380eb1a0a73 100644
@@ -201,4 +201,14 @@ config CORESIGHT_TRBE

        To compile this driver as a module, choose M here: the module will be called coresight-trbe.
+config ULTRASOC_SMB
+    tristate "Ultrasoc system memory buffer drivers"
+    depends on ACPI && ARM64 && CORESIGHT_LINKS_AND_SINKS
+    help
+      This driver provides support for the Ultrasoc system memory buffer (SMB).
+      SMB is responsible for receiving the trace data from Coresight ETM devices
+      and storing them to a system buffer.
+
+      To compile this driver as a module, choose M here: the module will be
+      called ultrasoc-smb.
  endif

drivers/hwtracing/coresight/Makefile +0 -0
index b6c4a48140ec..344dba8d6ff8 100644
@@ -27,3 +27,4 @@ obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o

  obj-$(CONFIG_CORESIGHT_TRBE) += coresight-trbe.o coresight-cti-y := coresight-cti-core.o    coresight-cti-platform.o \
             coresight-cti-sysfs.o

drivers/hwtracing/coresight/Makefile +1 -0
+obj-$(CONFIG_ULTRASOC_SMB) += ultrasoc-smb.o
drivers/hwtracing/coresight/ultrasoc-smb.c new file +41 -0
new file mode 100644
index 000000000000..9a93b7fc7bda
@@ -0,0 +1,643 @@
+// SPDX-License-Identifier: MIT/GPL
+/*
+ * Siemens System Memory Buffer driver.
+ * Copyright(c) 2021, HiSilicon Limited.
+ */
+
+#include <linux/acpi.h>
+#include <linux/circ_buf.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+
+#include "ultrasoc-smb.h"
+
+DEFINE_CORESIGHT_DEVLIST(sink_devs, "ultra_smb");
+
+#define ULTRASOC_SMB_DSM_UUID    "82ae1283-7f6a-4cbe-aa06-53e8fb24db18"
+
+static bool smb_buffer_is_empty(struct smb_drv_data *drvdata)
+{
+    u32 buf_status = readl(drvdata->base + SMB_LB_INT_STS);
+
+    return buf_status & BIT(0) ? false : true;
+}
+
+static bool smb_buffer_cmp_pointer(struct smb_drv_data *drvdata)
+{
+    u32 wr_offset, rd_offset;
+
+    wr_offset = readl(drvdata->base + SMB_LB_WR_ADDR);
+    rd_offset = readl(drvdata->base + SMB_LB_RD_ADDR);
+    return wr_offset == rd_offset;
+}
+
+static void smb_reset_buffer_status(struct smb_drv_data *drvdata)
+{
+    writel(0xf, drvdata->base + SMB_LB_INT_STS);
+}
+
+/* Purge data remaining in hardware path in case them influence next 

trace */

drivers/hwtracing/coresight/ultrasoc-smb.c new file +15 -0
+static void smb_purge_data(struct smb_drv_data *drvdata)
+{
+    writel(0x1, drvdata->base + SMB_LB_PURGE);
+}
+
+static void smb_update_data_size(struct smb_drv_data *drvdata)
+{
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+    u32 write_offset;
+
+    smb_purge_data(drvdata);
+    if (smb_buffer_cmp_pointer(drvdata)) {
+        if (smb_buffer_is_empty(drvdata))
+            sdb->data_size = 0;
+        else
Quoted 9 lines
Quoted 1 line

+            sdb->data_size = sdb->buf_size;

What happens when the buffer is full ? Does the sink stop writing ? Or does it keep on overwriting in a circular buffer mode ? If it does keep overwriting, we would need to make sure to update the sdb->rd_offset so that we provide the latest data (in smb_read())? If it doesn't overwrite, I think this logic could be simpler (similar to the tmc-et* circular buffer mode calculation.

sink will stop writing when the buffer is full, and I'll simplify this function like this:

static void smb_buffer_is_full(struct smb_drv_data *drvdata)

{
	if (smb_buffer_cmp_pointer(drvdata) && !smb_buffer_is_empty(drvdata))
		return true;
	return false;
}

static void smb_update_data_size(struct smb_drv_data *drvdata)

{
	struct smb_data_buffer *sdb = &drvdata->sdb;
	u32 write_offset;

	if (smb_buffer_is_full(drvdata)) {
		sdb->data_size = sdb->buf_size;
		return;
	}

	write_offset = readl(drvdata->base + SMB_LB_WR_ADDR) -
sdb->start_addr;
	sdb->data_size = CIRC_CNT(write_offset, sdb->rd_offset,

sdb->buf_size);
}

Quoted 11 lines
Quoted 11 lines

+        return;
+    }
+
+    write_offset = readl(drvdata->base + SMB_LB_WR_ADDR) - sdb->start_addr;
+    sdb->data_size = CIRC_CNT(write_offset, sdb->rd_offset, sdb->buf_size);

drivers/hwtracing/coresight/ultrasoc-smb.c new file +3 -0
+}
+
+static int smb_open(struct inode *inode, struct file *file)
Quoted 9 lines

drivers/hwtracing/coresight/ultrasoc-smb.c line 70

Quoted 5 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +5 -0
+{
+    struct smb_drv_data *drvdata = container_of(file->private_data,
+                    struct smb_drv_data, miscdev);
+
+    if (local_cmpxchg(&drvdata->reading, 0, 1))

I believe this must be done in the smb_read(). Please see my comment for smb_disable()

got it, I'll change this like:

static int smb_open(struct inode *inode, struct file *file)

{
	struct smb_drv_data *drvdata = container_of(file->private_data, struct 
smb_drv_data, miscdev);
	ret = 0;

	spin_lock_irqsave(&drvdata->spinlock, flags);

	if (drvdata->reading) {
		ret = -EBUSY;
		goto out;
	}

	if (drvdata->mode == CS_MODE_PERF) {
		ret = -EINVAL;
		goto out;
	}

	if (atomic_read(drvdata->csdev->refcnt))
		ret = -EBUSY;

out:

	spin_unlock_irqrestore(&drvdata->spinlock, flags);
	return ret;
}
Quoted 65 lines
Quoted 65 lines

+        return -EBUSY;

drivers/hwtracing/coresight/ultrasoc-smb.c new file +5 -0
+
+    return 0;
+}
+
+static ssize_t smb_read(struct file *file, char __user *data, size_t 

len,
+            loff_t *ppos)

drivers/hwtracing/coresight/ultrasoc-smb.c new file +24 -0
+{
+    struct smb_drv_data *drvdata = container_of(file->private_data,
+                        struct smb_drv_data, miscdev);
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+    struct device *dev = &drvdata->csdev->dev;
+    unsigned long flags;
+    int to_copy = 0;
+
+    spin_lock_irqsave(&drvdata->spinlock, flags);
+
+    if (atomic_read(drvdata->csdev->refcnt)) {
+        spin_unlock_irqrestore(&drvdata->spinlock, flags);
+        return -EBUSY;
+    }
+
+    if (!sdb->data_size) {
+        smb_update_data_size(drvdata);
+        if (!sdb->data_size)
+            goto out;
+    }
+
+    to_copy = min(sdb->data_size, len);
+
+    /* Copy parts of trace data when read pointer wrap around SMB 

buffer */
+    if (sdb->rd_offset + to_copy > sdb->buf_size) +        to_copy = sdb->buf_size - sdb->rd_offset;

drivers/hwtracing/coresight/ultrasoc-smb.c new file +30 -0
+
+    if (copy_to_user(data, (void *)sdb->buf_base + sdb->rd_offset,
+             to_copy)) {
+        dev_dbg(dev, "Failed to copy data to user.\n");
+        to_copy = -EFAULT;
+        goto out;
+    }
+
+    *ppos += to_copy;
+    sdb->data_size -= to_copy;
+    sdb->rd_offset += to_copy;
+    sdb->rd_offset %= sdb->buf_size;
+    writel(sdb->start_addr + sdb->rd_offset,
+           drvdata->base + SMB_LB_RD_ADDR);
+    dev_dbg(dev, "%d bytes copied.\n", to_copy);
+out:
+    if (!sdb->data_size)
+        smb_reset_buffer_status(drvdata);
+    spin_unlock_irqrestore(&drvdata->spinlock, flags);
+    return to_copy;
+}
+
+static int smb_release(struct inode *inode, struct file *file)
+{
+    struct smb_drv_data *drvdata = container_of(file->private_data,
+                        struct smb_drv_data, miscdev);
+    local_set(&drvdata->reading, 0);
+    return 0;
+}
+

[...]

Quoted 22 lines

drivers/hwtracing/coresight/ultrasoc-smb.c line 309

Quoted 13 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +13 -0
+
+static int smb_disable(struct coresight_device *csdev)
+{
+    struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+    unsigned long flags;
+
+    spin_lock_irqsave(&drvdata->spinlock, flags);
+
+    if (local_read(&drvdata->reading)) {
+        spin_unlock_irqrestore(&drvdata->spinlock, flags);
+        return -EBUSY;
+    }
+

This is a bit confusing. So, we don't allow "read" when a session is in progress (via refcnt check in smb_read()). But the flag, drvdata->reading is set as soon as we open(). And we fail the disable if the drvdata->reading is set. I guess, we should move the setting of the drvdata->reading to smb_read() and set it for the first case where we are able to read.
Otherwise we could see, something like:

Quoted 7 lines

CPU0: smb_enable()         # success, SMB is on
CPU1: open(/dev/usmb0) # -> set drvdata->reading
..
CPU0: smb_disable() # returns EBUSY since drvdata->reading is on.
CPU1: read(fd)      # returns EBUSY since there is a refcnt.

got it, I'll change this next version, thanks.

Quoted 13 lines
Quoted 12 lines

+    if (atomic_dec_return(csdev->refcnt)) {
+        spin_unlock_irqrestore(&drvdata->spinlock, flags); +        return -EBUSY;
+    }

drivers/hwtracing/coresight/ultrasoc-smb.c new file +7 -0
+
+    WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED);
+    smb_disable_hw(drvdata);
+    smb_purge_data(drvdata);
+
+    /*
+     * In perf mode, sink->disable is called after 
Quoted 1 line

sink->update_buffer, so

+    buf = kzalloc_node(sizeof(struct cs_buffers), GFP_KERNEL, node);

[...]

Quoted 18 lines
Quoted 18 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +18 -0
+
+static unsigned long smb_update_buffer(struct coresight_device *csdev,
+                       struct perf_output_handle *handle,
+                       void *sink_config)
+{
+    struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+    struct cs_buffers *buf = sink_config;
+    unsigned long data_size = 0;
+    unsigned long flags;
+    bool lost = false;
+
+    if (!buf)
+        return 0;
+
+    spin_lock_irqsave(&drvdata->spinlock, flags);
+
+    /* Don't do anything if another tracer is using this sink. */
Quoted 8 lines
Quoted 4 lines

+    if (atomic_read(csdev->refcnt) != 1)
+        goto out;
+
+    smb_update_data_size(drvdata);

Are we allowed to call this when the SMB is ON ? In perf mode, we call the update_buffer() before disabling the "sink". So, care must be taken to stop the SMB if needed to make sure the registers are read properly.

got it, will do disable smb before smb_update_data_size.

Quoted 7 lines

Rest looks fine to me.

Suzuki
.

Thanks,
Qi

author
#4 lore raw

PATCH v5 2/2 Documentation: Add document for UltraSoc SMB drivers

In reply to Qi Liu

This patch bring in a documentation for UltraSoc SMB drivers. It simple descripts the device, sysfs interface and the firmware bindings.

---
 .../trace/coresight/ultrasoc-smb.rst          | 79 +++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 Documentation/trace/coresight/ultrasoc-smb.rst
Documentation/trace/coresight/ultrasoc-smb.rst new file +79 -0
new file mode 100644
index 000000000000..024fa4492f42
@@ -0,0 +1,79 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======================================
+UltraSoc - HW Assisted Tracing on SoC
+======================================
+   :Author:   Qi Liu <[email protected]>
+   :Date:     March 2022
+
+Introduction
+------------
+
+UltraSoc SMB is a per SCCL hardware, and it provides a way to buffer and store
+CPU trace messages in a region of shared system memory. SMB is plugged as
+a coresight sink device and the corresponding trace generators (ETM) are
+plugged in as source devices.
+
+Sysfs files and directories
+---------------------------
+
+The SMB devices appear on the existing coresight bus alongside the other
+coresight devices::
+
+	$# ls /sys/bus/coresight/devices/
+	ultra_smb0   ultra_smb1   ultra_smb2   ultra_smb3
+
+The ``ultra_smb<N>`` named SMB associated with SCCL.::
+
+	$# ls /sys/bus/coresight/devices/ultra_smb0
+	enable_sink   mgmt
+	$# ls /sys/bus/coresight/devices/ultra_smb0/mgmt
+	buf_size  buf_status  read_pos  write_pos
+
+*Key file items are:-*
+   * ``read_pos``: Shows the value held by UltraSoc SMB Read Pointer register.
+   * ``write_pos``: Shows the value held by UltraSoc SMB Write Pointer register.
+   * ``buf_status``: Shows the value held by UltraSoc SMB status register.
+		     BIT(0) is zero means buffer is empty.
+   * ``buf_size``: Shows the buffer size of each UltraSoc SMB device.
+
+Firmware Bindings
+---------------------------
+
+Firmware binding of SMB device describes SMB device indentifier, resource
+information and graph structure.
+
+SMB is platform device and device id is "HISI03A1", resource of device is
+declared using the _CRS method. Each SMB must present two base address,
+the first one is the configuration base address of SMB device, the second
+one is the base address of shared system memory.
+
+examples::
+
+    Device(USMB) {                                               \
+      Name(_HID, "HISI03A1")                                     \
+      Name(_CRS, ResourceTemplate() {                            \
+          MEM_RESRC(0x95100000, 0x951FFFFF, 0x100000)            \
+          MEM_RESRC(0x50000000, 0x53FFFFFF, 0x4000000)           \
+      })                                                         \
+      Name(_DSD, Package() {                                     \
+        ToUUID("ab02a46b-74c7-45a2-bd68-f7d344ef2153"),          \
+        Package() {                                              \
+          0,                                                     \
+          1,                                                     \
+          Package() {                                            \
+            1,                                                   \
+            ToUUID("3ecbc8b6-1d0e-4fb3-8107-e627f805c6cd"),      \
+            8,                                                   \
+            Package() {0x8, 0, \_SB.S00.SL11.CL28.F008, 0},       \
+            Package() {0x9, 0, \_SB.S00.SL11.CL29.F009, 0},       \
+            Package() {0xa, 0, \_SB.S00.SL11.CL2A.F010, 0},       \
+            Package() {0xb, 0, \_SB.S00.SL11.CL2B.F011, 0},       \
+            Package() {0xc, 0, \_SB.S00.SL11.CL2C.F012, 0},       \
+            Package() {0xd, 0, \_SB.S00.SL11.CL2D.F013, 0},       \
+            Package() {0xe, 0, \_SB.S00.SL11.CL2E.F014, 0},       \
+            Package() {0xf, 0, \_SB.S00.SL11.CL2F.F015, 0},       \
+          }                                                      \
+        }                                                        \
+      })                                                         \
+    }
Signature · 1 line
2.24.0
maintainer
#5 lore raw

Re: [PATCH v5 2/2] Documentation: Add document for UltraSoc SMB drivers

Quoted 18 lines · Qi Liu

This patch bring in a documentation for UltraSoc SMB drivers. It simple descripts the device, sysfs interface and the firmware bindings.

---
  .../trace/coresight/ultrasoc-smb.rst          | 79 +++++++++++++++++++
  1 file changed, 79 insertions(+)

create mode 100644 Documentation/trace/coresight/ultrasoc-smb.rst

Documentation/trace/coresight/ultrasoc-smb.rst new file +2 -0
new file mode 100644
index 000000000000..024fa4492f42
@@ -0,0 +1,79 @@
+.. SPDX-License-Identifier: GPL-2.0
+

Documentation/trace/coresight/ultrasoc-smb.rst line 12

Quoted 10 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +10 -0
+======================================
+UltraSoc - HW Assisted Tracing on SoC
+======================================
+   :Author:   Qi Liu <[email protected]>
+   :Date:     March 2022
+
+Introduction
+------------
+
+UltraSoc SMB is a per SCCL hardware, and it provides a way to buffer and store

nit: what is SCCL ?

Quoted 40 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +40 -0
+CPU trace messages in a region of shared system memory. SMB is plugged as
+a coresight sink device and the corresponding trace generators (ETM) are
+plugged in as source devices.
+
+Sysfs files and directories
+---------------------------
+
+The SMB devices appear on the existing coresight bus alongside the other
+coresight devices::
+
+	$# ls /sys/bus/coresight/devices/
+	ultra_smb0   ultra_smb1   ultra_smb2   ultra_smb3
+
+The ``ultra_smb<N>`` named SMB associated with SCCL.::
+
+	$# ls /sys/bus/coresight/devices/ultra_smb0
+	enable_sink   mgmt
+	$# ls /sys/bus/coresight/devices/ultra_smb0/mgmt
+	buf_size  buf_status  read_pos  write_pos
+
+*Key file items are:-*
+   * ``read_pos``: Shows the value held by UltraSoc SMB Read Pointer register.
+   * ``write_pos``: Shows the value held by UltraSoc SMB Write Pointer register.
+   * ``buf_status``: Shows the value held by UltraSoc SMB status register.
+		     BIT(0) is zero means buffer is empty.
+   * ``buf_size``: Shows the buffer size of each UltraSoc SMB device.
+
+Firmware Bindings
+---------------------------
+
+Firmware binding of SMB device describes SMB device indentifier, resource
+information and graph structure.
+
+SMB is platform device and device id is "HISI03A1", resource of device is
+declared using the _CRS method. Each SMB must present two base address,
+the first one is the configuration base address of SMB device, the second
+one is the base address of shared system memory.
+
+examples::
+

Documentation/trace/coresight/ultrasoc-smb.rst line 60

Quoted 10 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +8 -0
+    Device(USMB) {                                               \
+      Name(_HID, "HISI03A1")                                     \
+      Name(_CRS, ResourceTemplate() {                            \
+          MEM_RESRC(0x95100000, 0x951FFFFF, 0x100000)            \
+          MEM_RESRC(0x50000000, 0x53FFFFFF, 0x4000000)           \
+      })                                                         \
 
 
+      Name(_DSD, Package() {                                     \
+        ToUUID("ab02a46b-74c7-45a2-bd68-f7d344ef2153"),          \

nit: May be add a comment here to explain, use Arm CoreSight Graph ACPI bindings to describe the connections.

Quoted 6 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +6 -0
+        Package() {                                              \
+          0,                                                     \
+          1,                                                     \
+          Package() {                                            \
+            1,                                                   \
+            ToUUID("3ecbc8b6-1d0e-4fb3-8107-e627f805c6cd"),      \

Documentation/trace/coresight/ultrasoc-smb.rst line 76

Quoted 10 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +10 -0
+            8,                                                   \
+            Package() {0x8, 0, \_SB.S00.SL11.CL28.F008, 0},       \
+            Package() {0x9, 0, \_SB.S00.SL11.CL29.F009, 0},       \
+            Package() {0xa, 0, \_SB.S00.SL11.CL2A.F010, 0},       \
+            Package() {0xb, 0, \_SB.S00.SL11.CL2B.F011, 0},       \
+            Package() {0xc, 0, \_SB.S00.SL11.CL2C.F012, 0},       \
+            Package() {0xd, 0, \_SB.S00.SL11.CL2D.F013, 0},       \
+            Package() {0xe, 0, \_SB.S00.SL11.CL2E.F014, 0},       \
+            Package() {0xf, 0, \_SB.S00.SL11.CL2F.F015, 0},       \
+          }                                                      \

Interesting, are there multiple input ports for the SMB ? We haven't seen an instance of a "sink" that supports this. So, would be interesting to see how the driver copes with that scenario.

Suzuki

Quoted 3 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +3 -0
+        }                                                        \
+      })                                                         \
+    }
author
#6 lore raw

Re: [PATCH v5 2/2] Documentation: Add document for UltraSoc SMB drivers

Hi Suzuki,

thanks for your review, some replies inline.

Quoted 24 lines · Suzuki K Poulose
Quoted 23 lines · Qi Liu

This patch bring in a documentation for UltraSoc SMB drivers. It simple descripts the device, sysfs interface and the firmware bindings.

---
  .../trace/coresight/ultrasoc-smb.rst          | 79 +++++++++++++++++++

  1 file changed, 79 insertions(+)

  create mode 100644 Documentation/trace/coresight/ultrasoc-smb.rst

Documentation/trace/coresight/ultrasoc-smb.rst new file +7 -0
new file mode 100644
index 000000000000..024fa4492f42
@@ -0,0 +1,79 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======================================
+UltraSoc - HW Assisted Tracing on SoC
+======================================
+   :Author:   Qi Liu <[email protected]>
+   :Date:     March 2022
Quoted 8 lines
Quoted 6 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +5 -0
+
+Introduction
+------------
+
+UltraSoc SMB is a per SCCL hardware, and it provides a way to buffer 

and store

nit: what is SCCL ?

SCCL is super CPU cluster, I'll add the full name next time.

Quoted 56 lines
Quoted 54 lines

+CPU trace messages in a region of shared system memory. SMB is plugged as

Documentation/trace/coresight/ultrasoc-smb.rst new file +21 -0
+a coresight sink device and the corresponding trace generators (ETM) are
+plugged in as source devices.
+
+Sysfs files and directories
+---------------------------
+
+The SMB devices appear on the existing coresight bus alongside the other
+coresight devices::
+
+    $# ls /sys/bus/coresight/devices/
+    ultra_smb0   ultra_smb1   ultra_smb2   ultra_smb3
+
+The ``ultra_smb<N>`` named SMB associated with SCCL.::
+
+    $# ls /sys/bus/coresight/devices/ultra_smb0
+    enable_sink   mgmt
+    $# ls /sys/bus/coresight/devices/ultra_smb0/mgmt
+    buf_size  buf_status  read_pos  write_pos
+
+*Key file items are:-*
+   * ``read_pos``: Shows the value held by UltraSoc SMB Read Pointer 

register.
+   * ``write_pos``: Shows the value held by UltraSoc SMB Write Pointer register.
+   * ``buf_status``: Shows the value held by UltraSoc SMB status register.
+             BIT(0) is zero means buffer is empty.
+   * ``buf_size``: Shows the buffer size of each UltraSoc SMB device.

Documentation/trace/coresight/ultrasoc-smb.rst new file +5 -0
+
+Firmware Bindings
+---------------------------
+
+Firmware binding of SMB device describes SMB device indentifier, 

resource

Documentation/trace/coresight/ultrasoc-smb.rst new file +3 -0
+information and graph structure.
+
+SMB is platform device and device id is "HISI03A1", resource of 

device is

Documentation/trace/coresight/ultrasoc-smb.rst new file +2 -0
+declared using the _CRS method. Each SMB must present two base address,
+the first one is the configuration base address of SMB device, the 

second

Documentation/trace/coresight/ultrasoc-smb.rst new file +10 -0
+one is the base address of shared system memory.
+
+examples::
+
+    Device(USMB) {                                               \
+      Name(_HID, "HISI03A1")                                     \
+      Name(_CRS, ResourceTemplate() {                            \
+          MEM_RESRC(0x95100000, 0x951FFFFF, 0x100000)            \
+          MEM_RESRC(0x50000000, 0x53FFFFFF, 0x4000000)           \
+      })                                                         \
Quoted 5 lines
Quoted 2 lines

+      Name(_DSD, Package() {                                     \
+        ToUUID("ab02a46b-74c7-45a2-bd68-f7d344ef2153"),          \

nit: May be add a comment here to explain, use Arm CoreSight Graph ACPI bindings to describe the connections.

got it, will add a comment above, thanks.

Quoted 18 lines
Quoted 17 lines

+        Package() {                                              \
+          0,                                                     \
+          1,                                                     \
+          Package() {                                            \
+            1,                                                   \
+            ToUUID("3ecbc8b6-1d0e-4fb3-8107-e627f805c6cd"),      \
+            8,                                                   \
+            Package() {0x8, 0, \_SB.S00.SL11.CL28.F008, 0},       \
+            Package() {0x9, 0, \_SB.S00.SL11.CL29.F009, 0},       \
+            Package() {0xa, 0, \_SB.S00.SL11.CL2A.F010, 0},       \
+            Package() {0xb, 0, \_SB.S00.SL11.CL2B.F011, 0},       \
+            Package() {0xc, 0, \_SB.S00.SL11.CL2C.F012, 0},       \
+            Package() {0xd, 0, \_SB.S00.SL11.CL2D.F013, 0},       \
+            Package() {0xe, 0, \_SB.S00.SL11.CL2E.F014, 0},       \
+            Package() {0xf, 0, \_SB.S00.SL11.CL2F.F015, 0},       \
+          }                                                      \

Quoted 7 lines

Interesting, are there multiple input ports for the SMB ? We haven't seen an instance of a "sink" that supports this. So, would be interesting to see how the driver copes with that scenario.

Suzuki

yes, as there are 8 clusters in a SCCL, and each cluster use one funnel

device to transmit core trace data, so SMB has 8 input funnel ports.

Thanks,
Qi

Quoted 6 lines
Quoted 4 lines

+        }                                                        \
+      })                                                         \
+    }

.

author
#7 lore raw
In reply to Qi Liu

Gentle ping. Any comment or suggestion is appreciated.

Thanks,
Qi

Quoted 43 lines · Qi Liu

Add support for UltraSoc System Memory Buffer.

Change since v4:
- Add a simple document of SMB driver according to Suzuki's comment.
- Address the comments from Suzuki.
- https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v3:
- Modify the file header according to community specifications.
- Address the comments from Mathieu.
- Link:https://lore.kernel.org/linux-arm-kernel/[email protected]/ Change since v2:
- Move ultrasoc driver to drivers/hwtracing/coresight.
- Link:https://lists.linaro.org/pipermail/coresight/2021-November/007310.html

Change since v1:
- Drop the document of UltraSoc according to Mathieu's comment.
- Add comments to explain some private hardware settings.
- Address the comments from Mathieu.
- Link: https://lists.linaro.org/pipermail/coresight/2021-August/006842.html

Change since RFC:
- Move driver to drivers/hwtracing/coresight/ultrasoc.
- Remove ultrasoc-axi-com.c, as AXI-COM doesn't need to be configured in basic tracing function.
- Remove ultrasoc.c as SMB does not need to register with the ultrasoc core.
- Address the comments from Mathieu and Suzuki.
- Link: https://lists.linaro.org/pipermail/coresight/2021-June/006535.html

Qi Liu (2):
drivers/coresight: Add UltraSoc System Memory Buffer driver
Documentation: Add document for UltraSoc SMB drivers

  .../trace/coresight/ultrasoc-smb.rst          |  79 +++
  drivers/hwtracing/coresight/Kconfig           |  10 +
  drivers/hwtracing/coresight/Makefile          |   1 +
  drivers/hwtracing/coresight/ultrasoc-smb.c    | 643 ++++++++++++++++++
  drivers/hwtracing/coresight/ultrasoc-smb.h    | 106 +++
  5 files changed, 839 insertions(+)

create mode 100644 Documentation/trace/coresight/ultrasoc-smb.rst create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h