Add support for UltraSoc System Memory Buffer
v11 cover Add support for UltraSoc System Memory Buffer
Add support for UltraSoc System Memory Buffer.
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 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 | 80 +++ drivers/hwtracing/coresight/Kconfig | 11 + drivers/hwtracing/coresight/Makefile | 1 + drivers/hwtracing/coresight/ultrasoc-smb.c | 631 ++++++++++++++++++ drivers/hwtracing/coresight/ultrasoc-smb.h | 113 ++++ 6 files changed, 867 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
PATCH v11 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 | 631 +++++++++++++++++++++ drivers/hwtracing/coresight/ultrasoc-smb.h | 113 ++++ 4 files changed, 756 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
@@ -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 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
@@ -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 +631 -0
631 lines not on this page · raw message
drivers/hwtracing/coresight/ultrasoc-smb.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.33.0
Re: [PATCH v11 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver
Quoted 6 lines · On Mon, 7 Nov 2022 21:06:23 +0800 Junhao He <[email protected]> wrote:
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.
Quoted 6 lines
SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.
Signed-off-by Qi Liu <[email protected]>Signed-off-by Junhao He <[email protected]>Tested-by JunHao He <[email protected]>
Hi JunHao,
It's been a while since I last looked at this driver, so I may have forgotten or missed previous discussions.
All the comments inline are fairly superficial and mostly concerned with making the code easy to review / maintain rather than correctness.
Jonathan
Quoted 14 lines
--- drivers/hwtracing/coresight/Kconfig | 11 + drivers/hwtracing/coresight/Makefile | 1 + drivers/hwtracing/coresight/ultrasoc-smb.c | 631 +++++++++++++++++++++ drivers/hwtracing/coresight/ultrasoc-smb.h | 113 ++++ 4 files changed, 756 insertions(+) create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.hdrivers/hwtracing/coresight/Kconfig +0
-0
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 ACPI && ARM64 && CORESIGHT_LINKS_AND_SINKS
Can you relax this at all in the interests of getting better CI build coverage from random configs etc.
From a quick look, I think you can safely drop the ACPI dependency on basis relevant functions are stubbed out in acpi.h
However, it looks like coresight more generally uses such depends, so perhaps better to just leave them here for consistency.
Quoted 16 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. endifdrivers/hwtracing/coresight/ultrasoc-smb.c new file +0
-0@@ -0,0 +1,631 @@
...
drivers/hwtracing/coresight/ultrasoc-smb.c line 40
Quoted 11 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +11
-0+ +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 ) - sdb->start_addr; + sdb->rd_offset =readl (drvdata->base +SMB_LB_RD_ADDR ) - sdb->start_addr; +if (sdb->wr_offset == sdb->rd_offset && !smb_buffer_is_empty (drvdata)) + sdb->full = true; +else + sdb->full = false;
Could do as
sdb->full = sdb->wr_offset == sdb->rd_offset && !smb_buffer_is_empty(drvdata);
up to you on which you think is more readable.
drivers/hwtracing/coresight/ultrasoc-smb.c line 170
Quoted 11 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +8
-0+} + +static struct attribute *smb_sink_attrs[] = { +coresight_simple_reg32 (read_pos,SMB_LB_RD_ADDR ), +coresight_simple_reg32 (write_pos,SMB_LB_WR_ADDR ), +coresight_simple_reg32 (buf_status,SMB_LB_INT_STS ), + &dev_attr_buf_size.attr, +NULL ,
As below.
drivers/hwtracing/coresight/ultrasoc-smb.c line 180
Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10
-0+}; + +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 ,
Generally no comma after a NULL terminator. Having a comma implies it may make sense to put something after it, which is never the case for these.
Quoted 2 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +2
-0+}; +
...
drivers/hwtracing/coresight/ultrasoc-smb.c line 337
Quoted 7 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +7
-0+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;
Do you need the cast? It's void ** so implicit cast should work I think.
char **dst_pages = buf->data_pages;
Quoted 44 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +44
-0+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 ; +writel (sdb->start_addr + sdb->rd_offset, drvdata->base +SMB_LB_RD_ADDR ); + +/* +* 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 ), + drvdata->base +SMB_LB_RD_ADDR ); + } +smb_reset_buffer_status (drvdata); +}
...
drivers/hwtracing/coresight/ultrasoc-smb.c line 473
Quoted 4 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +4
-0+ +static void smb_init_hw (struct smb_drv_data *drvdata) +{ +/* First disable smb and clear the status of SMB buffer */
Check for consistency in capitalization of SMB in all comments.
Quoted 11 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +11
-0+smb_reset_buffer_status (drvdata); +smb_disable_hw (drvdata); +smb_purge_data (drvdata); + +writel (SMB_BUF_CFG_STREAMING , drvdata->base +SMB_LB_CFG_LO ); +writel (SMB_MSG_FILTER , drvdata->base +SMB_LB_CFG_HI ); +writel (SMB_GLOBAL_CFG , drvdata->base +SMB_CFG_REG ); +writel (SMB_GLB_INT_CFG , drvdata->base +SMB_GLOBAL_INT ); +writel (SMB_BUF_INT_CFG , drvdata->base +SMB_LB_INT_CTRL ); +} +
...
Quoted 42 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +42
-0+static int smb_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct smb_drv_data *drvdata; +int ret; + + drvdata =devm_kzalloc (dev,sizeof (*drvdata),GFP_KERNEL ); +if (!drvdata) +return -ENOMEM ; + + drvdata->base =devm_platform_ioremap_resource (pdev,SMB_BASE_ADDR_RES ); +if (IS_ERR (drvdata->base)) { +dev_err (dev,"Failed to ioremap resource\n" ); +return PTR_ERR (drvdata->base); + } + + ret =smb_init_data_buffer (pdev, &drvdata->sdb); +if (ret) { +dev_err (dev,"Failed to init buffer, ret = %d\n" , ret); +return ret; + } + +smb_init_hw (drvdata); +mutex_init (&drvdata->mutex); + drvdata->pid =-1 ; + + ret =smb_register_sink (pdev, drvdata); +if (ret) { +dev_err (dev,"Failed to register smb sink\n" ); +return ret; + } + + ret =smb_config_inport (dev, true); +if (ret) { +smb_unregister_sink (drvdata); +return ret; + } + +platform_set_drvdata (pdev, drvdata); +return 0 ; +} +
drivers/hwtracing/coresight/ultrasoc-smb.c line 607
Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10
-0+static int smb_remove (struct platform_device *pdev) +{ +struct smb_drv_data *drvdata =platform_get_drvdata (pdev); +int ret; + + ret =smb_config_inport (&pdev->dev, false); +if (ret) +return ret; + +smb_unregister_sink (drvdata);
Trivial: I find a blank line before plane returns like this helps a little with readability. Up to you though!
drivers/hwtracing/coresight/ultrasoc-smb.c line 613
Quoted 6 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +6
-0+return 0 ; +} + +static const struct acpi_device_id ultrasoc_smb_acpi_match[] = { + {"HISI03A1" ,0 }, + {},
Trivial, but little point in a trailing comma on a NULL terminator.
{}
};is normally fine - note this is a bit subsystem specific so maintainer may say otherwise.
Quoted 24 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +18
-0+}; +MODULE_DEVICE_TABLE (acpi, ultrasoc_smb_acpi_match); + +static struct platform_driver smb_driver = { + .driver = { + .name ="ultrasoc-smb" , + .acpi_match_table =ACPI_PTR (ultrasoc_smb_acpi_match), + .suppress_bind_attrs = true, + }, + .probe = smb_probe, + .remove = smb_remove, +}; +module_platform_driver (smb_driver); + +MODULE_DESCRIPTION ("UltraSoc SMB CoreSight driver" ); +MODULE_LICENSE ("Dual MIT/GPL" ); +MODULE_AUTHOR ("Jonathan Zhou <[email protected]>" ); +MODULE_AUTHOR ("Qi Liu <[email protected]>" );drivers/hwtracing/coresight/ultrasoc-smb.h new file +0
-0
drivers/hwtracing/coresight/ultrasoc-smb.h line 10
Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +10
-0@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */ +/* +* Siemens System Memory Buffer driver. +* Copyright(c) 2022, HiSilicon Limited. +*/ + +#ifndef _ULTRASOC_SMB_H +#define _ULTRASOC_SMB_H + +#include <linux/coresight.h>
I think you could move this down into the c files and provide a forwards definition of struct coresight device
Always good to keep scope of includes to minimum necessary.
drivers/hwtracing/coresight/ultrasoc-smb.h line 15
Quoted 5 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +5
-0+#include <linux/miscdevice.h> +#include <linux/mutex.h> + +/* Offset of SMB logical buffer registers */ +#define SMB_CFG_REG 0x00
To avoid any naming confusion I would postfix all the register addresses with _REG
Then rethink the naming so the field names make it clear which register they are in.
Quoted 6 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +6
-0+#define SMB_GLOBAL_EN 0x04 +#define SMB_GLOBAL_INT 0x08 +#define SMB_LB_CFG_LO 0x40 +#define SMB_LB_CFG_HI 0x44 +#define SMB_LB_INT_CTRL 0x48 +#define SMB_LB_INT_STS 0x4c
drivers/hwtracing/coresight/ultrasoc-smb.h line 31
Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +10
-0+#define SMB_LB_LIMIT 0x58 +#define SMB_LB_RD_ADDR 0x5c +#define SMB_LB_WR_ADDR 0x60 +#define SMB_LB_PURGE 0x64 + +/* Set SMB_CFG_REG register */ +#define SMB_BURST_LEN GENMASK(7, 4) +#define SMB_IDLE_PRD GENMASK(15, 12) +#define SMB_MEM_WR GENMASK(17, 16) +#define SMB_MEM_RD (GENMASK(26, 25) | GENMASK(23, 22))
Are these masks, or default values? Ideally express them as a field mask then the value via FIELD_PREP
e.g.
#define SMB_CFG_BURST_LEN_MSK GENMASK(7, 4)
#define SMB_GLOBAL_CFG_DEFAULT ... | FIELD_PREP(SMB_CFG_BURST_LEN_MSK, 0xf) | etc
Quoted 24 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +24
-0+#define SMB_GLOBAL_CFG (SMB_IDLE_PRD | SMB_MEM_WR | SMB_MEM_RD | \ + SMB_BURST_LEN) + +/* Set SMB_GLOBAL_INT register */ +#define SMB_INT_EN BIT(0) +#define SMB_INT_TYPE_PULSE BIT(1) +#define SMB_INT_POLARITY_HIGH BIT(2) +#define SMB_GLB_INT_CFG (SMB_INT_EN | SMB_INT_TYPE_PULSE | \ + SMB_INT_POLARITY_HIGH) + +/* Set SMB_LB_CFG_LO register */ +#define SMB_BUF_EN BIT(0) +#define SMB_BUF_SINGLE_END BIT(1) +#define SMB_BUF_INIT BIT(8) +#define SMB_BUF_CONTINUOUS BIT(11) +#define SMB_FILTER_FLOW GENMASK(19, 16) +#define SMB_BUF_CFG_STREAMING (SMB_BUF_INIT | SMB_BUF_CONTINUOUS | \ + SMB_FILTER_FLOW | SMB_BUF_SINGLE_END | \ + SMB_BUF_EN) + +#define SMB_BASE_LOW_MASK GENMASK(31, 0) + +/* Set SMB_LB_CFG_HI register */ +#define SMB_MSG_FILTER GENMASK(15, 8)
drivers/hwtracing/coresight/ultrasoc-smb.h line 65
Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +10
-0+ +/* Set SMB_LB_INT_CTRL */ +#define SMB_BUF_INT_EN BIT(0) +#define SMB_BUF_NOTE_MASK GENMASK(11, 8) +#define SMB_BUF_INT_CFG (SMB_BUF_INT_EN | SMB_BUF_NOTE_MASK) + +#define SMB_BUF_NOT_EMPTY BIT(0) +#define SMB_RESET_BUF_STS GENMASK(3, 0) +#define SMB_PURGED BIT(0) +#define SMB_HW_ENABLE BIT(0)
It is useful to give fields names that reflect which register they are in. PerhapsSMB_GLOBAL_EN_HW_ENABLE for this one.
drivers/hwtracing/coresight/ultrasoc-smb.h line 78
Quoted 13 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +13
-0+ +#define SMB_BASE_ADDR_RES 0 +#define SMB_BUF_INFO_RES 1 + +/** +* struct smb_data_buffer - Details of the buffer used by SMB +* @buf_base: Memory mapped base address of SMB. +* @start_addr: SMB buffer start Physical address. +* @buf_size: Size of the buffer. +* @data_size: Size of Trace data copy to userspace. +* @rd_offset: Offset of the read pointer in the buffer. +* @wr_offset: Offset of the write pointer in the buffer. +* @status: Status of SMB buffer.
Naming wrong.
Quoted 35 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +35
-0+*/ +struct smb_data_buffer { +void __iomem *buf_base; +u32 start_addr; +unsigned long buf_size; +unsigned long data_size; +unsigned long rd_offset; +unsigned long wr_offset; +bool full; +}; + +/** +* struct smb_drv_data - specifics associated to an SMB component +* @base: Memory mapped base address for SMB component. +* @csdev: Component vitals needed by the framework. +* @sdb: Data buffer for SMB. +* @miscdev: Specifics to handle "/dev/xyz.smb" entry. +* @mutex: Control data access to one at a time. +* @reading: Synchronise user space access to SMB buffer. +* @pid: Process ID of the process being monitored by the +* session that is using this component. +* @mode: how this SMB is being used, perf mode or sysfs mode. +*/ +struct smb_drv_data { +void __iomem *base; +struct coresight_device *csdev; +struct smb_data_buffer sdb; +struct miscdevice miscdev; +struct mutex mutex; +local_t reading; +pid_t pid; +u32 mode; +}; + +#endif
Re: [PATCH v11 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver
Hi Jonathan,
Thanks for your comments.
Quoted 17 lines · Jonathan Cameron
Quoted 6 lines · On Mon, 7 Nov 2022 21:06:23 +0800 Junhao He <[email protected]> wrote:
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.
Quoted 6 lines
SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.
Signed-off-by Qi Liu <[email protected]>Signed-off-by Junhao He <[email protected]>Tested-by JunHao He <[email protected]>Hi JunHao,
Quoted 7 lines
It's been a while since I last looked at this driver, so I may have forgotten or missed previous discussions.
All the comments inline are fairly superficial and mostly concerned with making the code easy to review / maintain rather than correctness.
Jonathan
Yes, I will do that.
Junhao.
Quoted 24 lines
Quoted 14 lines
--- drivers/hwtracing/coresight/Kconfig | 11 + drivers/hwtracing/coresight/Makefile | 1 + drivers/hwtracing/coresight/ultrasoc-smb.c | 631 +++++++++++++++++++++ drivers/hwtracing/coresight/ultrasoc-smb.h | 113 ++++ 4 files changed, 756 insertions(+)create mode 100644
drivers/hwtracing/coresight/ultrasoc-smb.ccreate mode 100644drivers/hwtracing/coresight/ultrasoc-smb.hdrivers/hwtracing/coresight/Kconfig +0
-0drivers/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 ACPI && ARM64 && CORESIGHT_LINKS_AND_SINKSCan you relax this at all in the interests of getting better CI build coverage from random configs etc.
Quoted 5 lines
Quoted 1 line
From a quick look, I think you can safely drop the ACPI dependency on basis
relevant functions are stubbed out in
acpi.hHowever, it looks like coresight more generally uses such depends, so perhaps better to just leave them here for consistency.
Ok, Will check it.
Thanks.
Quoted 30 lines
Quoted 15 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. endifdrivers/hwtracing/coresight/ultrasoc-smb.c new file +0
-0@@ -0,0 +1,631 @@...
drivers/hwtracing/coresight/ultrasoc-smb.c line 40
Quoted 11 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +11
-0+ +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 ) - sdb->start_addr; + sdb->rd_offset =readl (drvdata->base +SMB_LB_RD_ADDR ) - sdb->start_addr; +if (sdb->wr_offset == sdb->rd_offset && !smb_buffer_is_empty (drvdata)) + sdb->full = true; +else + sdb->full = false;Could do as
Quoted 2 lines
sdb->full = sdb->wr_offset == sdb->rd_offset && !smb_buffer_is_empty(drvdata);up to you on which you think is more readable.
Ok, I will drop this "if else" block.
Thanks.
Quoted 5 lines
Quoted 3 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +2
-0+} +
Quoted 7 lines
drivers/hwtracing/coresight/ultrasoc-smb.c line 170
Quoted 6 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +6
-0+static struct attribute *smb_sink_attrs[] = { +coresight_simple_reg32 (read_pos,SMB_LB_RD_ADDR ), +coresight_simple_reg32 (write_pos,SMB_LB_WR_ADDR ), +coresight_simple_reg32 (buf_status,SMB_LB_INT_STS ), + &dev_attr_buf_size.attr, +NULL ,As below.
Sure, Will fix in next version.
Thanks.
Quoted 14 lines
drivers/hwtracing/coresight/ultrasoc-smb.c line 180
Quoted 11 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10
-0+}; + +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 ,Generally no comma after a NULL terminator. Having a comma implies it may make sense to put something after it, which is never the case for these.
Sure, Will fix in next version.
Thanks.
Quoted 13 lines
Quoted 2 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +2
-0+}; +...
drivers/hwtracing/coresight/ultrasoc-smb.c line 337
Quoted 7 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +7
-0+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;Do you need the cast? It's void ** so implicit cast should work I think.
Quoted 1 line
char **dst_pages = buf->data_pages;
Ok, Will fix in next version.
Thanks.
Quoted 47 lines
Quoted 44 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +44
-0+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 ; +writel (sdb->start_addr + sdb->rd_offset, drvdata->base +SMB_LB_RD_ADDR ); + +/* +* 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 ), + drvdata->base +SMB_LB_RD_ADDR ); + } +smb_reset_buffer_status (drvdata); +}...
Quoted 5 lines
drivers/hwtracing/coresight/ultrasoc-smb.c line 473
Quoted 4 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +4
-0+ +static void smb_init_hw (struct smb_drv_data *drvdata) +{ +/* First disable smb and clear the status of SMB buffer */ Check for consistency in capitalization of SMB in all comments.
Sure, Will fix in next version.
Thanks.
Quoted 61 lines
Quoted 12 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +11
-0+smb_reset_buffer_status (drvdata); +smb_disable_hw (drvdata); +smb_purge_data (drvdata); + +writel (SMB_BUF_CFG_STREAMING , drvdata->base +SMB_LB_CFG_LO ); +writel (SMB_MSG_FILTER , drvdata->base +SMB_LB_CFG_HI ); +writel (SMB_GLOBAL_CFG , drvdata->base +SMB_CFG_REG ); +writel (SMB_GLB_INT_CFG , drvdata->base +SMB_GLOBAL_INT ); +writel (SMB_BUF_INT_CFG , drvdata->base +SMB_LB_INT_CTRL ); +} +...
Quoted 46 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +46
-0+static int smb_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct smb_drv_data *drvdata; +int ret; + + drvdata =devm_kzalloc (dev,sizeof (*drvdata),GFP_KERNEL ); +if (!drvdata) +return -ENOMEM ; + + drvdata->base =devm_platform_ioremap_resource (pdev,SMB_BASE_ADDR_RES ); +if (IS_ERR (drvdata->base)) { +dev_err (dev,"Failed to ioremap resource\n" ); +return PTR_ERR (drvdata->base); + } + + ret =smb_init_data_buffer (pdev, &drvdata->sdb); +if (ret) { +dev_err (dev,"Failed to init buffer, ret = %d\n" , ret); +return ret; + } + +smb_init_hw (drvdata); +mutex_init (&drvdata->mutex); + drvdata->pid =-1 ; + + ret =smb_register_sink (pdev, drvdata); +if (ret) { +dev_err (dev,"Failed to register smb sink\n" ); +return ret; + } + + ret =smb_config_inport (dev, true); +if (ret) { +smb_unregister_sink (drvdata); +return ret; + } + +platform_set_drvdata (pdev, drvdata); +return 0 ; +} + +static int smb_remove (struct platform_device *pdev) +{ +struct smb_drv_data *drvdata =platform_get_drvdata (pdev); +int ret;
Quoted 8 lines
drivers/hwtracing/coresight/ultrasoc-smb.c line 607
Quoted 6 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +6
-0+ + ret =smb_config_inport (&pdev->dev, false); +if (ret) +return ret; + +smb_unregister_sink (drvdata);Trivial: I find a blank line before plane returns like this helps a little with readability. Up to you though!
Ok, Will fix it.
Thanks.
Quoted 8 lines
drivers/hwtracing/coresight/ultrasoc-smb.c line 613
Quoted 7 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +6
-0+return 0 ; +} + +static const struct acpi_device_id ultrasoc_smb_acpi_match[] = { + {"HISI03A1" ,0 }, + {},Trivial, but little point in a trailing comma on a NULL terminator.
Sure, Will fix in next version.
Thanks.
Quoted 6 lines
{} };is normally fine - note this is a bit subsystem specific so maintainer may say otherwise.
Ok, Thanks.
Quoted 38 lines
Quoted 25 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +18
-0+}; +MODULE_DEVICE_TABLE (acpi, ultrasoc_smb_acpi_match); + +static struct platform_driver smb_driver = { + .driver = { + .name ="ultrasoc-smb" , + .acpi_match_table =ACPI_PTR (ultrasoc_smb_acpi_match), + .suppress_bind_attrs = true, + }, + .probe = smb_probe, + .remove = smb_remove, +}; +module_platform_driver (smb_driver); + +MODULE_DESCRIPTION ("UltraSoc SMB CoreSight driver" ); +MODULE_LICENSE ("Dual MIT/GPL" ); +MODULE_AUTHOR ("Jonathan Zhou <[email protected]>" ); +MODULE_AUTHOR ("Qi Liu <[email protected]>" );drivers/hwtracing/coresight/ultrasoc-smb.h new file +0
-0drivers/hwtracing/coresight/ultrasoc-smb.h line 10
Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +10
-0@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */ +/* +* Siemens System Memory Buffer driver. +* Copyright(c) 2022, HiSilicon Limited. +*/ + +#ifndef _ULTRASOC_SMB_H +#define _ULTRASOC_SMB_H + +#include <linux/coresight.h> I think you could move this down into the c files and provide a forwards definition of struct coresight device
Quoted 1 line
Always good to keep scope of includes to minimum necessary.
Sure, Will fix in next version.
Thanks.
Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.h line 15
Quoted 6 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +5
-0+#include <linux/miscdevice.h> +#include <linux/mutex.h> + +/* Offset of SMB logical buffer registers */ +#define SMB_CFG_REG 0x00To avoid any naming confusion I would postfix all the register addresses with
_REG
Then rethink the naming so the field names make it clear which register they are in.
OK, I'll check all REG names.
Thanks.
Quoted 20 lines
Quoted 7 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +6
-0+#define SMB_GLOBAL_EN 0x04 +#define SMB_GLOBAL_INT 0x08 +#define SMB_LB_CFG_LO 0x40 +#define SMB_LB_CFG_HI 0x44 +#define SMB_LB_INT_CTRL 0x48 +#define SMB_LB_INT_STS 0x4cdrivers/hwtracing/coresight/ultrasoc-smb.h line 31
Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +10
-0+#define SMB_LB_LIMIT 0x58 +#define SMB_LB_RD_ADDR 0x5c +#define SMB_LB_WR_ADDR 0x60 +#define SMB_LB_PURGE 0x64 + +/* Set SMB_CFG_REG register */ +#define SMB_BURST_LEN GENMASK(7, 4) +#define SMB_IDLE_PRD GENMASK(15, 12) +#define SMB_MEM_WR GENMASK(17, 16) +#define SMB_MEM_RD (GENMASK(26, 25) | GENMASK(23, 22))Are these masks, or default values? Ideally express them as a field mask then the value via
FIELD_PREP
Quoted 3 lines
e.g.
#defineSMB_CFG_BURST_LEN_MSKGENMASK(7, 4)
#defineSMB_GLOBAL_CFG_DEFAULT... |FIELD_PREP(SMB_CFG_BURST_LEN_MSK, 0xf)| etc
Sure, I will do that.
Thanks.
Quoted 31 lines
Quoted 31 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +29
-0+#define SMB_GLOBAL_CFG (SMB_IDLE_PRD | SMB_MEM_WR | SMB_MEM_RD | \ + SMB_BURST_LEN) + +/* Set SMB_GLOBAL_INT register */ +#define SMB_INT_EN BIT(0) +#define SMB_INT_TYPE_PULSE BIT(1) +#define SMB_INT_POLARITY_HIGH BIT(2) +#define SMB_GLB_INT_CFG (SMB_INT_EN | SMB_INT_TYPE_PULSE | \ + SMB_INT_POLARITY_HIGH) + +/* Set SMB_LB_CFG_LO register */ +#define SMB_BUF_EN BIT(0) +#define SMB_BUF_SINGLE_END BIT(1) +#define SMB_BUF_INIT BIT(8) +#define SMB_BUF_CONTINUOUS BIT(11) +#define SMB_FILTER_FLOW GENMASK(19, 16) +#define SMB_BUF_CFG_STREAMING (SMB_BUF_INIT | SMB_BUF_CONTINUOUS | \ + SMB_FILTER_FLOW | SMB_BUF_SINGLE_END | \ + SMB_BUF_EN) + +#define SMB_BASE_LOW_MASK GENMASK(31, 0) + +/* Set SMB_LB_CFG_HI register */ +#define SMB_MSG_FILTER GENMASK(15, 8) + +/* Set SMB_LB_INT_CTRL */ +#define SMB_BUF_INT_EN BIT(0) +#define SMB_BUF_NOTE_MASK GENMASK(11, 8) +#define SMB_BUF_INT_CFG (SMB_BUF_INT_EN | SMB_BUF_NOTE_MASK)
Quoted 8 lines
drivers/hwtracing/coresight/ultrasoc-smb.h line 65
Quoted 5 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +5
-0+ +#define SMB_BUF_NOT_EMPTY BIT(0) +#define SMB_RESET_BUF_STS GENMASK(3, 0) +#define SMB_PURGED BIT(0) +#define SMB_HW_ENABLE BIT(0)It is useful to give fields names that reflect which register they are in. Perhaps
SMB_GLOBAL_EN_HW_ENABLEfor this one.
Sure, I will do that.
Thanks.
Quoted 15 lines
Quoted 4 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +3
-0+ +#define SMB_BASE_ADDR_RES 0 +#define SMB_BUF_INFO_RES 1drivers/hwtracing/coresight/ultrasoc-smb.h line 78
Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +10
-0+ +/** +* struct smb_data_buffer - Details of the buffer used by SMB +* @buf_base: Memory mapped base address of SMB. +* @start_addr: SMB buffer start Physical address. +* @buf_size: Size of the buffer. +* @data_size: Size of Trace data copy to userspace. +* @rd_offset: Offset of the read pointer in the buffer. +* @wr_offset: Offset of the write pointer in the buffer. +* @status: Status of SMB buffer. Naming wrong.
Sure, Will fix in next version.
Thanks.
Quoted 29 lines
Quoted 29 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +28
-0+*/ +struct smb_data_buffer { +void __iomem *buf_base; +u32 start_addr; +unsigned long buf_size; +unsigned long data_size; +unsigned long rd_offset; +unsigned long wr_offset; +bool full; +}; + +/** +* struct smb_drv_data - specifics associated to an SMB component +* @base: Memory mapped base address for SMB component. +* @csdev: Component vitals needed by the framework. +* @sdb: Data buffer for SMB. +* @miscdev: Specifics to handle "/dev/xyz.smb" entry. +* @mutex: Control data access to one at a time. +* @reading: Synchronise user space access to SMB buffer. +* @pid: Process ID of the process being monitored by the +* session that is using this component. +* @mode: how this SMB is being used, perf mode or sysfs mode. +*/ +struct smb_drv_data { +void __iomem *base; +struct coresight_device *csdev; +struct smb_data_buffer sdb; +struct miscdevice miscdev;
Quoted 9 lines
drivers/hwtracing/coresight/ultrasoc-smb.h line 113
Quoted 7 lines
drivers/hwtracing/coresight/ultrasoc-smb.h new file +7
-0+struct mutex mutex; +local_t reading; +pid_t pid; + u32 mode; +}; + +#endif .
Best regards,
Junhao.
PATCH v11 2/2 Documentation: Add document for UltraSoc SMB drivers
In reply to Junhao HeFrom: 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 | 80 +++++++++++++++++++ 2 files changed, 111 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
@@ -0,0 +1,31 @@ +What: /sys/bus/coresight/devices/ultra_smb<N>/enable_sink +Date: October 2022 +KernelVersion: 6.1 +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: October 2022 +KernelVersion: 6.1 +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: October 2022 +KernelVersion: 6.1 +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: October 2022 +KernelVersion: 6.1 +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: October 2022 +KernelVersion: 6.1 +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 +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.33.0
Re: [PATCH v11 2/2] Documentation: Add document for UltraSoc SMB drivers
Quoted 21 lines · On Mon, 7 Nov 2022 21:06:24 +0800 Junhao He <[email protected]> wrote:
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.
Signed-off-by Qi Liu <[email protected]>Signed-off-by Junhao He <[email protected]>--- .../sysfs-bus-coresight-devices-ultra_smb | 31 +++++++ .../trace/coresight/ultrasoc-smb.rst | 80 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb create mode 100644 Documentation/trace/coresight/ultrasoc-smb.rstDocumentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb new file +0
-0
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb line 3
Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb new file +3
-0@@ -0,0 +1,31 @@ +What: /sys/bus/coresight/devices/ultra_smb<N>/enable_sink +Date: October 2022 +KernelVersion: 6.1
Update to 6.2 as this will hopefully go in next merge window and it makes life easier for the maintainer if they don't need to fix all these up.
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb line 6
Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb new file +3
-0+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.
Rest looks good to me, (not an expert on this stuff though!)
Jonathan
Re: [PATCH v11 2/2] Documentation: Add document for UltraSoc SMB drivers
Hi Jonathan,
Quoted 18 lines · Jonathan Cameron
Quoted 15 lines · On Mon, 7 Nov 2022 21:06:24 +0800 Junhao He <[email protected]> wrote:
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.
Signed-off-by Qi Liu <[email protected]>Signed-off-by Junhao He <[email protected]>--- .../sysfs-bus-coresight-devices-ultra_smb | 31 +++++++ .../trace/coresight/ultrasoc-smb.rst | 80 +++++++++++++++++++ 2 files changed, 111 insertions(+)create mode 100644
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smbcreate mode 100644Documentation/trace/coresight/ultrasoc-smb.rst
Quoted 11 lines
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb line 3
Quoted 9 lines
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb new file +3
-0@@ -0,0 +1,31 @@ +What: /sys/bus/coresight/devices/ultra_smb<N>/enable_sink +Date: October 2022 +KernelVersion: 6.1Update to 6.2 as this will hopefully go in next merge window and it makes life easier for the maintainer if they don't need to fix all these up.
Ok, i will fix in next version.
Thanks.
Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb line 6
Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb new file +3
-0+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.Rest looks good to me, (not an expert on this stuff though!)
Jonathan
.
Best regards,
Junhao.