Skip to contentSkip to conversation

Add support for UltraSoc System Memory Buffer

PATCH Superseded Junhao He 3 participants 15 messages Nov 14, 2022 – Nov 23, 2022

Subsystems (3)

v13 of 16 Superseded Latest is v16 →

lore
Share & tools
lore

Junhao He

author
#0 lore raw

v13 cover Add support for UltraSoc System Memory Buffer

Add support for UltraSoc System Memory Buffer.

Change since v12:
- Modify the code style and add "#ifdef CONFIG_ACPI" according to Jonathan's comment.
- Address the comments from Yicong.
- Link: https://lore.kernel.org/lkml/[email protected]/

Change since v11:
- Modify the code style and rename the macro according to Jonathan's comment.
- Link: https://lore.kernel.org/lkml/[email protected]/

Change since v10:
- Rebase onto v6.1-rc4, included similar sysfs register accessors (as same as James's patch)
- Link: https://lore.kernel.org/lkml/[email protected]/

Change since v9:
- Update the Contact tag in SMB document.
- Replace the spinlock with mutex.
- Do some clean-ups in "smb_enable()" and "smb_release()".
- Use classic memory mapped interface.
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v8:
- Insert a blank line at the end of the config tag in Kconfig according to Randy's comment.
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v7:
- Use the macros for register bit flags and numbers of resource.
- Cleanup punctuation.
- Update the Date tag and the KernelVersion tag in the document.
- Link: https://lore.kernel.org/lkml/[email protected]/

Change since v6:
- Modify the code style and driver description according to Suzuki's comment.
- Modify configuration of "drvdata->reading", to void problems in open/read concurrency scenario.
- Rename the macro of "SMB_FLOW_MASK".
- Use the "handle->head" to determine the page number and offset.
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v5:
- Address the comments from Suzuki, add some comments in SMB document, and modify configuration of "drvdata->reading", to void problems in multi-core concurrency scenario
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v4:
- Add a simple document of SMB driver according to Suzuki's comment.
- Address the comments from Suzuki.
- Link: 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 by Mathieu's comment.
- 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

 .../sysfs-bus-coresight-devices-ultra_smb     |  31 +
 .../trace/coresight/ultrasoc-smb.rst          |  82 +++
 drivers/hwtracing/coresight/Kconfig           |  11 +
 drivers/hwtracing/coresight/Makefile          |   1 +
 drivers/hwtracing/coresight/ultrasoc-smb.c    | 646 ++++++++++++++++++
 drivers/hwtracing/coresight/ultrasoc-smb.h    | 120 ++++
 6 files changed, 891 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb
 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.33.0
author
#1 lore raw

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

From: Qi Liu <[email protected]>

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 trace" 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        |  11 +
 drivers/hwtracing/coresight/Makefile       |   1 +
 drivers/hwtracing/coresight/ultrasoc-smb.c | 656 +++++++++++++++++++++
 drivers/hwtracing/coresight/ultrasoc-smb.h | 120 ++++
 4 files changed, 788 insertions(+)
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h
drivers/hwtracing/coresight/Kconfig +11 -0
index 45c1eb5dfcb7..cb17c207a728 100644
@@ -201,4 +201,15 @@ 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 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 +656 -0

656 lines not on this page · raw message

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

120 lines not on this page · raw message

Signature · 1 line
2.33.0
maintainer
#2 lore raw

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

Quoted 27 lines · Junhao He

From: Qi Liu <[email protected]>

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 trace" 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        |  11 +
  drivers/hwtracing/coresight/Makefile       |   1 +
  drivers/hwtracing/coresight/ultrasoc-smb.c | 656 +++++++++++++++++++++
  drivers/hwtracing/coresight/ultrasoc-smb.h | 120 ++++
  4 files changed, 788 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 45c1eb5dfcb7..cb17c207a728 100644

drivers/hwtracing/coresight/Kconfig config CORESIGHT_TRBE · line 207

Quoted 7 lines
drivers/hwtracing/coresight/Kconfig +4 -0
@@ -201,4 +201,15 @@ 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 ARM64 && CORESIGHT_LINKS_AND_SINKS

I still think it is not a good idea to leave the ACPI dependency out of this. THe driver is unusable on a system without ACPI and the only other reason to build this would when using COMPILE_TEST. So, we could add something like :

	depends on ACPI || COMPILE_TEST
	depends on ARM64 && CORESIGHT_LINKS_AND_SINKS
Quoted 62 lines
drivers/hwtracing/coresight/Kconfig +7 -0
+	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 +39 -0
new file mode 100644
index 000000000000..1957796cbab2
@@ -0,0 +1,656 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Siemens System Memory Buffer driver.
+ * Copyright(c) 2022, HiSilicon Limited.
+ */
+
+#include <linux/atomic.h>
+#include <linux/acpi.h>
+#include <linux/circ_buf.h>
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+
+#include "coresight-etm-perf.h"
+#include "coresight-priv.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_REG);
+
+	return !FIELD_GET(SMB_LB_INT_STS_NOT_EMPTY_MSK, buf_status);
+}
+
+static void smb_buffer_sync_status(struct smb_drv_data *drvdata)
+{
+	struct smb_data_buffer *sdb = &drvdata->sdb;
+
+	sdb->wr_offset = readl(drvdata->base + SMB_LB_WR_ADDR_REG) -
+			 sdb->start_addr;
+	sdb->rd_offset = readl(drvdata->base + SMB_LB_RD_ADDR_REG) -
+			 sdb->start_addr;
+	sdb->full = sdb->wr_offset == sdb->rd_offset &&

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

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+		    !smb_buffer_is_empty(drvdata);
+}
+
+static void smb_reset_buffer_status(struct smb_drv_data *drvdata)
+{
+	/* All other bits are reserved and shall be 0 */
+	writel(SMB_LB_INT_STS_RESET, drvdata->base + SMB_LB_INT_STS_REG);
+}
+
+/* Purge data remaining in hardware path in case them influence next trace */

minor nit:

/*
* Purge data remaining in hardware path to avoid corrupting the next
* session.
*/

