Skip to contentSkip to conversation

Virtual bus implementation and SOF multi-client support

PATCH New Ranjani Sridharan 2 participants 16 messages May 28, 2020 – May 31, 2020

Subsystems (5)
Documentation Sound Kbuild ASoC +1 more subsystems
lore
Share & tools
lore
#0 lore raw

cover Virtual bus implementation and SOF multi-client support

This set of patches introduces the virtual bus implementation along with the example usage in the Sound Open Firmware(SOF) audio driver.

The primary purpose of the virtual bus is meant to be a minimalist software-based bus used for connecting virtual devices to be able to communicate with each other.

The SOF driver adopts the virtual bus for implementing the multi-client support. A client in the context of the SOF driver is a device that needs to communicate with the DSP via IPCs. With multi-client support, the sound card can be separated into multiple orthogonal virtual devices for local device (mic/speakers etc), HDMI, sensing, probes, debug etc. In this series, we demonstrate the usage of the virtual bus with the help of the IPC test client which is used for testing the serialization of IPCs when multiple clients talk to the DSP at the same time.

This version includes a series of incremental changes in virtual-bus based of Andy and Pierre's comments. These should be squashed with the first commit.

Dave Ertman (1):
Implementation of Virtual Bus

Ranjani Sridharan (13):
virtual-bus: rename struct virtbus_dev_id
virtual-bus: reword Kconfig help
virtual-bus: add comment for virtbus entry
virtual-bus: move MODULE macros to the end of the file
virtual-bus: remove INVALID_ID and fix error path
virtual-bus: remove #ifdef for PM ops
virtual-bus: remove superfluous assignment
virtual-bus: fix return value for match function
virtual-bus: reorder header includes
virtual-bus: remove filename from header
ASoC: SOF: Introduce descriptors for SOF client
ASoC: SOF: Create client driver for IPC test
ASoC: SOF: ops: Add new op for client registration

 Documentation/driver-api/index.rst       |   1 +
 Documentation/driver-api/virtual_bus.rst |  93 ++++++
 drivers/bus/Kconfig                      |  11 +
 drivers/bus/Makefile                     |   2 +
 drivers/bus/virtual_bus.c                | 209 ++++++++++++++
 include/linux/mod_devicetable.h          |   8 +
 include/linux/virtual_bus.h              |  62 ++++
 scripts/mod/devicetable-offsets.c        |   3 +
 scripts/mod/file2alias.c                 |   8 +
 sound/soc/sof/Kconfig                    |  29 ++
 sound/soc/sof/Makefile                   |   7 +-
 sound/soc/sof/core.c                     |  10 +
 sound/soc/sof/intel/Kconfig              |   1 +
 sound/soc/sof/intel/apl.c                |  19 ++
 sound/soc/sof/intel/bdw.c                |  19 ++
 sound/soc/sof/intel/byt.c                |  22 ++
 sound/soc/sof/intel/cnl.c                |  19 ++
 sound/soc/sof/ops.h                      |  20 ++
 sound/soc/sof/sof-client.c               |  89 ++++++
 sound/soc/sof/sof-client.h               |  79 +++++
 sound/soc/sof/sof-ipc-test-client.c      | 348 +++++++++++++++++++++++
 sound/soc/sof/sof-priv.h                 |   9 +
 22 files changed, 1067 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/driver-api/virtual_bus.rst
 create mode 100644 drivers/bus/virtual_bus.c
 create mode 100644 include/linux/virtual_bus.h
 create mode 100644 sound/soc/sof/sof-client.c
 create mode 100644 sound/soc/sof/sof-client.h
 create mode 100644 sound/soc/sof/sof-ipc-test-client.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/14 Implementation of Virtual Bus

From: Dave Ertman <[email protected]>

This is the initial implementation of the Virtual Bus, virtbus_device and virtbus_driver. The virtual bus is a software based bus intended to support registering virtbus_devices and virtbus_drivers and provide matching between them and probing of the registered drivers.

The bus will support probe/remove shutdown and
suspend/resume callbacks.

---
 Documentation/driver-api/index.rst       |   1 +
 Documentation/driver-api/virtual_bus.rst |  93 ++++++++++
 drivers/bus/Kconfig                      |  10 ++
 drivers/bus/Makefile                     |   2 +
 drivers/bus/virtual_bus.c                | 215 +++++++++++++++++++++++
 include/linux/mod_devicetable.h          |   8 +
 include/linux/virtual_bus.h              |  62 +++++++
 scripts/mod/devicetable-offsets.c        |   3 +
 scripts/mod/file2alias.c                 |   7 +
 9 files changed, 401 insertions(+)
 create mode 100644 Documentation/driver-api/virtual_bus.rst
 create mode 100644 drivers/bus/virtual_bus.c
 create mode 100644 include/linux/virtual_bus.h
Documentation/driver-api/index.rst +1 -0
index d4e78cb3ef4d..4e628a6b8408 100644
@@ -101,6 +101,7 @@ available subsections can be seen below.
    sync_file
    vfio-mediated-device
    vfio
+   virtual_bus
    xilinx/index
    xillybus
    zorro
Documentation/driver-api/virtual_bus.rst new file +93 -0

93 lines not on this page · raw message

drivers/bus/Kconfig +10 -0
index 6d4e4497b59b..00553c78510c 100644
@@ -203,4 +203,14 @@ config DA8XX_MSTPRI
 source "drivers/bus/fsl-mc/Kconfig"
 source "drivers/bus/mhi/Kconfig"
 
+config VIRTUAL_BUS
+       tristate "Software based Virtual Bus"
+       help
+         Provides a software bus for virtbus_devices to be added to it
+         and virtbus_drivers to be registered on it.  It matches driver
+         and device based on id and calls the driver's probe routine.
+         One example is the irdma driver needing to connect with various
+         PCI LAN drivers to request resources (queues) to be able to perform
+         its function.
+
 endmenu