Quoted 141 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +141 -0
+static void smb_purge_data(struct smb_drv_data *drvdata)
+{
+	/* All other bits are reserved and shall be 0 */
+	writel(SMB_LB_PURGE_PURGED, drvdata->base + SMB_LB_PURGE_REG);
+}
+
+static void smb_update_data_size(struct smb_drv_data *drvdata)
+{
+	struct smb_data_buffer *sdb = &drvdata->sdb;
+
+	smb_purge_data(drvdata);
+	smb_buffer_sync_status(drvdata);
+	if (sdb->full) {
+		sdb->data_size = sdb->buf_size;
+		return;
+	}
+
+	sdb->data_size = CIRC_CNT(sdb->wr_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);
+	int ret = 0;
+
+	mutex_lock(&drvdata->mutex);
+
+	if (drvdata->reading) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	if (atomic_read(drvdata->csdev->refcnt)) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	drvdata->reading = true;
+out:
+	mutex_unlock(&drvdata->mutex);
+
+	return ret;
+}
+
+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;
+	ssize_t to_copy = 0;
+
+	mutex_lock(&drvdata->mutex);
+
+	if (!len)
+		goto out;
+
+	/*
+	 * In sysfs mode, size need to be update in the following two cases:
+	 * 1) Start dumping data.
+	 * 2) End dump data, make sure there is no remaining data in
+	 *    the hardware path. Because the remaining data cannot be purged
+	 *    when the buffer is full.
+	 */
+	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_REG);
+	dev_dbg(dev, "%zu bytes copied\n", to_copy);
+out:
+	if (!sdb->data_size)
+		smb_reset_buffer_status(drvdata);
+	mutex_unlock(&drvdata->mutex);
+
+	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);
+
+	mutex_lock(&drvdata->mutex);
+	drvdata->reading = false;
+	mutex_unlock(&drvdata->mutex);
+
+	return 0;
+}
+
+static const struct file_operations smb_fops = {
+	.owner		= THIS_MODULE,
+	.open		= smb_open,
+	.read		= smb_read,
+	.release	= smb_release,
+	.llseek		= no_llseek,
+};
+
+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[] = {
+	coresight_simple_reg32(read_pos, SMB_LB_RD_ADDR_REG),
+	coresight_simple_reg32(write_pos, SMB_LB_WR_ADDR_REG),
+	coresight_simple_reg32(buf_status, SMB_LB_INT_STS_REG),
+	&dev_attr_buf_size.attr,
+	NULL
+};
+
+static const struct attribute_group smb_sink_group = {
+	.attrs = smb_sink_attrs,
+	.name = "mgmt",

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

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+};
+
+static const struct attribute_group *smb_sink_groups[] = {
+	&smb_sink_group,
+	NULL
+};
+
+static void smb_enable_hw(struct smb_drv_data *drvdata)
+{
+	writel(SMB_GLB_EN_HW_ENABLE, drvdata->base + SMB_GLB_EN_REG);

What happens to the RD_ADDR_REG and WR_ADDR_REG at enable ? Do they reset to the base of the buf or do we need to program at enable ? Are there any other modes of operation ? Or is it always in circular buffer mode ?

Quoted 178 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +178 -0
+}
+
+static void smb_disable_hw(struct smb_drv_data *drvdata)
+{
+	writel(0x0, drvdata->base + SMB_GLB_EN_REG);
+}
+
+static void smb_enable_sysfs(struct coresight_device *csdev)
+{
+	struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+
+	if (drvdata->mode != CS_MODE_DISABLED)
+		return;
+
+	smb_enable_hw(drvdata);
+	drvdata->mode = CS_MODE_SYSFS;
+}
+
+static int smb_enable_perf(struct coresight_device *csdev, void *data)
+{
+	struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+	struct perf_output_handle *handle = data;
+	struct cs_buffers *buf = etm_perf_sink_config(handle);
+	pid_t pid;
+
+	if (!buf)
+		return -EINVAL;
+
+	/* Get a handle on the pid of the target process */
+	pid = buf->pid;
+
+	/* Device is already in used by other session */
+	if (drvdata->pid != -1 && drvdata->pid != pid)
+		return -EBUSY;
+
+	if (drvdata->pid == -1) {
+		smb_enable_hw(drvdata);
+		drvdata->pid = pid;
+		drvdata->mode = CS_MODE_PERF;
+	}
+
+	return 0;
+}
+
+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 = 0;
+
+	mutex_lock(&drvdata->mutex);
+
+	/* Do nothing, the trace data is reading by other interface now */
+	if (drvdata->reading) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	/* Do nothing, the SMB is already enabled as other mode */
+	if (drvdata->mode != CS_MODE_DISABLED && drvdata->mode != mode) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	switch (mode) {
+	case CS_MODE_SYSFS:
+		smb_enable_sysfs(csdev);
+		break;
+	case CS_MODE_PERF:
+		ret = smb_enable_perf(csdev, data);
+		break;
+	default:
+		ret = -EINVAL;
+	}
+
+	if (ret)
+		goto out;
+
+	atomic_inc(csdev->refcnt);
+
+	dev_dbg(&csdev->dev, "Ultrasoc SMB enabled\n");
+out:
+	mutex_unlock(&drvdata->mutex);
+
+	return ret;
+}
+
+static int smb_disable(struct coresight_device *csdev)
+{
+	struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+	int ret = 0;
+
+	mutex_lock(&drvdata->mutex);
+
+	if (drvdata->reading) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	if (atomic_dec_return(csdev->refcnt)) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	/* Complain if we (somehow) got out of sync */
+	WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED);
+
+	smb_disable_hw(drvdata);
+	smb_purge_data(drvdata);
+
+	/* Dissociate from the target process. */
+	drvdata->pid = -1;
+	drvdata->mode = CS_MODE_DISABLED;
+
+	dev_dbg(&csdev->dev, "Ultrasoc SMB disabled\n");
+out:
+	mutex_unlock(&drvdata->mutex);
+
+	return ret;
+}
+
+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 head,
+				 unsigned long data_size)
+{
+	struct smb_data_buffer *sdb = &drvdata->sdb;
+	char **dst_pages = (char **)buf->data_pages;
+	unsigned long to_copy;
+	long pg_idx, pg_offset;
+
+	pg_idx = head >> PAGE_SHIFT;
+	pg_offset = head & (PAGE_SIZE - 1);
+
+	while (data_size) {
+		unsigned long pg_space = PAGE_SIZE - pg_offset;
+
+		/* Copy parts of trace data when read pointer wrap around */
+		if (sdb->rd_offset + pg_space > sdb->buf_size)
+			to_copy = sdb->buf_size - sdb->rd_offset;
+		else
+			to_copy = min(data_size, pg_space);
+
+		memcpy(dst_pages[pg_idx] + pg_offset,
+			      sdb->buf_base + sdb->rd_offset, to_copy);
+
+		pg_offset += to_copy;
+		if (pg_offset >= PAGE_SIZE) {
+			pg_offset = 0;
+			pg_idx++;
+			pg_idx %= buf->nr_pages;
+		}

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

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +8 -0
+		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_REG);

Is this safe ? When the buffer was not full and the buffer was not copied in full (i.e., perf_buffer < buffer_size), the RD_ADDR_REG won't reach the WR_ADDR_REG. So can that affect the next session ? See more below :

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

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+
+	/*
+	 * Data remained in link cannot be purged when SMB is full, so
+	 * synchronize the read pointer to write pointer, to make sure
+	 * these remained data won't influence next trace.
+	 */
+	if (sdb->full) {
+		smb_purge_data(drvdata);
+		writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
+		       drvdata->base + SMB_LB_RD_ADDR_REG);

Or, in other words, shouldn't we do this irrespective of whether the buffer->full or not ? We set the TRUNCATED flag appropriately when there was data lost and thus we must not leave any trace from a previous "schedule" in for the "next" collection. So, we must reset the RD/WR registers to the base.

Quoted 36 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +34 -0
+	}
 
 
+	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;
+	bool lost = false;
+
+	if (!buf)
+		return 0;
+
+	mutex_lock(&drvdata->mutex);
+
+	/* Don't do anything if another tracer is using this sink. */
+	if (atomic_read(csdev->refcnt) != 1)
+		goto out;
+
+	smb_disable_hw(drvdata);
+	smb_update_data_size(drvdata);
+	data_size = sdb->data_size;
+
+	/*
+	 * The SMB buffer may be bigger than the space available in the
+	 * perf ring buffer (handle->size). If so advance the offset so
+	 * that we get the latest trace data.
+	 */
+	if (data_size > handle->size) {
+		sdb->rd_offset += data_size - handle->size;

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

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +9 -0
+		sdb->rd_offset %= sdb->buf_size;
+		data_size = handle->size;
+		lost = true;
+	} > +
+	smb_sync_perf_buffer(drvdata, buf, handle->head, data_size);
+	if (!buf->snapshot && lost)
+		perf_aux_output_flag(handle, PERF_AUX_FLAG_TRUNCATED);
+
 
+	smb_enable_hw(drvdata);

We do not need this and could leave this disabled at this stage. The perf session has stopped the "source" anyway.

Quoted 51 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +51 -0
+out:
+	mutex_unlock(&drvdata->mutex);
+
+	return data_size;
+}
+
+static const struct coresight_ops_sink smb_cs_ops = {
+	.enable		= smb_enable,
+	.disable	= smb_disable,
+	.alloc_buffer	= smb_alloc_buffer,
+	.free_buffer	= smb_free_buffer,
+	.update_buffer	= smb_update_buffer,
+};
+
+static const struct coresight_ops cs_ops = {
+	.sink_ops	= &smb_cs_ops,
+};
+
+static int smb_init_data_buffer(struct platform_device *pdev,
+				struct smb_data_buffer *sdb)
+{
+	struct resource *res;
+	void *base;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, SMB_BUF_ADDR_RES);
+	if (IS_ERR(res)) {
+		dev_err(&pdev->dev, "SMB device failed to get resource\n");
+		return -EINVAL;
+	}
+
+	sdb->start_addr = FIELD_GET(SMB_BUF_ADDR_LO_MSK, res->start);
+	sdb->buf_size = resource_size(res);
+	if (sdb->buf_size == 0)
+		return -EINVAL;
+
+	/*
+	 * This is a chunk of memory, use classic mapping with better
+	 * performance.
+	 */
+	base = devm_memremap(&pdev->dev, sdb->start_addr, sdb->buf_size,
+				MEMREMAP_WB);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	sdb->buf_base = base;
+
+	return 0;
+}
+
+static void smb_init_hw(struct smb_drv_data *drvdata)
+{

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

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+	/* First disable SMB and clear the status of SMB buffer */
+	smb_reset_buffer_status(drvdata);
+	smb_disable_hw(drvdata);
+	smb_purge_data(drvdata);
+
+	writel(SMB_LB_CFG_LO_DEFAULT, drvdata->base + SMB_LB_CFG_LO_REG);
+	writel(SMB_LB_CFG_HI_DEFAULT, drvdata->base + SMB_LB_CFG_HI_REG);
+	writel(SMB_GLB_CFG_DEFAULT, drvdata->base + SMB_GLB_CFG_REG);
+	writel(SMB_GLB_INT_CFG, drvdata->base + SMB_GLB_INT_REG);
+	writel(SMB_LB_INT_CTRL_CFG, drvdata->base + SMB_LB_INT_CTRL_REG);

Does this come with interrupt on overflow ? Do we not use this ?

Rest looks fine to me.

Suzuki

author
#3 lore raw

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

Hi Suzuki ,

Quoted 41 lines · Suzuki K Poulose
Quoted 30 lines · Junhao He

From: Qi Liu <[email protected]>

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 trace" 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        |  11 +
  drivers/hwtracing/coresight/Makefile       |   1 +
  drivers/hwtracing/coresight/ultrasoc-smb.c | 656 +++++++++++++++++++++
  drivers/hwtracing/coresight/ultrasoc-smb.h | 120 ++++
  4 files changed, 788 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 45c1eb5dfcb7..cb17c207a728 100644
@@ -201,4 +201,15 @@ config CORESIGHT_TRBE
          To compile this driver as a module, choose M here: the 

module will be
called coresight-trbe.

drivers/hwtracing/coresight/Kconfig config CORESIGHT_TRBE · line 207

Quoted 4 lines
drivers/hwtracing/coresight/Kconfig +4 -0
+
+config ULTRASOC_SMB
+    tristate "Ultrasoc system memory buffer drivers"
+    depends on ARM64 && CORESIGHT_LINKS_AND_SINKS

I still think it is not a good idea to leave the ACPI dependency out of this. THe driver is unusable on a system without ACPI and the only other reason to build this would when using COMPILE_TEST. So, we could add something like :

Quoted 3 lines
    depends on ACPI || COMPILE_TEST
    depends on ARM64 && CORESIGHT_LINKS_AND_SINKS

OK, I will do that.
Thanks.

Quoted 80 lines
Quoted 76 lines
drivers/hwtracing/coresight/Kconfig +2 -0
+    help
+      This driver provides support for the Ultrasoc system memory 

buffer (SMB).
+ SMB is responsible for receiving the trace data from Coresight
ETM devices

drivers/hwtracing/coresight/Kconfig +3 -0
+      and storing them to a system buffer.
+
+      To compile this driver as a module, choose M here: the module 

will be

drivers/hwtracing/coresight/Kconfig +1 -0
+      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 +49 -0
new file mode 100644
index 000000000000..1957796cbab2
@@ -0,0 +1,656 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Siemens System Memory Buffer driver.
+ * Copyright(c) 2022, HiSilicon Limited.
+ */
+
+#include <linux/atomic.h>
+#include <linux/acpi.h>
+#include <linux/circ_buf.h>
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+
+#include "coresight-etm-perf.h"
+#include "coresight-priv.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_REG);
+
+    return !FIELD_GET(SMB_LB_INT_STS_NOT_EMPTY_MSK, buf_status);
+}
+
+static void smb_buffer_sync_status(struct smb_drv_data *drvdata)
+{
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+
+    sdb->wr_offset = readl(drvdata->base + SMB_LB_WR_ADDR_REG) -
+             sdb->start_addr;
+    sdb->rd_offset = readl(drvdata->base + SMB_LB_RD_ADDR_REG) -
+             sdb->start_addr;
+    sdb->full = sdb->wr_offset == sdb->rd_offset &&
+            !smb_buffer_is_empty(drvdata);
+}
+
+static void smb_reset_buffer_status(struct smb_drv_data *drvdata)
+{
+    /* All other bits are reserved and shall be 0 */
+    writel(SMB_LB_INT_STS_RESET, drvdata->base + SMB_LB_INT_STS_REG);
+}
+
+/* Purge data remaining in hardware path in case them influence next 
Quoted 1 line

trace */

minor nit:

Quoted 5 lines

/*
* Purge data remaining in hardware path to avoid corrupting the next
* session.
*/

Ok, will fix it.
Thanks.