drivers/bus/Makefile +2 -0
index 05f32cd694a4..d30828a4768c 100644
@@ -37,3 +37,5 @@ obj-$(CONFIG_DA8XX_MSTPRI)	+= da8xx-mstpri.o
 
 # MHI
 obj-$(CONFIG_MHI_BUS)		+= mhi/
+
+obj-$(CONFIG_VIRTUAL_BUS)	+= virtual_bus.o
drivers/bus/virtual_bus.c new file +215 -0

215 lines not on this page · raw message

include/linux/mod_devicetable.h +8 -0
index 4c2ddd0941a7..60bcfe75fb94 100644
@@ -832,4 +832,12 @@ struct mhi_device_id {
 	kernel_ulong_t driver_data;
 };
 
+#define VIRTBUS_NAME_SIZE 20
+#define VIRTBUS_MODULE_PREFIX "virtbus:"
+
+struct virtbus_dev_id {
+	char name[VIRTBUS_NAME_SIZE];
+	kernel_ulong_t driver_data;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
include/linux/virtual_bus.h new file +62 -0

62 lines not on this page · raw message

scripts/mod/devicetable-offsets.c +3 -0
index 010be8ba2116..0c8e0e3a7c84 100644
@@ -241,5 +241,8 @@ int main(void)
 	DEVID(mhi_device_id);
 	DEVID_FIELD(mhi_device_id, chan);
 
+	DEVID(virtbus_dev_id);
+	DEVID_FIELD(virtbus_dev_id, name);
+
 	return 0;
 }
scripts/mod/file2alias.c +7 -0
index 02d5d79da284..7d78fa3fba34 100644
@@ -1358,7 +1358,13 @@ static int do_mhi_entry(const char *filename, void *symval, char *alias)
 {
 	DEF_FIELD_ADDR(symval, mhi_device_id, chan);
 	sprintf(alias, MHI_DEVICE_MODALIAS_FMT, *chan);
+	return 1;
+}
 
+static int do_virtbus_entry(const char *filename, void *symval, char *alias)
+{
+	DEF_FIELD_ADDR(symval, virtbus_dev_id, name);
+	sprintf(alias, VIRTBUS_MODULE_PREFIX "%s", *name);
 	return 1;
 }
 