Quoted 153 lines
Quoted 153 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +47 -0
+static void smb_purge_data(struct smb_drv_data *drvdata)
+{
+    /* All other bits are reserved and shall be 0 */
+    writel(SMB_LB_PURGE_PURGED, drvdata->base + SMB_LB_PURGE_REG);
+}
+
+static void smb_update_data_size(struct smb_drv_data *drvdata)
+{
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+
+    smb_purge_data(drvdata);
+    smb_buffer_sync_status(drvdata);
+    if (sdb->full) {
+        sdb->data_size = sdb->buf_size;
+        return;
+    }
+
+    sdb->data_size = CIRC_CNT(sdb->wr_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);
+    int ret = 0;
+
+    mutex_lock(&drvdata->mutex);
+
+    if (drvdata->reading) {
+        ret = -EBUSY;
+        goto out;
+    }
+
+    if (atomic_read(drvdata->csdev->refcnt)) {
+        ret = -EBUSY;
+        goto out;
+    }
+
+    drvdata->reading = true;
+out:
+    mutex_unlock(&drvdata->mutex);
+
+    return ret;
+}
+
+static ssize_t smb_read(struct file *file, char __user *data, size_t 

len,

drivers/hwtracing/coresight/ultrasoc-smb.c new file +15 -0
+            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;
+    ssize_t to_copy = 0;
+
+    mutex_lock(&drvdata->mutex);
+
+    if (!len)
+        goto out;
+
+    /*
+     * In sysfs mode, size need to be update in the following two 

cases:

drivers/hwtracing/coresight/ultrasoc-smb.c new file +3 -0
+     * 1) Start dumping data.
+     * 2) End dump data, make sure there is no remaining data in
+     *    the hardware path. Because the remaining data cannot be 

purged

drivers/hwtracing/coresight/ultrasoc-smb.c new file +11 -0
+     *    when the buffer is full.
+     */
+    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 */

drivers/hwtracing/coresight/ultrasoc-smb.c new file +46 -0
+    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_REG);
+    dev_dbg(dev, "%zu bytes copied\n", to_copy);
+out:
+    if (!sdb->data_size)
+        smb_reset_buffer_status(drvdata);
+    mutex_unlock(&drvdata->mutex);
+
+    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);
+
+    mutex_lock(&drvdata->mutex);
+    drvdata->reading = false;
+    mutex_unlock(&drvdata->mutex);
+
+    return 0;
+}
+
+static const struct file_operations smb_fops = {
+    .owner        = THIS_MODULE,
+    .open        = smb_open,
+    .read        = smb_read,
+    .release    = smb_release,
+    .llseek        = no_llseek,
+};
+
+static ssize_t buf_size_show(struct device *dev, struct 

device_attribute *attr,

drivers/hwtracing/coresight/ultrasoc-smb.c new file +26 -0
+                 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[] = {
+    coresight_simple_reg32(read_pos, SMB_LB_RD_ADDR_REG),
+    coresight_simple_reg32(write_pos, SMB_LB_WR_ADDR_REG),
+    coresight_simple_reg32(buf_status, SMB_LB_INT_STS_REG),
+    &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
+};
+
Quoted 8 lines

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

Quoted 3 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +3 -0
+static void smb_enable_hw(struct smb_drv_data *drvdata)
+{
+    writel(SMB_GLB_EN_HW_ENABLE, drvdata->base + SMB_GLB_EN_REG);

What happens to the RD_ADDR_REG and WR_ADDR_REG at enable ? Do they reset to the base of the buf or do we need to program at enable ? Are there any other modes of operation ? Or is it always in circular buffer mode ?

The RD_ADDR_REG and WR_ADDR_REG register is filled in BIOS, and WR_ADDR_REG is RO mode.
When the SMB is enabled, the values of RD_ADDR_REG and WR_ADDR_REG remain unchanged.
UltraSoc SMB is always in circular buffer mode.
Thanks.

Quoted 186 lines
Quoted 185 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +45 -0
+}
+
+static void smb_disable_hw(struct smb_drv_data *drvdata)
+{
+    writel(0x0, drvdata->base + SMB_GLB_EN_REG);
+}
+
+static void smb_enable_sysfs(struct coresight_device *csdev)
+{
+    struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+
+    if (drvdata->mode != CS_MODE_DISABLED)
+        return;
+
+    smb_enable_hw(drvdata);
+    drvdata->mode = CS_MODE_SYSFS;
+}
+
+static int smb_enable_perf(struct coresight_device *csdev, void *data)
+{
+    struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+    struct perf_output_handle *handle = data;
+    struct cs_buffers *buf = etm_perf_sink_config(handle);
+    pid_t pid;
+
+    if (!buf)
+        return -EINVAL;
+
+    /* Get a handle on the pid of the target process */
+    pid = buf->pid;
+
+    /* Device is already in used by other session */
+    if (drvdata->pid != -1 && drvdata->pid != pid)
+        return -EBUSY;
+
+    if (drvdata->pid == -1) {
+        smb_enable_hw(drvdata);
+        drvdata->pid = pid;
+        drvdata->mode = CS_MODE_PERF;
+    }
+
+    return 0;
+}
+
+static int smb_enable(struct coresight_device *csdev, u32 mode, void 

*data)

drivers/hwtracing/coresight/ultrasoc-smb.c new file +139 -0
+{
+    struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+    int ret = 0;
+
+    mutex_lock(&drvdata->mutex);
+
+    /* Do nothing, the trace data is reading by other interface now */
+    if (drvdata->reading) {
+        ret = -EBUSY;
+        goto out;
+    }
+
+    /* Do nothing, the SMB is already enabled as other mode */
+    if (drvdata->mode != CS_MODE_DISABLED && drvdata->mode != mode) {
+        ret = -EBUSY;
+        goto out;
+    }
+
+    switch (mode) {
+    case CS_MODE_SYSFS:
+        smb_enable_sysfs(csdev);
+        break;
+    case CS_MODE_PERF:
+        ret = smb_enable_perf(csdev, data);
+        break;
+    default:
+        ret = -EINVAL;
+    }
+
+    if (ret)
+        goto out;
+
+    atomic_inc(csdev->refcnt);
+
+    dev_dbg(&csdev->dev, "Ultrasoc SMB enabled\n");
+out:
+    mutex_unlock(&drvdata->mutex);
+
+    return ret;
+}
+
+static int smb_disable(struct coresight_device *csdev)
+{
+    struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent);
+    int ret = 0;
+
+    mutex_lock(&drvdata->mutex);
+
+    if (drvdata->reading) {
+        ret = -EBUSY;
+        goto out;
+    }
+
+    if (atomic_dec_return(csdev->refcnt)) {
+        ret = -EBUSY;
+        goto out;
+    }
+
+    /* Complain if we (somehow) got out of sync */
+    WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED);
+
+    smb_disable_hw(drvdata);
+    smb_purge_data(drvdata);
+
+    /* Dissociate from the target process. */
+    drvdata->pid = -1;
+    drvdata->mode = CS_MODE_DISABLED;
+
+    dev_dbg(&csdev->dev, "Ultrasoc SMB disabled\n");
+out:
+    mutex_unlock(&drvdata->mutex);
+
+    return ret;
+}
+
+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 head,
+                 unsigned long data_size)
+{
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+    char **dst_pages = (char **)buf->data_pages;
+    unsigned long to_copy;
+    long pg_idx, pg_offset;
+
+    pg_idx = head >> PAGE_SHIFT;
+    pg_offset = head & (PAGE_SIZE - 1);
+
+    while (data_size) {
+        unsigned long pg_space = PAGE_SIZE - pg_offset;
+
+        /* Copy parts of trace data when read pointer wrap around */
+        if (sdb->rd_offset + pg_space > sdb->buf_size)
+            to_copy = sdb->buf_size - sdb->rd_offset;
+        else
+            to_copy = min(data_size, pg_space);
+
+        memcpy(dst_pages[pg_idx] + pg_offset,
+                  sdb->buf_base + sdb->rd_offset, to_copy);
+
+        pg_offset += to_copy;
+        if (pg_offset >= PAGE_SIZE) {
+            pg_offset = 0;
+            pg_idx++;
+            pg_idx %= buf->nr_pages;
+        }
+        data_size -= to_copy;
+        sdb->rd_offset += to_copy;
+        sdb->rd_offset %= sdb->buf_size;
+    }
+
+    sdb->data_size = 0;
Quoted 8 lines

drivers/hwtracing/coresight/ultrasoc-smb.c

Quoted 2 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +2 -0
+    writel(sdb->start_addr + sdb->rd_offset,
+        drvdata->base + SMB_LB_RD_ADDR_REG);

Is this safe ? When the buffer was not full and the buffer was not copied in full (i.e., perf_buffer < buffer_size), the RD_ADDR_REG won't reach the WR_ADDR_REG. So can that affect the next session ? See more below :

Yes, In this case. "sdb->rd_offset" will add the offset of discarded data (buffer_size - perf_buffer) in the smb_update_buffer() function. If the buffer was not full, the values of RD_ADDR_REG and WR_ADDR_REG ​​will always be the same.
When SMB is full, the data remained in link only can be written into buffer after updated RD_ADDR_REG, and the value of WR_ADDR_REG will be advanced. So in this case we need synchronize the WR_ADDR_REG to RD_ADDR_REG again. Thanks.

Quoted 11 lines

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

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+
+    /*
+     * Data remained in link cannot be purged when SMB is full, so
+     * synchronize the read pointer to write pointer, to make sure
+     * these remained data won't influence next trace.
+     */
+    if (sdb->full) {
+        smb_purge_data(drvdata);
+        writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
+               drvdata->base + SMB_LB_RD_ADDR_REG);
Quoted 6 lines

Or, in other words, shouldn't we do this irrespective of whether the buffer->full or not ? We set the TRUNCATED flag appropriately when there was data lost and thus we must not leave any trace from a previous "schedule" in for the "next" collection. So, we must reset the RD/WR registers to the base.

Yes, You are right, but the WR_ADDR_REG register is RO mode. Thanks.

Quoted 45 lines
Quoted 44 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +42 -0
+    }
 
 
+    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;
+    bool lost = false;
+
+    if (!buf)
+        return 0;
+
+    mutex_lock(&drvdata->mutex);
+
+    /* Don't do anything if another tracer is using this sink. */
+    if (atomic_read(csdev->refcnt) != 1)
+        goto out;
+
+    smb_disable_hw(drvdata);
+    smb_update_data_size(drvdata);
+    data_size = sdb->data_size;
+
+    /*
+     * The SMB buffer may be bigger than the space available in the
+     * perf ring buffer (handle->size). If so advance the offset so
+     * that we get the latest trace data.
+     */
+    if (data_size > handle->size) {
+        sdb->rd_offset += data_size - handle->size;
+        sdb->rd_offset %= sdb->buf_size;
+        data_size = handle->size;
+        lost = true;
+    } > +
+    smb_sync_perf_buffer(drvdata, buf, handle->head, data_size);
+    if (!buf->snapshot && lost)
+        perf_aux_output_flag(handle, PERF_AUX_FLAG_TRUNCATED);
+
Quoted 5 lines
Quoted 1 line