@@ -1436,6 +1442,7 @@ static const struct devtable devtable[] = {
 	{"tee", SIZE_tee_client_device_id, do_tee_entry},
 	{"wmi", SIZE_wmi_device_id, do_wmi_entry},
 	{"mhi", SIZE_mhi_device_id, do_mhi_entry},
+	{"virtbus", SIZE_virtbus_dev_id, do_virtbus_entry},
 };
 
 /* Create MODULE_ALIAS() statements.
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/14 virtual-bus: rename struct virtbus_dev_id

In reply to Ranjani Sridharan

Rename struct virtbus_dev_id to struct virtbus_device_id. This is needed for auto loading of virtbus driver modules to work with MODULE_DEVICE_TABLE().

---
 drivers/bus/virtual_bus.c         | 7 ++++---
 include/linux/mod_devicetable.h   | 2 +-
 include/linux/virtual_bus.h       | 2 +-
 scripts/mod/devicetable-offsets.c | 4 ++--
 scripts/mod/file2alias.c          | 4 ++--
 5 files changed, 10 insertions(+), 9 deletions(-)
drivers/bus/virtual_bus.c +4 -3
index b70023d5b58a..90d2ad19b5cb 100644
@@ -27,8 +27,8 @@ static DEFINE_IDA(virtbus_dev_ida);
 #define VIRTBUS_INVALID_ID	0xFFFFFFFF
 
 static const
-struct virtbus_dev_id *virtbus_match_id(const struct virtbus_dev_id *id,
-					struct virtbus_device *vdev)
+struct virtbus_device_id *virtbus_match_id(const struct virtbus_device_id *id,
+					   struct virtbus_device *vdev)
 {
 	while (id->name[0]) {
 		if (!strcmp(vdev->match_name, id->name))
@@ -50,7 +50,8 @@ static int virtbus_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
 	struct virtbus_device *vdev = to_virtbus_dev(dev);
 
-	if (add_uevent_var(env, "MODALIAS=%s%s", "virtbus:", vdev->match_name))
+	if (add_uevent_var(env, "MODALIAS=%s%s", VIRTBUS_MODULE_PREFIX,
+			   vdev->match_name))
 		return -ENOMEM;
 
 	return 0;
include/linux/mod_devicetable.h +1 -1
index 60bcfe75fb94..1378bc165c07 100644
@@ -835,7 +835,7 @@ struct mhi_device_id {
 #define VIRTBUS_NAME_SIZE 20
 #define VIRTBUS_MODULE_PREFIX "virtbus:"
 
-struct virtbus_dev_id {
+struct virtbus_device_id {
 	char name[VIRTBUS_NAME_SIZE];
 	kernel_ulong_t driver_data;
 };
include/linux/virtual_bus.h +1 -1
index 4872fd5a9218..aeac7144b220 100644
@@ -26,7 +26,7 @@ struct virtbus_driver {
 	int (*suspend)(struct virtbus_device *, pm_message_t);
 	int (*resume)(struct virtbus_device *);
 	struct device_driver driver;
-	const struct virtbus_dev_id *id_table;
+	const struct virtbus_device_id *id_table;
 };
 
 static inline
scripts/mod/devicetable-offsets.c +2 -2
index 0c8e0e3a7c84..2848926ed223 100644
@@ -241,8 +241,8 @@ int main(void)
 	DEVID(mhi_device_id);
 	DEVID_FIELD(mhi_device_id, chan);
 
-	DEVID(virtbus_dev_id);
-	DEVID_FIELD(virtbus_dev_id, name);
+	DEVID(virtbus_device_id);
+	DEVID_FIELD(virtbus_device_id, name);
 
 	return 0;
 }
scripts/mod/file2alias.c +2 -2
index 7d78fa3fba34..fd3908ed922d 100644
@@ -1363,7 +1363,7 @@ static int do_mhi_entry(const char *filename, void *symval, char *alias)
 
 static int do_virtbus_entry(const char *filename, void *symval, char *alias)
 {
-	DEF_FIELD_ADDR(symval, virtbus_dev_id, name);
+	DEF_FIELD_ADDR(symval, virtbus_device_id, name);
 	sprintf(alias, VIRTBUS_MODULE_PREFIX "%s", *name);
 	return 1;
 }
@@ -1442,7 +1442,7 @@ static const struct devtable devtable[] = {
 	{"tee", SIZE_tee_client_device_id, do_tee_entry},
 	{"wmi", SIZE_wmi_device_id, do_wmi_entry},
 	{"mhi", SIZE_mhi_device_id, do_mhi_entry},
-	{"virtbus", SIZE_virtbus_dev_id, do_virtbus_entry},
+	{"virtbus", SIZE_virtbus_device_id, do_virtbus_entry},
 };
 
 /* Create MODULE_ALIAS() statements.
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/14 virtual-bus: reword Kconfig help

In reply to Ranjani Sridharan
---
 drivers/bus/Kconfig | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/bus/Kconfig +7 -6
index 00553c78510c..b3f59bdf5c51 100644
@@ -206,11 +206,12 @@ source "drivers/bus/mhi/Kconfig"
 config VIRTUAL_BUS
        tristate "Software based Virtual Bus"
        help
-         Provides a software bus for virtbus_devices to be added to it
-         and virtbus_drivers to be registered on it.  It matches driver
-         and device based on id and calls the driver's probe routine.
-         One example is the irdma driver needing to connect with various
-         PCI LAN drivers to request resources (queues) to be able to perform
-         its function.
+         Provides a software bus for virtual bus drivers to register and
+	 attach virtual bus devices.  It matches driver and device based on a
+	 unique string and calls the driver's probe routine. One example is
+	 SOF (Sound Open Firmware) clients such as audio cards or test
+	 tools needing to connect with the SOF core. Another example is
+	 the irdma driver needing to connect with various PCI LAN drivers
+	 to request resources (queues) to be able to perform its function.
 
 endmenu
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/14 virtual-bus: add comment for virtbus entry

In reply to Ranjani Sridharan
---
 scripts/mod/file2alias.c | 1 +
 1 file changed, 1 insertion(+)
scripts/mod/file2alias.c +1 -0
index fd3908ed922d..929fc152e404 100644
@@ -1361,6 +1361,7 @@ static int do_mhi_entry(const char *filename, void *symval, char *alias)
 	return 1;
 }
 
+/* Looks like: virtbus:S */
 static int do_virtbus_entry(const char *filename, void *symval, char *alias)
 {
 	DEF_FIELD_ADDR(symval, virtbus_device_id, name);
Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/14 virtual-bus: move MODULE macros to the end of the file

In reply to Ranjani Sridharan
---
 drivers/bus/virtual_bus.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/bus/virtual_bus.c +5 -5
index 90d2ad19b5cb..25f85672b70d 100644
@@ -18,11 +18,6 @@
 #include <linux/acpi.h>
 #include <linux/device.h>
 
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("Virtual Bus");
-MODULE_AUTHOR("David Ertman <[email protected]>");
-MODULE_AUTHOR("Kiran Patil <[email protected]>");
-
 static DEFINE_IDA(virtbus_dev_ida);
 #define VIRTBUS_INVALID_ID	0xFFFFFFFF
 
@@ -214,3 +209,8 @@ static void __exit virtual_bus_exit(void)
 
 module_init(virtual_bus_init);
 module_exit(virtual_bus_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Virtual Bus");
+MODULE_AUTHOR("David Ertman <[email protected]>");
+MODULE_AUTHOR("Kiran Patil <[email protected]>");
Signature · 1 line
2.17.1
#6 lore raw

PATCH 6/14 virtual-bus: remove INVALID_ID and fix error path

In reply to Ranjani Sridharan

INVALID_ID is not really needed, so remove it and fix error path to remove auto ID in case of errors.

---
 drivers/bus/virtual_bus.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/bus/virtual_bus.c +4 -9
index 25f85672b70d..7518c6c8eaea 100644
@@ -19,7 +19,6 @@
 #include <linux/device.h>
 
 static DEFINE_IDA(virtbus_dev_ida);
-#define VIRTBUS_INVALID_ID	0xFFFFFFFF
 
 static const
 struct virtbus_device_id *virtbus_match_id(const struct virtbus_device_id *id,
@@ -77,8 +76,7 @@ static void virtbus_release_device(struct device *_dev)
 	u32 ida = vdev->id;
 
 	vdev->release(vdev);
-	if (ida != VIRTBUS_INVALID_ID)
-		ida_simple_remove(&virtbus_dev_ida, ida);
+	ida_simple_remove(&virtbus_dev_ida, ida);
 }
 
 /**
@@ -103,9 +101,7 @@ int virtbus_register_device(struct virtbus_device *vdev)
 
 	/* All device IDs are automatically allocated */
 	ret = ida_simple_get(&virtbus_dev_ida, 0, 0, GFP_KERNEL);
-
 	if (ret < 0) {
-		vdev->id = VIRTBUS_INVALID_ID;
 		dev_err(&vdev->dev, "get IDA idx for virtbus device failed!\n");
 		goto device_add_err;
 	}
@@ -122,13 +118,12 @@ int virtbus_register_device(struct virtbus_device *vdev)
 		dev_name(&vdev->dev));
 
 	ret = device_add(&vdev->dev);
-	if (ret)
-		goto device_add_err;
+	if (!ret)
+		return ret;
 
-	return 0;
+	dev_err(&vdev->dev, "Add device to virtbus failed!: %d\n", ret);
 
 device_add_err:
-	dev_err(&vdev->dev, "Add device to virtbus failed!: %d\n", ret);
 	put_device(&vdev->dev);
 
 	return ret;
Signature · 1 line
2.17.1
#7 lore raw

PATCH 7/14 virtual-bus: remove #ifdef for PM ops

In reply to Ranjani Sridharan

not really needed.

---
 drivers/bus/virtual_bus.c | 2 --
 1 file changed, 2 deletions(-)
drivers/bus/virtual_bus.c +0 -2
index 7518c6c8eaea..519b578a347f 100644
@@ -54,9 +54,7 @@ static int virtbus_uevent(struct device *dev, struct kobj_uevent_env *env)
 static const struct dev_pm_ops virtbus_dev_pm_ops = {
 	SET_RUNTIME_PM_OPS(pm_generic_runtime_suspend,
 			   pm_generic_runtime_resume, NULL)
-#ifdef CONFIG_PM_SLEEP
 	SET_SYSTEM_SLEEP_PM_OPS(pm_generic_suspend, pm_generic_resume)
-#endif
 };
 
 struct bus_type virtual_bus_type = {
Signature · 1 line
2.17.1
#8 lore raw

PATCH 8/14 virtual-bus: remove superfluous assignment

In reply to Ranjani Sridharan
---
 drivers/bus/virtual_bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/virtual_bus.c +1 -1
index 519b578a347f..2b0007932517 100644
@@ -153,7 +153,7 @@ static int virtbus_remove_driver(struct device *_dev)
 {
 	struct virtbus_driver *vdrv = to_virtbus_drv(_dev->driver);
 	struct virtbus_device *vdev = to_virtbus_dev(_dev);
-	int ret = 0;
+	int ret;
 
 	ret = vdrv->remove(vdev);
 	dev_pm_domain_detach(_dev, true);
Signature · 1 line
2.17.1
#9 lore raw

PATCH 9/14 virtual-bus: fix return value for match function

In reply to Ranjani Sridharan
---
 drivers/bus/virtual_bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/virtual_bus.c +1 -1
index 2b0007932517..27db2d3463a3 100644
@@ -37,7 +37,7 @@ static int virtbus_match(struct device *dev, struct device_driver *drv)
 	struct virtbus_driver *vdrv = to_virtbus_drv(drv);
 	struct virtbus_device *vdev = to_virtbus_dev(dev);
 
-	return virtbus_match_id(vdrv->id_table, vdev) != NULL;
+	return !!virtbus_match_id(vdrv->id_table, vdev);
 }
 
 static int virtbus_uevent(struct device *dev, struct kobj_uevent_env *env)
Signature · 1 line
2.17.1
#10 lore raw

PATCH 10/14 virtual-bus: reorder header includes

In reply to Ranjani Sridharan
---
 drivers/bus/virtual_bus.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/bus/virtual_bus.c +7 -7
index 27db2d3463a3..613445640cd0 100644
@@ -8,15 +8,15 @@
  * more information
  */
 
-#include <linux/string.h>
-#include <linux/virtual_bus.h>
-#include <linux/of_irq.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/pm_runtime.h>
-#include <linux/pm_domain.h>
 #include <linux/acpi.h>
 #include <linux/device.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/of_irq.h>
+#include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
+#include <linux/string.h>
+#include <linux/virtual_bus.h>
 
 static DEFINE_IDA(virtbus_dev_ida);
 
Signature · 1 line
2.17.1
#11 lore raw

PATCH 11/14 virtual-bus: remove filename from header

In reply to Ranjani Sridharan
---
 drivers/bus/virtual_bus.c   | 2 +-
 include/linux/virtual_bus.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/bus/virtual_bus.c +1 -1
index 613445640cd0..64d7e588fe7d 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * virtual_bus.c - lightweight software based bus for virtual devices
+ * Lightweight software based bus for virtual devices
  *
  * Copyright (c) 2019-2020 Intel Corporation
  *
include/linux/virtual_bus.h +1 -1
index aeac7144b220..a34e060ded56 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * virtual_bus.h - lightweight software bus
+ * Lightweight software bus
  *
  * Copyright (c) 2019-2020 Intel Corporation
  *
Signature · 1 line
2.17.1
#12 lore raw

PATCH 12/14 ASoC: SOF: Introduce descriptors for SOF client

In reply to Ranjani Sridharan

A client in the SOF (Sound Open Firmware) context is a device that needs to communicate with the DSP via IPC messages. The SOF core is responsible for serializing the IPC messages to the DSP from the different clients. One example of an SOF client would be an IPC test client that floods the DSP with test IPC messages to validate if the serialization works as expected. Multi-client support will also add the ability to split the existing audio cards into multiple ones, so as to e.g. to deal with HDMI with a dedicated client instead of adding HDMI to all cards.

This patch introduces descriptors for SOF client driver and SOF client device along with APIs for registering and unregistering a SOF client driver, sending IPCs from a client device and accessing the SOF core debugfs root entry.

Along with this, add a couple of new members to struct snd_sof_dev that will be used for maintaining the list of clients.

---
 sound/soc/sof/Kconfig      | 19 ++++++++
 sound/soc/sof/Makefile     |  1 +
 sound/soc/sof/core.c       |  2 +
 sound/soc/sof/sof-client.c | 89 ++++++++++++++++++++++++++++++++++++++
 sound/soc/sof/sof-client.h | 79 +++++++++++++++++++++++++++++++++
 sound/soc/sof/sof-priv.h   |  6 +++
 6 files changed, 196 insertions(+)
 create mode 100644 sound/soc/sof/sof-client.c
 create mode 100644 sound/soc/sof/sof-client.h
sound/soc/sof/Kconfig +19 -0
index 4dda4b62509f..664af8cbacea 100644
@@ -50,6 +50,24 @@ config SND_SOC_SOF_DEBUG_PROBES
 	  Say Y if you want to enable probes.
 	  If unsure, select "N".
 
+config SND_SOC_SOF_CLIENT
+	tristate
+	select VIRTUAL_BUS
+	help
+	  This option is not user-selectable but automagically handled by
+	  'select' statements at a higher level
+
+config SND_SOC_SOF_CLIENT_SUPPORT
+	bool "SOF enable clients"
+	depends on SND_SOC_SOF
+	help
+	  This adds support for virtual client devices to separate out the debug
+	  functionality for IPC tests, probes etc. into separate devices. This
+	  option would also allow adding client devices based on DSP FW
+	  capabilities and ACPI/OF device information.
+	  Say Y if you want to enable clients with SOF.
+	  If unsure select "N".
+
 config SND_SOC_SOF_DEVELOPER_SUPPORT
 	bool "SOF developer options support"
 	depends on EXPERT
@@ -186,6 +204,7 @@ endif ## SND_SOC_SOF_DEVELOPER_SUPPORT
 
 config SND_SOC_SOF
 	tristate
+	select SND_SOC_SOF_CLIENT if SND_SOC_SOF_CLIENT_SUPPORT
 	select SND_SOC_TOPOLOGY
 	select SND_SOC_SOF_NOCODEC if SND_SOC_SOF_NOCODEC_SUPPORT
 	help
sound/soc/sof/Makefile +1 -0
index 05718dfe6cd2..35d6803caf38 100644
@@ -2,6 +2,7 @@
 
 snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
 		control.o trace.o utils.o sof-audio.o
+snd-sof-$(CONFIG_SND_SOC_SOF_CLIENT) := sof-client.o
 snd-sof-$(CONFIG_SND_SOC_SOF_DEBUG_PROBES) += probe.o compress.o
 
 snd-sof-pci-objs := sof-pci-dev.o
sound/soc/sof/core.c +2 -0
index 339c4930b0c0..3a7ea7be70fa 100644
@@ -314,8 +314,10 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
 	INIT_LIST_HEAD(&sdev->widget_list);
 	INIT_LIST_HEAD(&sdev->dai_list);
 	INIT_LIST_HEAD(&sdev->route_list);
+	INIT_LIST_HEAD(&sdev->client_list);
 	spin_lock_init(&sdev->ipc_lock);
 	spin_lock_init(&sdev->hw_lock);
+	mutex_init(&sdev->client_mutex);
 
 	if (IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE))
 		INIT_WORK(&sdev->probe_work, sof_probe_work);
sound/soc/sof/sof-client.c new file +89 -0

89 lines not on this page · raw message

sound/soc/sof/sof-client.h new file +79 -0

79 lines not on this page · raw message

sound/soc/sof/sof-priv.h +6 -0
index 9bee2aab750d..2233370a0339 100644
@@ -441,6 +441,12 @@ struct snd_sof_dev {
 
 	bool msi_enabled;
 
+	/* list of client devices */
+	struct list_head client_list;
+
+	/* mutex to protect client list */
+	struct mutex client_mutex;
+
 	void *private;			/* core does not touch this */
 };
 
Signature · 1 line
2.17.1
#13 lore raw

PATCH 13/14 ASoC: SOF: Create client driver for IPC test

In reply to Ranjani Sridharan

Create an SOF client driver for IPC flood test. This driver is used to set up the debugfs entries and the read/write ops for initiating the IPC flood test that would be used to measure the min/max/avg response times for sending IPCs to the DSP.

---
 sound/soc/sof/Kconfig               |  10 +
 sound/soc/sof/Makefile              |   6 +-
 sound/soc/sof/sof-ipc-test-client.c | 348 ++++++++++++++++++++++++++++
 3 files changed, 363 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/sof/sof-ipc-test-client.c
sound/soc/sof/Kconfig +10 -0
index 664af8cbacea..9cc76951cfc6 100644
@@ -190,6 +190,16 @@ config SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST
 	  Say Y if you want to enable IPC flood test.
 	  If unsure, select "N".
 
+config SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT
+	tristate "SOF enable IPC flood test client"
+	depends on SND_SOC_SOF_CLIENT
+	help
+	  This option enables a separate client device for IPC flood test
+	  which can be used to flood the DSP with test IPCs and gather stats
+	  about response times.
+	  Say Y if you want to enable IPC flood test.
+	  If unsure, select "N".
+
 config SND_SOC_SOF_DEBUG_RETAIN_DSP_CONTEXT
 	bool "SOF retain DSP context on any FW exceptions"
 	help
sound/soc/sof/Makefile +5 -1
index 35d6803caf38..bff97ff421b1 100644
@@ -9,16 +9,20 @@ snd-sof-pci-objs := sof-pci-dev.o
 snd-sof-acpi-objs := sof-acpi-dev.o
 snd-sof-of-objs := sof-of-dev.o
 
+snd-sof-ipc-test-objs := sof-ipc-test-client.o
+
 snd-sof-nocodec-objs := nocodec.o
 
+
 obj-$(CONFIG_SND_SOC_SOF) += snd-sof.o
 obj-$(CONFIG_SND_SOC_SOF_NOCODEC) += snd-sof-nocodec.o
 
-
 obj-$(CONFIG_SND_SOC_SOF_ACPI) += snd-sof-acpi.o
 obj-$(CONFIG_SND_SOC_SOF_OF) += snd-sof-of.o
 obj-$(CONFIG_SND_SOC_SOF_PCI) += snd-sof-pci.o
 
+obj-$(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT) += snd-sof-ipc-test.o
+
 obj-$(CONFIG_SND_SOC_SOF_INTEL_TOPLEVEL) += intel/
 obj-$(CONFIG_SND_SOC_SOF_IMX_TOPLEVEL) += imx/
 obj-$(CONFIG_SND_SOC_SOF_XTENSA) += xtensa/
sound/soc/sof/sof-ipc-test-client.c new file +348 -0

348 lines not on this page · raw message

Signature · 1 line
2.17.1
#14 lore raw

PATCH 14/14 ASoC: SOF: ops: Add new op for client registration

In reply to Ranjani Sridharan

Add a new op for registering clients. The clients to be registered depend on the DSP capabilities and the ACPI/DT information. For now, we only add 2 IPC test clients that will be used for run tandem IPC flood tests for all Intel platforms.

For ACPI platforms, change the Kconfig to select SND_SOC_SOF_PROBE_WORK_QUEUE to allow the virtbus driver to probe when the client is registered.

---
 sound/soc/sof/core.c        |  8 ++++++++
 sound/soc/sof/intel/Kconfig |  1 +
 sound/soc/sof/intel/apl.c   | 19 +++++++++++++++++++
 sound/soc/sof/intel/bdw.c   | 19 +++++++++++++++++++
 sound/soc/sof/intel/byt.c   | 22 ++++++++++++++++++++++
 sound/soc/sof/intel/cnl.c   | 19 +++++++++++++++++++
 sound/soc/sof/ops.h         | 20 ++++++++++++++++++++
 sound/soc/sof/sof-priv.h    |  3 +++
 8 files changed, 111 insertions(+)
sound/soc/sof/core.c +8 -0
index 3a7ea7be70fa..ce7d87c8f34c 100644
@@ -246,6 +246,12 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
 	if (plat_data->sof_probe_complete)
 		plat_data->sof_probe_complete(sdev->dev);
 
+	/*
+	 * Register client devices. This can fail but errors cannot be
+	 * propagated.
+	 */
+	snd_sof_register_clients(sdev);
+
 	return 0;
 
 fw_trace_err:
@@ -356,6 +362,7 @@ int snd_sof_device_remove(struct device *dev)
 		cancel_work_sync(&sdev->probe_work);
 
 	if (sdev->fw_state > SOF_FW_BOOT_NOT_STARTED) {
+		snd_sof_unregister_clients(sdev);
 		snd_sof_fw_unload(sdev);
 		snd_sof_ipc_free(sdev);
 		snd_sof_free_debug(sdev);
@@ -389,4 +396,5 @@ EXPORT_SYMBOL(snd_sof_device_remove);
 MODULE_AUTHOR("Liam Girdwood");
 MODULE_DESCRIPTION("Sound Open Firmware (SOF) Core");
 MODULE_LICENSE("Dual BSD/GPL");
+MODULE_IMPORT_NS(SND_SOC_SOF_CLIENT);
 MODULE_ALIAS("platform:sof-audio");
sound/soc/sof/intel/Kconfig +1 -0
index 9b3c01072dd8..46e3a17b9bc6 100644
@@ -13,6 +13,7 @@ config SND_SOC_SOF_INTEL_ACPI
 	def_tristate SND_SOC_SOF_ACPI
 	select SND_SOC_SOF_BAYTRAIL  if SND_SOC_SOF_BAYTRAIL_SUPPORT
 	select SND_SOC_SOF_BROADWELL if SND_SOC_SOF_BROADWELL_SUPPORT
+	select SND_SOC_SOF_PROBE_WORK_QUEUE if SND_SOC_SOF_CLIENT
 	help
 	  This option is not user-selectable but automagically handled by
 	  'select' statements at a higher level
sound/soc/sof/intel/apl.c +19 -0
index 9e29d4fd393a..d6f42794f0b7 100644
@@ -18,6 +18,7 @@
 #include "../sof-priv.h"
 #include "hda.h"
 #include "../sof-audio.h"
+#include "../sof-client.h"
 
 static const struct snd_sof_debugfs_map apl_dsp_debugfs[] = {
 	{"hda", HDA_DSP_HDA_BAR, 0, 0x4000, SOF_DEBUGFS_ACCESS_ALWAYS},
@@ -25,6 +26,20 @@ static const struct snd_sof_debugfs_map apl_dsp_debugfs[] = {
 	{"dsp", HDA_DSP_BAR,  0, 0x10000, SOF_DEBUGFS_ACCESS_ALWAYS},
 };
 
+static void apl_register_clients(struct snd_sof_dev *sdev)
+{
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT)
+	/*
+	 * Register 2 IPC clients to facilitate tandem flood test.
+	 * The device name below is appended with the device ID assigned
+	 * automatically when the virtbus device is registered making
+	 * them unique.
+	 */
+	sof_client_dev_register(sdev, "sof-ipc-test");
+	sof_client_dev_register(sdev, "sof-ipc-test");
+#endif
+}
+
 /* apollolake ops */
 const struct snd_sof_dsp_ops sof_apl_ops = {
 	/* probe and remove */
@@ -101,6 +116,9 @@ const struct snd_sof_dsp_ops sof_apl_ops = {
 	.trace_release = hda_dsp_trace_release,
 	.trace_trigger = hda_dsp_trace_trigger,
 
+	/* client register */
+	.register_clients = apl_register_clients,
+
 	/* DAI drivers */
 	.drv		= skl_dai,
 	.num_drv	= SOF_SKL_NUM_DAIS,
@@ -140,3 +158,4 @@ const struct sof_intel_dsp_desc apl_chip_info = {
 	.ssp_base_offset = APL_SSP_BASE_OFFSET,
 };
 EXPORT_SYMBOL_NS(apl_chip_info, SND_SOC_SOF_INTEL_HDA_COMMON);
+MODULE_IMPORT_NS(SND_SOC_SOF_CLIENT);
sound/soc/sof/intel/bdw.c +19 -0
index 99fd0bd7276e..1909c93fecba 100644
@@ -18,6 +18,7 @@
 #include "../ops.h"
 #include "shim.h"
 #include "../sof-audio.h"
+#include "../sof-client.h"
 
 /* BARs */
 #define BDW_DSP_BAR 0
@@ -563,6 +564,20 @@ static void bdw_set_mach_params(const struct snd_soc_acpi_mach *mach,
 	mach_params->platform = dev_name(dev);
 }
 
+static void bdw_register_clients(struct snd_sof_dev *sdev)
+{
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT)
+	/*
+	 * Register 2 IPC clients to facilitate tandem flood test.
+	 * The device name below is appended with the device ID assigned
+	 * automatically when the virtbus device is registered making
+	 * them unique.
+	 */
+	sof_client_dev_register(sdev, "sof-ipc-test");
+	sof_client_dev_register(sdev, "sof-ipc-test");
+#endif
+}
+
 /* Broadwell DAIs */
 static struct snd_soc_dai_driver bdw_dai[] = {
 {
@@ -638,6 +653,9 @@ const struct snd_sof_dsp_ops sof_bdw_ops = {
 	/*Firmware loading */
 	.load_firmware	= snd_sof_load_firmware_memcpy,
 
+	/* client register */
+	.register_clients = bdw_register_clients,
+
 	/* DAI drivers */
 	.drv = bdw_dai,
 	.num_drv = ARRAY_SIZE(bdw_dai),
@@ -662,3 +680,4 @@ EXPORT_SYMBOL_NS(bdw_chip_info, SND_SOC_SOF_BROADWELL);
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_HIFI_EP_IPC);
 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
+MODULE_IMPORT_NS(SND_SOC_SOF_CLIENT);
sound/soc/sof/intel/byt.c +22 -0
index e6ba8382b1de..e70fd96f3045 100644
@@ -19,6 +19,7 @@
 #include "shim.h"
 #include "../sof-audio.h"
 #include "../../intel/common/soc-intel-quirks.h"
+#include "../sof-client.h"
 
 /* DSP memories */
 #define IRAM_OFFSET		0x0C0000
@@ -821,6 +822,20 @@ static int byt_acpi_probe(struct snd_sof_dev *sdev)
 	return ret;
 }
 
+static void byt_register_clients(struct snd_sof_dev *sdev)
+{
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT)
+	/*
+	 * Register 2 IPC clients to facilitate tandem flood test.
+	 * The device name below is appended with the device ID assigned
+	 * automatically when the virtbus device is registered making
+	 * them unique.
+	 */
+	sof_client_dev_register(sdev, "sof-ipc-test");
+	sof_client_dev_register(sdev, "sof-ipc-test");
+#endif
+}
+
 /* baytrail ops */
 const struct snd_sof_dsp_ops sof_byt_ops = {
 	/* device init */
@@ -879,6 +894,9 @@ const struct snd_sof_dsp_ops sof_byt_ops = {
 	.suspend = byt_suspend,
 	.resume = byt_resume,
 
+	/* client register */
+	.register_clients = byt_register_clients,
+
 	/* DAI drivers */
 	.drv = byt_dai,
 	.num_drv = 3, /* we have only 3 SSPs on byt*/
@@ -958,6 +976,9 @@ const struct snd_sof_dsp_ops sof_cht_ops = {
 	.suspend = byt_suspend,
 	.resume = byt_resume,
 
+	/* client register */
+	.register_clients = byt_register_clients,
+
 	/* DAI drivers */
 	.drv = byt_dai,
 	/* all 6 SSPs may be available for cherrytrail */
@@ -985,3 +1006,4 @@ EXPORT_SYMBOL_NS(cht_chip_info, SND_SOC_SOF_BAYTRAIL);
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_HIFI_EP_IPC);
 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
+MODULE_IMPORT_NS(SND_SOC_SOF_CLIENT);
sound/soc/sof/intel/cnl.c +19 -0
index 16db0f50d139..322764b6f9b4 100644
@@ -19,6 +19,7 @@
 #include "hda.h"
 #include "hda-ipc.h"
 #include "../sof-audio.h"
+#include "../sof-client.h"
 
 static const struct snd_sof_debugfs_map cnl_dsp_debugfs[] = {
 	{"hda", HDA_DSP_HDA_BAR, 0, 0x4000, SOF_DEBUGFS_ACCESS_ALWAYS},
@@ -231,6 +232,20 @@ static void cnl_ipc_dump(struct snd_sof_dev *sdev)
 		hipcida, hipctdr, hipcctl);
 }
 
+static void cnl_register_clients(struct snd_sof_dev *sdev)
+{
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST_CLIENT)
+	/*
+	 * Register 2 IPC clients to facilitate tandem flood test.
+	 * The device name below is appended with the device ID assigned
+	 * automatically when the virtbus device is registered making
+	 * them unique.
+	 */
+	sof_client_dev_register(sdev, "sof-ipc-test");
+	sof_client_dev_register(sdev, "sof-ipc-test");
+#endif
+}
+
 /* cannonlake ops */
 const struct snd_sof_dsp_ops sof_cnl_ops = {
 	/* probe and remove */
@@ -307,6 +322,9 @@ const struct snd_sof_dsp_ops sof_cnl_ops = {
 	.trace_release = hda_dsp_trace_release,
 	.trace_trigger = hda_dsp_trace_trigger,
 
+	/* client register */
+	.register_clients = cnl_register_clients,
+
 	/* DAI drivers */
 	.drv		= skl_dai,
 	.num_drv	= SOF_SKL_NUM_DAIS,
@@ -417,3 +435,4 @@ const struct sof_intel_dsp_desc jsl_chip_info = {
 	.ssp_base_offset = CNL_SSP_BASE_OFFSET,
 };
 EXPORT_SYMBOL_NS(jsl_chip_info, SND_SOC_SOF_INTEL_HDA_COMMON);
+MODULE_IMPORT_NS(SND_SOC_SOF_CLIENT);
sound/soc/sof/ops.h +20 -0
index b21632f5511a..6fa8b6736dce 100644
@@ -14,9 +14,12 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
 #include <linux/types.h>
 #include <sound/pcm.h>
 #include "sof-priv.h"
+#include "sof-client.h"
 
 #define sof_ops(sdev) \
 	((sdev)->pdata->desc->ops)
@@ -470,6 +473,23 @@ snd_sof_set_mach_params(const struct snd_soc_acpi_mach *mach,
 		sof_ops(sdev)->set_mach_params(mach, dev);
 }
 
+static inline void
+snd_sof_register_clients(struct snd_sof_dev *sdev)
+{
+	if (sof_ops(sdev) && sof_ops(sdev)->register_clients)
+		sof_ops(sdev)->register_clients(sdev);
+}
+
+static inline void
+snd_sof_unregister_clients(struct snd_sof_dev *sdev)
+{
+	struct sof_client_dev *cdev, *_cdev;
+
+	/* unregister client devices */
+	list_for_each_entry_safe(cdev, _cdev, &sdev->client_list, list)
+		sof_client_dev_unregister(cdev);
+}
+
 static inline const struct snd_sof_dsp_ops
 *sof_get_ops(const struct sof_dev_desc *d,
 	     const struct sof_ops_table mach_ops[], int asize)
sound/soc/sof/sof-priv.h +3 -0
index 2233370a0339..932eea7d441e 100644
@@ -252,6 +252,9 @@ struct snd_sof_dsp_ops {
 	void (*set_mach_params)(const struct snd_soc_acpi_mach *mach,
 				struct device *dev); /* optional */
 
+	/* client ops */
+	void (*register_clients)(struct snd_sof_dev *sdev); /* optional */
+
 	/* DAI ops */
 	struct snd_soc_dai_driver *drv;
 	int num_drv;
Signature · 1 line
2.17.1
#15 lore raw

Re: [Intel-wired-lan] [PATCH 14/14] ASoC: SOF: ops: Add new op for client registration

I love your patch! Yet something to improve:

Hi Ranjani,

I love your patch! Yet something to improve:

[auto build test ERROR on asoc/for-next]
[also build test ERROR on next-20200529]
[cannot apply to kbuild/for-next linus/master v5.7-rc7]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Ranjani-Sridharan/Virtual-bus-implementation-and-SOF-multi-client-support/20200531-012935
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: riscv-allmodconfig (attached as .config)
compiler: riscv64-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

sound/soc/sof/intel/apl.c:161:1: warning: data definition has no type or storage class 161 | MODULE_IMPORT_NS(SND_SOC_SOF_CLIENT);
| ^~~~~~~~~~~~~~~~

>> sound/soc/sof/intel/apl.c:161:1: error: type defaults to 'int' in declaration of 'MODULE_IMPORT_NS' [-Werror=implicit-int]

sound/soc/sof/intel/apl.c:161:1: warning: parameter names (without types) in function declaration
cc1: some warnings being treated as errors
--
sound/soc/sof/intel/cnl.c:438:1: warning: data definition has no type or storage class 438 | MODULE_IMPORT_NS(SND_SOC_SOF_CLIENT);
| ^~~~~~~~~~~~~~~~

>> sound/soc/sof/intel/cnl.c:438:1: error: type defaults to 'int' in declaration of 'MODULE_IMPORT_NS' [-Werror=implicit-int]

sound/soc/sof/intel/cnl.c:438:1: warning: parameter names (without types) in function declaration
cc1: some warnings being treated as errors

vim +161 sound/soc/sof/intel/apl.c

145
146 const struct sof_intel_dsp_desc apl_chip_info = {
147 /* Apollolake */
148 .cores_num = 2,
149 .init_core_mask = 1,
150 .cores_mask = HDA_DSP_CORE_MASK(0) | HDA_DSP_CORE_MASK(1),
151 .ipc_req = HDA_DSP_REG_HIPCI,
152 .ipc_req_mask = HDA_DSP_REG_HIPCI_BUSY,
153 .ipc_ack = HDA_DSP_REG_HIPCIE,
154 .ipc_ack_mask = HDA_DSP_REG_HIPCIE_DONE,
155 .ipc_ctl = HDA_DSP_REG_HIPCCTL,
156 .rom_init_timeout = 150,
157 .ssp_count = APL_SSP_COUNT,
158 .ssp_base_offset = APL_SSP_BASE_OFFSET,
159 };
160 EXPORT_SYMBOL_NS(apl_chip_info, SND_SOC_SOF_INTEL_HDA_COMMON);

 > 161	MODULE_IMPORT_NS(SND_SOC_SOF_CLIENT);

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org