+ smb_enable_hw(drvdata);

We do not need this and could leave this disabled at this stage. The perf session has stopped the "source" anyway.

Yes, I will do that.
Thanks.

Quoted 56 lines
Quoted 56 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +25 -0
+out:
+    mutex_unlock(&drvdata->mutex);
+
+    return data_size;
+}
+
+static const struct coresight_ops_sink smb_cs_ops = {
+    .enable        = smb_enable,
+    .disable    = smb_disable,
+    .alloc_buffer    = smb_alloc_buffer,
+    .free_buffer    = smb_free_buffer,
+    .update_buffer    = smb_update_buffer,
+};
+
+static const struct coresight_ops cs_ops = {
+    .sink_ops    = &smb_cs_ops,
+};
+
+static int smb_init_data_buffer(struct platform_device *pdev,
+                struct smb_data_buffer *sdb)
+{
+    struct resource *res;
+    void *base;
+
+    res = platform_get_resource(pdev, IORESOURCE_MEM, 

SMB_BUF_ADDR_RES);

drivers/hwtracing/coresight/ultrasoc-smb.c new file +30 -0
+    if (IS_ERR(res)) {
+        dev_err(&pdev->dev, "SMB device failed to get resource\n");
+        return -EINVAL;
+    }
+
+    sdb->start_addr = FIELD_GET(SMB_BUF_ADDR_LO_MSK, res->start);
+    sdb->buf_size = resource_size(res);
+    if (sdb->buf_size == 0)
+        return -EINVAL;
+
+    /*
+     * This is a chunk of memory, use classic mapping with better
+     * performance.
+     */
+    base = devm_memremap(&pdev->dev, sdb->start_addr, sdb->buf_size,
+                MEMREMAP_WB);
+    if (IS_ERR(base))
+        return PTR_ERR(base);
+
+    sdb->buf_base = base;
+
+    return 0;
+}
+
+static void smb_init_hw(struct smb_drv_data *drvdata)
+{
+    /* First disable SMB and clear the status of SMB buffer */
+    smb_reset_buffer_status(drvdata);
+    smb_disable_hw(drvdata);
+    smb_purge_data(drvdata);
Quoted 9 lines

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

Quoted 6 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +6 -0
+
+    writel(SMB_LB_CFG_LO_DEFAULT, drvdata->base + SMB_LB_CFG_LO_REG);
+    writel(SMB_LB_CFG_HI_DEFAULT, drvdata->base + SMB_LB_CFG_HI_REG);
+    writel(SMB_GLB_CFG_DEFAULT, drvdata->base + SMB_GLB_CFG_REG);
+    writel(SMB_GLB_INT_CFG, drvdata->base + SMB_GLB_INT_REG);
+    writel(SMB_LB_INT_CTRL_CFG, drvdata->base + SMB_LB_INT_CTRL_REG);

Does this come with interrupt on overflow ? Do we not use this ?

When the buffer overflow, no interrupt will come.
Interrupt will upgrade SMB_LB_INT_STS_REG register status if start trace. Thanks.

Quoted 4 lines

Rest looks fine to me.

Suzuki

Best regards,
HeJunhao.

Quoted 6 lines

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

.

#4 lore raw

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

Quoted 23 lines · hejunhao

Hi Suzuki ,

Quoted 4 lines · Suzuki K Poulose
Quoted 2 lines · Junhao He

From: Qi Liu <[email protected]>

Quoted 15 lines

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

Quoted 12 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +12 -0
+static void smb_init_hw(struct smb_drv_data *drvdata)
+{
+    /* First disable SMB and clear the status of SMB buffer */
+    smb_reset_buffer_status(drvdata);
+    smb_disable_hw(drvdata);
+    smb_purge_data(drvdata);
+
+    writel(SMB_LB_CFG_LO_DEFAULT, drvdata->base + SMB_LB_CFG_LO_REG);
+    writel(SMB_LB_CFG_HI_DEFAULT, drvdata->base + SMB_LB_CFG_HI_REG);
+    writel(SMB_GLB_CFG_DEFAULT, drvdata->base + SMB_GLB_CFG_REG);
+    writel(SMB_GLB_INT_CFG, drvdata->base + SMB_GLB_INT_REG);
+    writel(SMB_LB_INT_CTRL_CFG, drvdata->base + SMB_LB_INT_CTRL_REG);

Does this come with interrupt on overflow ? Do we not use this ?

Quoted 4 lines

When the buffer overflow, no interrupt will come.
Interrupt will upgrade SMB_LB_INT_STS_REG register status if start trace. Thanks.

Quoted 1 line

Rest looks fine to me.

What is the purpose of the "Interrupt" on the SMB ? It is not clear to me.

Suzuki

author
#5 lore raw

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

Quoted 24 lines · Suzuki Kuruppassery Poulose
Quoted 23 lines · hejunhao

Hi Suzuki ,

Quoted 19 lines · Suzuki K Poulose
Quoted 5 lines · Junhao He

From: Qi Liu <[email protected]>

drivers/hwtracing/coresight/ultrasoc-smb.c new file +2 -0
+static void smb_init_hw(struct smb_drv_data *drvdata)
+{

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

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+    /* First disable SMB and clear the status of SMB buffer */
+    smb_reset_buffer_status(drvdata);
+    smb_disable_hw(drvdata);
+    smb_purge_data(drvdata);
+
+    writel(SMB_LB_CFG_LO_DEFAULT, drvdata->base + SMB_LB_CFG_LO_REG);
+    writel(SMB_LB_CFG_HI_DEFAULT, drvdata->base + SMB_LB_CFG_HI_REG);
+    writel(SMB_GLB_CFG_DEFAULT, drvdata->base + SMB_GLB_CFG_REG);
+    writel(SMB_GLB_INT_CFG, drvdata->base + SMB_GLB_INT_REG);
+    writel(SMB_LB_INT_CTRL_CFG, drvdata->base + SMB_LB_INT_CTRL_REG);

Does this come with interrupt on overflow ? Do we not use this ?

Quoted 7 lines
Quoted 4 lines

When the buffer overflow, no interrupt will come.
Interrupt will upgrade SMB_LB_INT_STS_REG register status if start trace. Thanks.

Quoted 1 line

Rest looks fine to me.

What is the purpose of the "Interrupt" on the SMB ? It is not clear to me.

The SMB_LB_INT_CTRL_REG register control the validity of both real-time events and interrupts. When logical buffer status changes causes to issue an interrupt at the same time as it issues a real-time event. Real-time events are used in SMB driver, which needs to get the buffer status. Interrupts are used in debugger mode and cannot be registered in kernel.
..._BUF_NOTE_MASK control which events flags or interrupts are valid.

Thanks.

Best regards,
Junhao.

Quoted 5 lines

Suzuki

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

maintainer
#6 lore raw

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

Quoted 31 lines · hejunhao
Quoted 29 lines · Suzuki Kuruppassery Poulose
Quoted 27 lines · hejunhao

Hi Suzuki ,

Quoted 4 lines · Suzuki K Poulose
Quoted 2 lines · Junhao He

From: Qi Liu <[email protected]>

Quoted 15 lines

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

Quoted 12 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +12 -0
+static void smb_init_hw(struct smb_drv_data *drvdata)
+{
+    /* First disable SMB and clear the status of SMB buffer */
+    smb_reset_buffer_status(drvdata);
+    smb_disable_hw(drvdata);
+    smb_purge_data(drvdata);
+
+    writel(SMB_LB_CFG_LO_DEFAULT, drvdata->base + SMB_LB_CFG_LO_REG);
+    writel(SMB_LB_CFG_HI_DEFAULT, drvdata->base + SMB_LB_CFG_HI_REG);
+    writel(SMB_GLB_CFG_DEFAULT, drvdata->base + SMB_GLB_CFG_REG);
+    writel(SMB_GLB_INT_CFG, drvdata->base + SMB_GLB_INT_REG);
+    writel(SMB_LB_INT_CTRL_CFG, drvdata->base + SMB_LB_INT_CTRL_REG);

Does this come with interrupt on overflow ? Do we not use this ?

When the buffer overflow, no interrupt will come.
Interrupt will upgrade SMB_LB_INT_STS_REG register status if start trace. Thanks.

Quoted 1 line

Rest looks fine to me.

Quoted 8 lines
Quoted 2 lines

What is the purpose of the "Interrupt" on the SMB ? It is not clear to me.

The SMB_LB_INT_CTRL_REG register control the validity of both real-time events and interrupts. When logical buffer status changes causes to issue an interrupt at the same time as it issues a real-time event. Real-time events are used in SMB driver, which needs to get the buffer status. Interrupts are used in debugger mode and cannot be registered in kernel.
 ..._BUF_NOTE_MASK control which events flags or interrupts are valid.

Please add this to a comment in the code above the register write.

Thanks
Suzuki

Quoted 12 lines

Thanks.

Best regards,
Junhao.

Quoted 5 lines

Suzuki

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#7 lore raw

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

Hi Suzuki ,

Quoted 44 lines · Suzuki K Poulose
Quoted 34 lines · hejunhao
Quoted 32 lines · Suzuki Kuruppassery Poulose
Quoted 30 lines · hejunhao

Hi Suzuki ,

Quoted 13 lines · Suzuki K Poulose
Quoted 12 lines · Junhao He

From: Qi Liu <[email protected]>

drivers/hwtracing/coresight/ultrasoc-smb.c new file +8 -0
+static void smb_init_hw(struct smb_drv_data *drvdata)
+{
+    /* First disable SMB and clear the status of SMB buffer */
+    smb_reset_buffer_status(drvdata);
+    smb_disable_hw(drvdata);
+    smb_purge_data(drvdata);
+
+    writel(SMB_LB_CFG_LO_DEFAULT, drvdata->base + 

SMB_LB_CFG_LO_REG);

Quoted 9 lines
Quoted 6 lines

+ writel(SMB_LB_CFG_HI_DEFAULT, drvdata->base +
SMB_LB_CFG_HI_REG);

drivers/hwtracing/coresight/ultrasoc-smb.c new file +3 -0
+    writel(SMB_GLB_CFG_DEFAULT, drvdata->base + SMB_GLB_CFG_REG);
+    writel(SMB_GLB_INT_CFG, drvdata->base + SMB_GLB_INT_REG);
+    writel(SMB_LB_INT_CTRL_CFG, drvdata->base + 

SMB_LB_INT_CTRL_REG);

Does this come with interrupt on overflow ? Do we not use this ?

When the buffer overflow, no interrupt will come.
Interrupt will upgrade SMB_LB_INT_STS_REG register status if start trace. Thanks.

Quoted 1 line

Rest looks fine to me.

Quoted 8 lines
Quoted 2 lines

What is the purpose of the "Interrupt" on the SMB ? It is not clear to me.

The SMB_LB_INT_CTRL_REG register control the validity of both real-time events and interrupts. When logical buffer status changes causes to issue an interrupt at the same time as it issues a real-time event. Real-time events are used in SMB driver, which needs to get the buffer status. Interrupts are used in debugger mode and cannot be registered in kernel.
..._BUF_NOTE_MASK control which events flags or interrupts are valid.

Quoted 5 lines

Please add this to a comment in the code above the register write.

Thanks
Suzuki

Yes, thanks for the comment. I will do that.

Best regards,
Junhao.

Quoted 16 lines
Quoted 12 lines

Thanks.

Best regards,
Junhao.

Quoted 5 lines

Suzuki

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

author
#8 lore raw

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

In reply to Junhao He

From: Qi Liu <[email protected]>

This patch bring in documentation for UltraSoc SMB drivers. It simply describes the device, sysfs interface and the firmware bindings.

---
 .../sysfs-bus-coresight-devices-ultra_smb     | 31 +++++++
 .../trace/coresight/ultrasoc-smb.rst          | 82 +++++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb
 create mode 100644 Documentation/trace/coresight/ultrasoc-smb.rst
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb new file +31 -0
new file mode 100644
index 000000000000..deaefd508105
@@ -0,0 +1,31 @@
+What:		/sys/bus/coresight/devices/ultra_smb<N>/enable_sink
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(RW) Add/remove a SMB device from a trace path. There can be
+		multiple sources for a single SMB device.
+
+What:		/sys/bus/coresight/devices/ultra_smb<N>/mgmt/buf_size
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(Read) Shows the buffer size of each UltraSoc SMB device.
+
+What:		/sys/bus/coresight/devices/ultra_smb<N>/mgmt/buf_status
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(Read) Shows the value held by UltraSoc SMB status register.
+		BIT(0) is zero means buffer is empty.
+
+What:		/sys/bus/coresight/devices/ultra_smb<N>/mgmt/read_pos
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(Read) Shows the value held by UltraSoc SMB Read Pointer register.
+
+What:		/sys/bus/coresight/devices/ultra_smb<N>/mgmt/write_pos
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(Read) Shows the value held by UltraSoc SMB Write Pointer register.
Documentation/trace/coresight/ultrasoc-smb.rst new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
2.33.0
#9 lore raw

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

Quoted 34 lines · Junhao He
Documentation/trace/coresight/ultrasoc-smb.rst new file +28 -0
new file mode 100644
index 000000000000..b7fe3f5c7f53
@@ -0,0 +1,82 @@
+.. 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(Super CPU Cluster) 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

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

Quoted 10 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +10 -0
+	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.

The key list above doesn't look right, so I have applied the fixup:

---- >8 ----

Documentation/trace/coresight/ultrasoc-smb.rst +3 -2
index b7fe3f5c7f53f7..5d0fa1a76b04d1 100644
@@ -30,11 +30,12 @@ The ``ultra_smb<N>`` named SMB associated with SCCL.::
 	$# ls /sys/bus/coresight/devices/ultra_smb0/mgmt
 	buf_size  buf_status  read_pos  write_pos
 
-*Key file items are:-*
+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.
+     BIT(0) is zero means buffer is empty.
    * ``buf_size``: Shows the buffer size of each UltraSoc SMB device.
 
 Firmware Bindings
Quoted 34 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +34 -0
+
+Firmware Bindings
+---------------------------
+
+SMB device is only supported with ACPI, and ACPI binding of SMB device
+describes SMB device indentifier, resource information and graph structure.
+
+SMB is identified by ACPI HID "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 32bits base
+address of shared system memory.
+
+examples::
+
+    Device(USMB) {                                               \
+      Name(_HID, "HISI03A1")                                     \
+      Name(_CRS, ResourceTemplate() {                            \
+          QWordMemory (ResourceConsumer, , MinFixed, MaxFixed, NonCacheable, \
+		       ReadWrite, 0x0, 0x95100000, 0x951FFFFF, 0x0, 0x100000) \
+          QWordMemory (ResourceConsumer, , MinFixed, MaxFixed, Cacheable, \
+		       ReadWrite, 0x0, 0x50000000, 0x53FFFFFF, 0x0, 0x4000000) \
+      })                                                         \
+      Name(_DSD, Package() {                                     \
+        ToUUID("ab02a46b-74c7-45a2-bd68-f7d344ef2153"),          \
+	/* Use CoreSight Graph ACPI bindings to describe connections topology */
+        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},       \

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

Quoted 10 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +10 -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},       \
+          }                                                      \
+        }                                                        \
+      })                                                         \
+    }

The rest of wordings also read a rather weird. What about below instead?

---- >8 ----

Documentation/trace/coresight/ultrasoc-smb.rst +18 -19
index 5d0fa1a76b04d1..eee32cbf90d2ea 100644
@@ -9,21 +9,21 @@ UltraSoc - HW Assisted Tracing on SoC
 Introduction
 ------------
 
-UltraSoc SMB is a per SCCL(Super CPU Cluster) hardware, and it provides a
+UltraSoc SMB is a per SCCL (Super CPU Cluster) hardware. 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.
+memory. The device acts as a coresight sink device and the
+corresponding trace generators (ETM) are attached as source devices.
 
 Sysfs files and directories
 ---------------------------
 
-The SMB devices appear on the existing coresight bus alongside the other
-coresight devices::
+The SMB devices appear on the existing coresight bus alongside other
+devices::
 
 	$# ls /sys/bus/coresight/devices/
 	ultra_smb0   ultra_smb1   ultra_smb2   ultra_smb3
 
-The ``ultra_smb<N>`` named SMB associated with SCCL.::
+The ``ultra_smb<N>`` names SMB device associated with SCCL.::
 
 	$# ls /sys/bus/coresight/devices/ultra_smb0
 	enable_sink   mgmt
@@ -32,24 +32,23 @@ The ``ultra_smb<N>`` named SMB associated with SCCL.::
 
 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.
+   * ``read_pos``: Shows the value on the read pointer register.
+   * ``write_pos``: Shows the value on the write pointer register.
+   * ``buf_status``: Shows the value on the status register.
+     BIT(0) is zero value which means the buffer is empty.
+   * ``buf_size``: Shows the buffer size of each device.
 
 Firmware Bindings
----------------------------
+-----------------
 
-SMB device is only supported with ACPI, and ACPI binding of SMB device
-describes SMB device indentifier, resource information and graph structure.
+The device is only supported with ACPI. Its binding describes device
+identifier, resource information and graph structure.
 
-SMB is identified by ACPI HID "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 32bits base
-address of shared system memory.
+The device is identified as ACPI HID "HISI03A1". Device resources are allocated
+using the _CRS method. Each device must present two base address; the first one is the configuration base address of the device, the second one is the 32-bit
+base address of shared system memory.
 
-examples::
+Example::
 
     Device(USMB) {                                               \
       Name(_HID, "HISI03A1")                                     \

Thanks.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
author
#10 lore raw

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

Hi Bagas,

will apply the fix in next version.
Thank you very much.

Best regards,
Junhao.

Quoted 189 lines · Bagas Sanjaya
Quoted 34 lines · Junhao He
Documentation/trace/coresight/ultrasoc-smb.rst new file +28 -0
new file mode 100644
index 000000000000..b7fe3f5c7f53
@@ -0,0 +1,82 @@
+.. 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(Super CPU Cluster) 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

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

Quoted 10 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +10 -0
+	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.

The key list above doesn't look right, so I have applied the fixup:

---- >8 ----

Documentation/trace/coresight/ultrasoc-smb.rst +3 -2
index b7fe3f5c7f53f7..5d0fa1a76b04d1 100644
@@ -30,11 +30,12 @@ The ``ultra_smb<N>`` named SMB associated with SCCL.::
  	$# ls /sys/bus/coresight/devices/ultra_smb0/mgmt
  	buf_size  buf_status  read_pos  write_pos
 
-*Key file items are:-*
+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.
+     BIT(0) is zero means buffer is empty.
     * ``buf_size``: Shows the buffer size of each UltraSoc SMB device.
 
  Firmware Bindings
Quoted 35 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +34 -0
+
+Firmware Bindings
+---------------------------
+
+SMB device is only supported with ACPI, and ACPI binding of SMB device
+describes SMB device indentifier, resource information and graph structure.
+
+SMB is identified by ACPI HID "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 32bits base
+address of shared system memory.
+
+examples::
+
+    Device(USMB) {                                               \
+      Name(_HID, "HISI03A1")                                     \
+      Name(_CRS, ResourceTemplate() {                            \
+          QWordMemory (ResourceConsumer, , MinFixed, MaxFixed, NonCacheable, \
+		       ReadWrite, 0x0, 0x95100000, 0x951FFFFF, 0x0, 0x100000) \
+          QWordMemory (ResourceConsumer, , MinFixed, MaxFixed, Cacheable, \
+		       ReadWrite, 0x0, 0x50000000, 0x53FFFFFF, 0x0, 0x4000000) \
+      })                                                         \
+      Name(_DSD, Package() {                                     \
+        ToUUID("ab02a46b-74c7-45a2-bd68-f7d344ef2153"),          \
+	/* Use CoreSight Graph ACPI bindings to describe connections topology */
+        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},       \

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

Quoted 10 lines
Documentation/trace/coresight/ultrasoc-smb.rst new file +10 -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},       \
+          }                                                      \
+        }                                                        \
+      })                                                         \
+    }

The rest of wordings also read a rather weird. What about below instead?

---- >8 ----

Documentation/trace/coresight/ultrasoc-smb.rst +18 -19
index 5d0fa1a76b04d1..eee32cbf90d2ea 100644
@@ -9,21 +9,21 @@ UltraSoc - HW Assisted Tracing on SoC
  Introduction
  ------------
 
-UltraSoc SMB is a per SCCL(Super CPU Cluster) hardware, and it provides a
+UltraSoc SMB is a per SCCL (Super CPU Cluster) hardware. 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.
+memory. The device acts as a coresight sink device and the
+corresponding trace generators (ETM) are attached as source devices.
 
  Sysfs files and directories
  ---------------------------
 
-The SMB devices appear on the existing coresight bus alongside the other
-coresight devices::
+The SMB devices appear on the existing coresight bus alongside other
+devices::
 
  	$# ls /sys/bus/coresight/devices/
  	ultra_smb0   ultra_smb1   ultra_smb2   ultra_smb3
 
-The ``ultra_smb<N>`` named SMB associated with SCCL.::
+The ``ultra_smb<N>`` names SMB device associated with SCCL.::
 
  	$# ls /sys/bus/coresight/devices/ultra_smb0
  	enable_sink   mgmt
@@ -32,24 +32,23 @@ The ``ultra_smb<N>`` named SMB associated with SCCL.::
 
  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.
+   * ``read_pos``: Shows the value on the read pointer register.
+   * ``write_pos``: Shows the value on the write pointer register.
+   * ``buf_status``: Shows the value on the status register.
+     BIT(0) is zero value which means the buffer is empty.
+   * ``buf_size``: Shows the buffer size of each device.
 
  Firmware Bindings
----------------------------
+-----------------
 
-SMB device is only supported with ACPI, and ACPI binding of SMB device
-describes SMB device indentifier, resource information and graph structure.
+The device is only supported with ACPI. Its binding describes device
+identifier, resource information and graph structure.
 
-SMB is identified by ACPI HID "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 32bits base
-address of shared system memory.
+The device is identified as ACPI HID "HISI03A1". Device resources are allocated
+using the _CRS method. Each device must present two base address; the first one is the configuration base address of the device, the second one is the 32-bit
+base address of shared system memory.
 
-examples::
+Example::
 
      Device(USMB) {                                               \
        Name(_HID, "HISI03A1")                                     \

Thanks.

#11 lore raw

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

Quoted 5 lines · hejunhao

Hi Bagas,

will apply the fix  in next version.
Thank you very much.

Please don't top-post, reply inline with appropriate context instead. I had to trim all the below context as a result.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
author
#12 lore raw

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

Hi Bagas,

Quoted 8 lines · Bagas Sanjaya
Quoted 5 lines · hejunhao

Hi Bagas,

will apply the fix in next version.
Thank you very much.

Please don't top-post, reply inline with appropriate context instead. I had to trim all the below context as a result.

Yes, I'm sorry for that.

Best regards,
Junhao.

#13 lore raw
In reply to Junhao He
Quoted 2 lines · Junhao He

Add support for UltraSoc System Memory Buffer.

The cover letter message (aside changelogs) is short but LGTM. However, for individual patches description, please write in imperative mood (that is, no "This patch/commit does foo" but "Do foo" instead).

Thanks.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
author
#14 lore raw

Hi Bagas,

Quoted 8 lines · Bagas Sanjaya
Quoted 2 lines · Junhao He

Add support for UltraSoc System Memory Buffer.

The cover letter message (aside changelogs) is short but LGTM. However, for individual patches description, please write in imperative mood (that is, no "This patch/commit does foo" but "Do foo" instead).

Thanks.

Yes, I will do that.

Best regards,
Junhao.