Skip to contentSkip to conversation

add support for CDX bus

PATCH In review Nipun Gupta 3 participants 12 messages Mar 13, 2023 – Apr 28, 2023

Subsystems (4)
lore
Share & tools
lore

Nipun Gupta

author maintainer
#0 lore raw

v10 cover add support for CDX bus

Introduce AMD CDX bus, which provides a mechanism to discover/rescan CDX devices. The CDX devices are memory mapped on system bus for embedded CPUs.

CDX controller interacts with the firmware to query different CDX devices present in the Fabric and expose them to the Linux host on CDX bus.

This patch series:
- Introduces the CDX bus and CDX devices.
- Device tree binding for CDX controller
- Support for CDX bus in arm-smmu-v3 driver
- Add MCDI (Management CPU Driver Interface) as a protocol for communication with RPU Firmware
- Support RPMSg channel for Firmware communication

v9 patch series is at:
https://lore.kernel.org/lkml/[email protected]/

Changes v9 -> v10
- Update sysfs entries description to be more specific w.r.t. setting their values and the output type.
- Use kstrtobool() instead of kstrtoul() for sysfs processing of boolean sysfs entries.
- Update driver override to use pre-defined driver_set_override() API.
- Update the name of patch (PATCH 2/7 - iommu: Add iommu probe for CDX bus)

Changes v8 -> v9
- Update the name of patch (PATCH 2/7 - iommu: Support ops registration for CDX bus)
- update a log print and return variable names

Changes v7 -> v8
- Add ranges property in device tree bindings

Changes v6 -> v7
- Fix compilation for x86 environment in case CDX bus is enabled
- Fixed crash in reset if device is not bound to any device driver
- Update sysfs with typo and other minor changes
- Removed header file issue reported by make versioncheck

Changes v5 -> v6
- updated compatible name in the CDX dt-binding
- updated reset CDX device and removed redundant function
- moved from drivers/bus/cdx to drivers/cdx
- used xarray instead of controller list and ID
- updated sysfs documentation with more details

Changes RFC v4 -> v5
- Fixed device tree documentation
- Add MCDI as a protocol and RPMsg as transport for communication with RPU Firmware instead of using MCDI stubs.
- MSI patches for CDX are not added in this series as it's support is being revisited as per patch series:
https://lore.kernel.org/all/[email protected]/
It will be added as separate patches.

Changes RFC v3 -> RFC v4:
- Separate CDX bus and CDX controller driver (Greg K-H)
- Added MSI interfacing to Firmware for writing MSI message to firmware so it can be provided to the device.
- Fix MSI review comments - multiple cleanups (Mark Zynger)
- Fix the device tree yaml compilation (Rob Herring, Krzysztof)
- removed vfio-cdx from this series. It will be added after bus support is complete (Jason)

Changes RFC v2 -> RFC v3:
- Move CDX bus as a new bus type in kernel rather than using the platform devices (Greg K-H, Marc Zynger)
- Correspondingly update ARM SMMU v3
- Add support for vfio-cdx driver
- Updated device tree yaml with correct binding information (Krzysztof Kozlowski)
- remove 'compatible' sysfs platform patch which was required for CDX devices exposed as platform devices

Changes RFC v1 -> RFC v2:
- introduce CDX bus infrastructure
- fixed code for making compatible visible for devices having the 'compatible' property only (Greg K-H)
- moved CDX-MSI domain as part of CDX bus infrastructure. previously it was part of irqchip (Marc Zynger).
- fixed few prints (Greg K-H)
- support rescan and reset of CDX bus
- add VFIO reset module for CDX bus based devices

Nipun Gupta (7):
cdx: add the cdx bus driver
iommu: Add iommu probe for CDX bus
dt-bindings: bus: add CDX bus controller for versal net
cdx: add MCDI protocol interface for firmware interaction
cdx: add cdx controller
cdx: add rpmsg communication channel for CDX
cdx: add device attributes

 Documentation/ABI/testing/sysfs-bus-cdx       |  56 ++
 .../bindings/bus/xlnx,versal-net-cdx.yaml     |  82 ++
 MAINTAINERS                                   |   8 +
 drivers/Kconfig                               |   2 +
 drivers/Makefile                              |   1 +
 drivers/cdx/Kconfig                           |  19 +
 drivers/cdx/Makefile                          |   8 +
 drivers/cdx/cdx.c                             | 535 +++++++++++
 drivers/cdx/cdx.h                             |  62 ++
 drivers/cdx/controller/Kconfig                |  31 +
 drivers/cdx/controller/Makefile               |   9 +
 drivers/cdx/controller/bitfield.h             |  90 ++
 drivers/cdx/controller/cdx_controller.c       | 230 +++++
 drivers/cdx/controller/cdx_controller.h       |  30 +
 drivers/cdx/controller/cdx_rpmsg.c            | 202 ++++
 drivers/cdx/controller/mc_cdx_pcol.h          | 590 ++++++++++++
 drivers/cdx/controller/mcdi.c                 | 903 ++++++++++++++++++
 drivers/cdx/controller/mcdi.h                 | 248 +++++
 drivers/cdx/controller/mcdi_functions.c       | 139 +++
 drivers/cdx/controller/mcdi_functions.h       |  61 ++
 drivers/iommu/iommu.c                         |   4 +
 include/linux/cdx/cdx_bus.h                   | 174 ++++
 include/linux/mod_devicetable.h               |  15 +
 scripts/mod/devicetable-offsets.c             |   4 +
 scripts/mod/file2alias.c                      |  12 +
 25 files changed, 3515 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-cdx
 create mode 100644 Documentation/devicetree/bindings/bus/xlnx,versal-net-cdx.yaml
 create mode 100644 drivers/cdx/Kconfig
 create mode 100644 drivers/cdx/Makefile
 create mode 100644 drivers/cdx/cdx.c
 create mode 100644 drivers/cdx/cdx.h
 create mode 100644 drivers/cdx/controller/Kconfig
 create mode 100644 drivers/cdx/controller/Makefile
 create mode 100644 drivers/cdx/controller/bitfield.h
 create mode 100644 drivers/cdx/controller/cdx_controller.c
 create mode 100644 drivers/cdx/controller/cdx_controller.h
 create mode 100644 drivers/cdx/controller/cdx_rpmsg.c
 create mode 100644 drivers/cdx/controller/mc_cdx_pcol.h
 create mode 100644 drivers/cdx/controller/mcdi.c
 create mode 100644 drivers/cdx/controller/mcdi.h
 create mode 100644 drivers/cdx/controller/mcdi_functions.c
 create mode 100644 drivers/cdx/controller/mcdi_functions.h
 create mode 100644 include/linux/cdx/cdx_bus.h
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v10 1/7 cdx: add the cdx bus driver

Introduce AMD CDX bus, which provides a mechanism for scanning and probing CDX devices. These devices are memory mapped on system bus for Application Processors(APUs).

CDX devices can be changed dynamically in the Fabric and CDX bus interacts with CDX controller to rescan the bus and rediscover the devices.

---
 Documentation/ABI/testing/sysfs-bus-cdx |  12 +
 MAINTAINERS                             |   7 +
 drivers/Kconfig                         |   2 +
 drivers/Makefile                        |   1 +
 drivers/cdx/Kconfig                     |  17 +
 drivers/cdx/Makefile                    |   8 +
 drivers/cdx/cdx.c                       | 408 ++++++++++++++++++++++++
 drivers/cdx/cdx.h                       |  62 ++++
 include/linux/cdx/cdx_bus.h             | 147 +++++++++
 include/linux/mod_devicetable.h         |  15 +
 scripts/mod/devicetable-offsets.c       |   4 +
 scripts/mod/file2alias.c                |  12 +
 12 files changed, 695 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-cdx
 create mode 100644 drivers/cdx/Kconfig
 create mode 100644 drivers/cdx/Makefile
 create mode 100644 drivers/cdx/cdx.c
 create mode 100644 drivers/cdx/cdx.h
 create mode 100644 include/linux/cdx/cdx_bus.h
Documentation/ABI/testing/sysfs-bus-cdx new file +12 -0
new file mode 100644
index 000000000000..43b4e161f226
@@ -0,0 +1,12 @@
+What:		/sys/bus/cdx/rescan
+Date:		March 2023
+Contact:	[email protected]
+Description:
+		Writing y/1/on to this file will cause rescan of the bus
+		and devices on the CDX bus. Any new devices are scanned and
+		added to the list of Linux devices and any devices removed are
+		also deleted from Linux.
+
+		For example::
+
+		  # echo 1 > /sys/bus/cdx/rescan
MAINTAINERS +7 -0
index 2892858cb040..16b42c22902b 100644
@@ -964,6 +964,13 @@ Q:	https://patchwork.kernel.org/project/linux-rdma/list/
 F:	drivers/infiniband/hw/efa/
 F:	include/uapi/rdma/efa-abi.h
 
+AMD CDX BUS DRIVER
+M:	Nipun Gupta <[email protected]>
+M:	Nikhil Agarwal <[email protected]>
+S:	Maintained
+F:	drivers/cdx/*
+F:	include/linux/cdx/*
+
 AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER
 M:	Tom Lendacky <[email protected]>
 M:	John Allen <[email protected]>
drivers/Kconfig +2 -0
index 968bd0a6fd78..514ae6b24cb2 100644
@@ -241,4 +241,6 @@ source "drivers/peci/Kconfig"
 
 source "drivers/hte/Kconfig"
 
+source "drivers/cdx/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
index 20b118dca999..7241d80a7b29 100644
@@ -194,3 +194,4 @@ obj-$(CONFIG_MOST)		+= most/
 obj-$(CONFIG_PECI)		+= peci/
 obj-$(CONFIG_HTE)		+= hte/
 obj-$(CONFIG_DRM_ACCEL)		+= accel/
+obj-$(CONFIG_CDX_BUS)		+= cdx/
drivers/cdx/Kconfig new file +17 -0
new file mode 100644
index 000000000000..1aaee0ec5bd9
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# CDX bus configuration
+#
+# Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
+#
+
+config CDX_BUS
+	bool "CDX Bus driver"
+	depends on OF && ARM64
+	help
+	  Driver to enable Composable DMA Transfer(CDX) Bus. CDX bus
+	  exposes Fabric devices which uses composable DMA IP to the
+	  APU. CDX bus provides a mechanism for scanning and probing
+	  of CDX devices. CDX devices are memory mapped on system bus
+	  for embedded CPUs. CDX bus uses CDX controller and firmware
+	  to scan these CDX devices.
drivers/cdx/Makefile new file +8 -0
new file mode 100644
index 000000000000..c5feb11fc718
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for CDX
+#
+# Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
+#
+
+obj-$(CONFIG_CDX_BUS) += cdx.o
drivers/cdx/cdx.c new file +408 -0

408 lines not on this page · raw message

drivers/cdx/cdx.h new file +62 -0

62 lines not on this page · raw message

include/linux/cdx/cdx_bus.h new file +147 -0

147 lines not on this page · raw message

include/linux/mod_devicetable.h +15 -0
index 549590e9c644..23445b163c2a 100644
@@ -911,4 +911,19 @@ struct ishtp_device_id {
 	kernel_ulong_t driver_data;
 };
 
+/**
+ * struct cdx_device_id - CDX device identifier
+ * @vendor: Vendor ID
+ * @device: Device ID
+ * @override_only: Match only when dev->driver_override is this driver.
+ *
+ * Type of entries in the "device Id" table for CDX devices supported by
+ * a CDX device driver.
+ */
+struct cdx_device_id {
+	__u16 vendor;
+	__u16 device;
+	__u32 override_only;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
scripts/mod/devicetable-offsets.c +4 -0
index c0d3bcb99138..62dc988df84d 100644
@@ -262,5 +262,9 @@ int main(void)
 	DEVID(ishtp_device_id);
 	DEVID_FIELD(ishtp_device_id, guid);
 
+	DEVID(cdx_device_id);
+	DEVID_FIELD(cdx_device_id, vendor);
+	DEVID_FIELD(cdx_device_id, device);
+
 	return 0;
 }
scripts/mod/file2alias.c +12 -0
index 91c2e7ba5e52..28da34ba4359 100644
@@ -1452,6 +1452,17 @@ static int do_dfl_entry(const char *filename, void *symval, char *alias)
 	return 1;
 }
 
+/* Looks like: cdx:vNdN */
+static int do_cdx_entry(const char *filename, void *symval,
+			char *alias)
+{
+	DEF_FIELD(symval, cdx_device_id, vendor);
+	DEF_FIELD(symval, cdx_device_id, device);
+
+	sprintf(alias, "cdx:v%08Xd%08Xd", vendor, device);
+	return 1;
+}
+
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 {
@@ -1531,6 +1542,7 @@ static const struct devtable devtable[] = {
 	{"ssam", SIZE_ssam_device_id, do_ssam_entry},
 	{"dfl", SIZE_dfl_device_id, do_dfl_entry},
 	{"ishtp", SIZE_ishtp_device_id, do_ishtp_entry},
+	{"cdx", SIZE_cdx_device_id, do_cdx_entry},
 };
 
 /* Create MODULE_ALIAS() statements.
Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH v10 2/7 iommu: Add iommu probe for CDX bus

In reply to Nipun Gupta

Add CDX bus to iommu_buses so that IOMMU probe is called for it.

---
 drivers/iommu/iommu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/iommu.c +4 -0
index 10db680acaed..0025a631b8e1 100644
@@ -28,6 +28,7 @@
 #include <linux/fsl/mc.h>
 #include <linux/module.h>
 #include <linux/cc_platform.h>
+#include <linux/cdx/cdx_bus.h>
 #include <trace/events/iommu.h>
 #include <linux/sched/mm.h>
 #include <linux/msi.h>
@@ -129,6 +130,9 @@ static struct bus_type * const iommu_buses[] = {
 #ifdef CONFIG_TEGRA_HOST1X_CONTEXT_BUS
 	&host1x_context_device_bus_type,
 #endif
+#ifdef CONFIG_CDX_BUS
+	&cdx_bus_type,
+#endif
 };
 
 /*
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH v10 2/7] iommu: Add iommu probe for CDX bus

Quoted 24 lines · Nipun Gupta

Add CDX bus to iommu_buses so that IOMMU probe is called for it.

---
 drivers/iommu/iommu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/iommu.c +1 -0
index 10db680acaed..0025a631b8e1 100644
@@ -28,6 +28,7 @@
 #include <linux/fsl/mc.h>
 #include <linux/module.h>
 #include <linux/cc_platform.h>
+#include <linux/cdx/cdx_bus.h>
 #include <trace/events/iommu.h>
 #include <linux/sched/mm.h>
 #include <linux/msi.h>

drivers/iommu/iommu.c static struct bus_type * const iommu_buses[] = { · line 136

Quoted 7 lines
drivers/iommu/iommu.c +3 -0
@@ -129,6 +130,9 @@ static struct bus_type * const iommu_buses[] = {
 #ifdef CONFIG_TEGRA_HOST1X_CONTEXT_BUS
 	&host1x_context_device_bus_type,
 #endif
+#ifdef CONFIG_CDX_BUS
+	&cdx_bus_type,
+#endif
 };

Note, this prevents the ability for this struct bus_type from being moved into read-only memory in the future. But hopefully that will be fixed up eventually, you are in good company with some other busses here...

Other than that, this series looks good, I'll queue this up through my tree for now as I seem to collect new subsystems. Feel free to send future patches through me as well until you get tired of that and want to send stuff to Linus directly.

thanks,

greg k-h

author maintainer
#4 lore raw

RE: [PATCH v10 2/7] iommu: Add iommu probe for CDX bus

[AMD Official Use Only - General]

Quoted 64 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: Wednesday, March 29, 2023 3:56 PM
To: Gupta, Nipun <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Anand, Harpreet <[email protected]>; Agarwal, Nikhil <[email protected]>; Simek, Michal <[email protected]>; Jansen Van Vuuren, Pieter <[email protected]>; Cascon, Pablo <[email protected]>; git (AMD-Xilinx) <[email protected]>
Subject: Re: [PATCH v10 2/7] iommu: Add iommu probe for CDX bus

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 5 lines · Nipun Gupta

Add CDX bus to iommu_buses so that IOMMU probe is called for it.

Reviewed-by Pieter Jansen van Vuuren <pieter.jansen-van-

[email protected]>

Quoted 19 lines
---
 drivers/iommu/iommu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/iommu.c +1 -0
index 10db680acaed..0025a631b8e1 100644
@@ -28,6 +28,7 @@
 #include <linux/fsl/mc.h>
 #include <linux/module.h>
 #include <linux/cc_platform.h>
+#include <linux/cdx/cdx_bus.h>
 #include <trace/events/iommu.h>
 #include <linux/sched/mm.h>
 #include <linux/msi.h>

drivers/iommu/iommu.c static struct bus_type * const iommu_buses[] = { · line 136

Quoted 7 lines
drivers/iommu/iommu.c +3 -0
@@ -129,6 +130,9 @@ static struct bus_type * const iommu_buses[] = {
 #ifdef CONFIG_TEGRA_HOST1X_CONTEXT_BUS
      &host1x_context_device_bus_type,
 #endif
+#ifdef CONFIG_CDX_BUS
+     &cdx_bus_type,
+#endif
 };

Note, this prevents the ability for this struct bus_type from being moved into read-only memory in the future. But hopefully that will be fixed up eventually, you are in good company with some other busses here...

Quoted 4 lines

Other than that, this series looks good, I'll queue this up through my tree for now as I seem to collect new subsystems. Feel free to send future patches through me as well until you get tired of that and want to send stuff to Linus directly.

Thanks, Greg, for the review and helping get the series in : )

Regards,
Nipun

Quoted 4 lines

thanks,

greg k-h

author maintainer
#5 lore raw

PATCH v10 3/7 dt-bindings: bus: add CDX bus controller for versal net

In reply to Nipun Gupta

Add CDX bus controller device tree bindings for versal-net devices.

---
 .../bindings/bus/xlnx,versal-net-cdx.yaml     | 82 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 83 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/bus/xlnx,versal-net-cdx.yaml
Documentation/devicetree/bindings/bus/xlnx,versal-net-cdx.yaml new file +82 -0
new file mode 100644
index 000000000000..7f62ffbdc245
@@ -0,0 +1,82 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/bus/xlnx,versal-net-cdx.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AMD CDX bus controller
+
+description: |
+  CDX bus controller for AMD devices is implemented to dynamically
+  detect CDX bus and devices using the firmware.
+  The CDX bus manages multiple FPGA based hardware devices, which
+  can support network, crypto or any other specialized type of
+  devices. These FPGA based devices can be added/modified dynamically
+  on run-time.
+
+  All devices on the CDX bus will have a unique streamid (for IOMMU)
+  and a unique device ID (for MSI) corresponding to a requestor ID
+  (one to one associated with the device). The streamid and deviceid
+  are used to configure SMMU and GIC-ITS respectively.
+
+  iommu-map property is used to define the set of stream ids
+  corresponding to each device and the associated IOMMU.
+
+  The MSI writes are accompanied by sideband data (Device ID).
+  The msi-map property is used to associate the devices with the
+  device ID as well as the associated ITS controller.
+
+  rproc property (xlnx,rproc) is used to identify the remote processor
+  with which APU (Application Processor Unit) interacts to find out
+  the bus and device configuration.
+
+maintainers:
+  - Nipun Gupta <[email protected]>
+  - Nikhil Agarwal <[email protected]>
+
+properties:
+  compatible:
+    const: xlnx,versal-net-cdx
+
+  iommu-map: true
+
+  msi-map: true
+
+  xlnx,rproc:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to the remoteproc_r5 rproc node using which APU interacts
+      with remote processor.
+
+  ranges: true
+
+  "#address-cells":
+    enum: [1, 2]
+
+  "#size-cells":
+    enum: [1, 2]
+
+required:
+  - compatible
+  - iommu-map
+  - msi-map
+  - xlnx,rproc
+  - ranges
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    cdx {
+        compatible = "xlnx,versal-net-cdx";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        /* define map for RIDs 250-259 */
+        iommu-map = <250 &smmu 250 10>;
+        /* define msi map for RIDs 250-259 */
+        msi-map = <250 &its 250 10>;
+        xlnx,rproc = <&remoteproc_r5>;
+        ranges;
+    };
MAINTAINERS +1 -0
index 16b42c22902b..82b2c5534e1f 100644
@@ -968,6 +968,7 @@ AMD CDX BUS DRIVER
 M:	Nipun Gupta <[email protected]>
 M:	Nikhil Agarwal <[email protected]>
 S:	Maintained
+F:	Documentation/devicetree/bindings/bus/xlnx,versal-net-cdx.yaml
 F:	drivers/cdx/*
 F:	include/linux/cdx/*
 
Signature · 1 line
2.17.1
author maintainer
#6 lore raw

PATCH v10 4/7 cdx: add MCDI protocol interface for firmware interaction

In reply to Nipun Gupta

The MCDI (Management CPU Driver Interface) is used as a protocol to communicate with the RPU firmware. It has pre-defined set of messages for different message exchanges between APU and RPU.

---
 drivers/cdx/Kconfig                  |   2 +
 drivers/cdx/Makefile                 |   2 +-
 drivers/cdx/controller/Kconfig       |  20 +
 drivers/cdx/controller/Makefile      |   9 +
 drivers/cdx/controller/bitfield.h    |  90 +++
 drivers/cdx/controller/mc_cdx_pcol.h | 590 +++++++++++++++++
 drivers/cdx/controller/mcdi.c        | 903 +++++++++++++++++++++++++++
 drivers/cdx/controller/mcdi.h        | 238 +++++++
 8 files changed, 1853 insertions(+), 1 deletion(-)
 create mode 100644 drivers/cdx/controller/Kconfig
 create mode 100644 drivers/cdx/controller/Makefile
 create mode 100644 drivers/cdx/controller/bitfield.h
 create mode 100644 drivers/cdx/controller/mc_cdx_pcol.h
 create mode 100644 drivers/cdx/controller/mcdi.c
 create mode 100644 drivers/cdx/controller/mcdi.h
drivers/cdx/Kconfig +2 -0
index 1aaee0ec5bd9..a08958485e31 100644
@@ -15,3 +15,5 @@ config CDX_BUS
 	  of CDX devices. CDX devices are memory mapped on system bus
 	  for embedded CPUs. CDX bus uses CDX controller and firmware
 	  to scan these CDX devices.
+
+source "drivers/cdx/controller/Kconfig"
drivers/cdx/Makefile +1 -1
index c5feb11fc718..0324e4914f6e 100644
@@ -5,4 +5,4 @@
 # Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
 #
 
-obj-$(CONFIG_CDX_BUS) += cdx.o
+obj-$(CONFIG_CDX_BUS) += cdx.o controller/
drivers/cdx/controller/Kconfig new file +20 -0
new file mode 100644
index 000000000000..785c71063b2a
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# CDX controller configuration
+#
+# Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
+#
+
+if CDX_BUS
+
+config MCDI_LOGGING
+	bool "MCDI Logging for the CDX controller"
+	depends on CDX_CONTROLLER
+	help
+	  Enable MCDI Logging for
+	  the CDX Controller for debug
+	  purpose.
+
+	  If unsure, say N.
+
+endif
drivers/cdx/controller/Makefile new file +9 -0
new file mode 100644
index 000000000000..0ce200678eda
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for CDX controller drivers
+#
+# Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
+#
+
+obj-$(CONFIG_CDX_CONTROLLER) += cdx-controller.o
+cdx-controller-objs := mcdi.o
drivers/cdx/controller/bitfield.h new file +90 -0

90 lines not on this page · raw message

drivers/cdx/controller/mc_cdx_pcol.h new file +590 -0

590 lines not on this page · raw message

drivers/cdx/controller/mcdi.c new file +903 -0

903 lines not on this page · raw message

drivers/cdx/controller/mcdi.h new file +238 -0

238 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

Re: [PATCH v10 4/7] cdx: add MCDI protocol interface for firmware interaction

Hi Nipun,

Quoted 10 lines · Nipun Gupta

The MCDI (Management CPU Driver Interface) is used as a protocol to communicate with the RPU firmware. It has pre-defined set of messages for different message exchanges between APU and RPU.

Thanks for your patch, which is now commit eb96b740192b2a09 ("cdx:
add MCDI protocol interface for firmware interaction") upstream.

Quoted 13 lines
drivers/cdx/controller/Kconfig new file +10 -0
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# CDX controller configuration
+#
+# Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
+#
+
+if CDX_BUS
+
+config MCDI_LOGGING

drivers/cdx/controller/Kconfig line 20

Quoted 10 lines
drivers/cdx/controller/Kconfig new file +10 -0
+       bool "MCDI Logging for the CDX controller"
+       depends on CDX_CONTROLLER
+       help
+         Enable MCDI Logging for
+         the CDX Controller for debug
+         purpose.
+
+         If unsure, say N.
+
+endif

As there also exist config symbols SFC_MCDI_LOGGING and SFC_SIENA_MCDI_LOGGING, perhaps MCDI_LOGGING is too generic, and should be renamed to CDX_MCDI_LOGGING?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

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

author maintainer
#8 lore raw

RE: [PATCH v10 4/7] cdx: add MCDI protocol interface for firmware interaction

Quoted 64 lines

-----Original Message-----
From: linux-arm-kernel <[email protected]> On Behalf Of Geert Uytterhoeven
Sent: Friday, April 28, 2023 1:44 PM
To: Gupta, Nipun <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Anand, Harpreet <[email protected]>; Agarwal, Nikhil <[email protected]>; Simek, Michal <[email protected]>; Jansen Van Vuuren, Pieter <[email protected]>; Cascon, Pablo <[email protected]>; git (AMD-Xilinx) <[email protected]>
Subject: Re: [PATCH v10 4/7] cdx: add MCDI protocol interface for firmware interaction

Hi Nipun,

Quoted 10 lines · Nipun Gupta

The MCDI (Management CPU Driver Interface) is used as a protocol to communicate with the RPU firmware. It has pre-defined set of messages for different message exchanges between APU and RPU.

Thanks for your patch, which is now commit eb96b740192b2a09 ("cdx:
add MCDI protocol interface for firmware interaction") upstream.

Quoted 20 lines
drivers/cdx/controller/Kconfig new file +17 -0
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# CDX controller configuration
+#
+# Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
+#
+
+if CDX_BUS
+
+config MCDI_LOGGING
+       bool "MCDI Logging for the CDX controller"
+       depends on CDX_CONTROLLER
+       help
+         Enable MCDI Logging for
+         the CDX Controller for debug
+         purpose.
+
Quoted 8 lines

drivers/cdx/controller/Kconfig line 20

Quoted 3 lines
drivers/cdx/controller/Kconfig new file +3 -0
+         If unsure, say N.
+
+endif

As there also exist config symbols SFC_MCDI_LOGGING and SFC_SIENA_MCDI_LOGGING, perhaps MCDI_LOGGING is too generic, and should
be renamed to CDX_MCDI_LOGGING?

Sure, we will add a patch to rename this.

Thanks,
Nipun

Quoted 17 lines

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux- m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

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

author maintainer
#9 lore raw

PATCH v10 5/7 cdx: add cdx controller

In reply to Nipun Gupta

CDX controller uses MCDI interface as a protocol to communicate with the RPU firmware and registers the detected CDX devices on the CDX bus. It also uses RPMsg as the communication channel with the Firmware.

---
 drivers/cdx/controller/Kconfig          |   9 ++
 drivers/cdx/controller/Makefile         |   2 +-
 drivers/cdx/controller/cdx_controller.c | 188 ++++++++++++++++++++++++
 drivers/cdx/controller/mcdi_functions.c | 125 ++++++++++++++++
 drivers/cdx/controller/mcdi_functions.h |  50 +++++++
 5 files changed, 373 insertions(+), 1 deletion(-)
 create mode 100644 drivers/cdx/controller/cdx_controller.c
 create mode 100644 drivers/cdx/controller/mcdi_functions.c
 create mode 100644 drivers/cdx/controller/mcdi_functions.h
drivers/cdx/controller/Kconfig +9 -0
index 785c71063b2a..17f9c6be2fe1 100644
@@ -7,6 +7,15 @@
 
 if CDX_BUS
 
+config CDX_CONTROLLER
+	tristate "CDX bus controller"
+	help
+	  CDX controller drives the CDX bus. It interacts with
+	  firmware to get the hardware devices and registers with
+	  the CDX bus. Say Y to enable the CDX hardware driver.
+
+	  If unsure, say N.
+
 config MCDI_LOGGING
 	bool "MCDI Logging for the CDX controller"
 	depends on CDX_CONTROLLER
drivers/cdx/controller/Makefile +1 -1
index 0ce200678eda..f7437c882cc9 100644
@@ -6,4 +6,4 @@
 #
 
 obj-$(CONFIG_CDX_CONTROLLER) += cdx-controller.o
-cdx-controller-objs := mcdi.o
+cdx-controller-objs := cdx_controller.o mcdi.o mcdi_functions.o
drivers/cdx/controller/cdx_controller.c new file +188 -0

188 lines not on this page · raw message

drivers/cdx/controller/mcdi_functions.c new file +125 -0

125 lines not on this page · raw message

drivers/cdx/controller/mcdi_functions.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#10 lore raw

PATCH v10 6/7 cdx: add rpmsg communication channel for CDX

In reply to Nipun Gupta

RPMsg is used as a transport communication channel. This change introduces RPMsg driver and integrates it with the CDX controller.

---
 drivers/cdx/controller/Kconfig          |   2 +
 drivers/cdx/controller/Makefile         |   2 +-
 drivers/cdx/controller/cdx_controller.c |  32 +++-
 drivers/cdx/controller/cdx_controller.h |  30 ++++
 drivers/cdx/controller/cdx_rpmsg.c      | 202 ++++++++++++++++++++++++
 drivers/cdx/controller/mcdi.h           |  10 ++
 6 files changed, 273 insertions(+), 5 deletions(-)
 create mode 100644 drivers/cdx/controller/cdx_controller.h
 create mode 100644 drivers/cdx/controller/cdx_rpmsg.c
drivers/cdx/controller/Kconfig +2 -0
index 17f9c6be2fe1..c3e3b9ff8dfe 100644
@@ -9,6 +9,8 @@ if CDX_BUS
 
 config CDX_CONTROLLER
 	tristate "CDX bus controller"
+	select REMOTEPROC
+	select RPMSG
 	help
 	  CDX controller drives the CDX bus. It interacts with
 	  firmware to get the hardware devices and registers with
drivers/cdx/controller/Makefile +1 -1
index f7437c882cc9..f071be411d96 100644
@@ -6,4 +6,4 @@
 #
 
 obj-$(CONFIG_CDX_CONTROLLER) += cdx-controller.o
-cdx-controller-objs := cdx_controller.o mcdi.o mcdi_functions.o
+cdx-controller-objs := cdx_controller.o cdx_rpmsg.o mcdi.o mcdi_functions.o
drivers/cdx/controller/cdx_controller.c +28 -4
index fbebc8cdcbf8..0d1826980935 100644
@@ -9,6 +9,7 @@
 #include <linux/slab.h>
 #include <linux/cdx/cdx_bus.h>
 
+#include "cdx_controller.h"
 #include "../cdx.h"
 #include "mcdi_functions.h"
 #include "mcdi.h"
@@ -22,10 +23,8 @@ static void cdx_mcdi_request(struct cdx_mcdi *cdx,
 			     const struct cdx_dword *hdr, size_t hdr_len,
 			     const struct cdx_dword *sdu, size_t sdu_len)
 {
-	/*
-	 * This will get updated by rpmsg APIs, with RPMSG introduction
-	 * in CDX controller as a transport layer.
-	 */
+	if (cdx_rpmsg_send(cdx, hdr, hdr_len, sdu, sdu_len))
+		dev_err(&cdx->rpdev->dev, "Failed to send rpmsg data\n");
 }
 
 static const struct cdx_mcdi_ops mcdi_ops = {
@@ -33,6 +32,19 @@ static const struct cdx_mcdi_ops mcdi_ops = {
 	.mcdi_request = cdx_mcdi_request,
 };
 
+void cdx_rpmsg_post_probe(struct cdx_controller *cdx)
+{
+	/* Register CDX controller with CDX bus driver */
+	if (cdx_register_controller(cdx))
+		dev_err(cdx->dev, "Failed to register CDX controller\n");
+}
+
+void cdx_rpmsg_pre_remove(struct cdx_controller *cdx)
+{
+	cdx_unregister_controller(cdx);
+	cdx_mcdi_wait_for_quiescence(cdx->priv, MCDI_RPC_TIMEOUT);
+}
+
 static int cdx_scan_devices(struct cdx_controller *cdx)
 {
 	struct cdx_mcdi *cdx_mcdi = cdx->priv;
@@ -124,8 +136,18 @@ static int xlnx_cdx_probe(struct platform_device *pdev)
 	cdx->priv = cdx_mcdi;
 	cdx->ops = &cdx_ops;
 
+	ret = cdx_setup_rpmsg(pdev);
+	if (ret) {
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "Failed to register CDX RPMsg transport\n");
+		goto cdx_rpmsg_fail;
+	}
+
+	dev_info(&pdev->dev, "Successfully registered CDX controller with RPMsg as transport\n");
 	return 0;
 
+cdx_rpmsg_fail:
+	kfree(cdx);
 cdx_alloc_fail:
 	cdx_mcdi_finish(cdx_mcdi);
 mcdi_init_fail:
@@ -139,6 +161,8 @@ static int xlnx_cdx_remove(struct platform_device *pdev)
 	struct cdx_controller *cdx = platform_get_drvdata(pdev);
 	struct cdx_mcdi *cdx_mcdi = cdx->priv;
 
+	cdx_destroy_rpmsg(pdev);
+
 	kfree(cdx);
 
 	cdx_mcdi_finish(cdx_mcdi);
drivers/cdx/controller/cdx_controller.h new file +30 -0
new file mode 100644
index 000000000000..43b7c742df87
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Header file for the CDX Controller
+ *
+ * Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
+ */
+
+#ifndef _CDX_CONTROLLER_H_
+#define _CDX_CONTROLLER_H_
+
+#include <linux/cdx/cdx_bus.h>
+#include "mcdi_functions.h"
+
+void cdx_rpmsg_post_probe(struct cdx_controller *cdx);
+
+void cdx_rpmsg_pre_remove(struct cdx_controller *cdx);
+
+int cdx_rpmsg_send(struct cdx_mcdi *cdx_mcdi,
+		   const struct cdx_dword *hdr, size_t hdr_len,
+		   const struct cdx_dword *sdu, size_t sdu_len);
+
+void cdx_rpmsg_read_resp(struct cdx_mcdi *cdx_mcdi,
+			 struct cdx_dword *outbuf, size_t offset,
+			 size_t outlen);
+
+int cdx_setup_rpmsg(struct platform_device *pdev);
+
+void cdx_destroy_rpmsg(struct platform_device *pdev);
+
+#endif /* _CDX_CONT_PRIV_H_ */
drivers/cdx/controller/cdx_rpmsg.c new file +202 -0

202 lines not on this page · raw message

drivers/cdx/controller/mcdi.h +10 -0
index 63933ede33ed..0bfbeab04e43 100644
@@ -9,6 +9,7 @@
 
 #include <linux/mutex.h>
 #include <linux/kref.h>
+#include <linux/rpmsg.h>
 
 #include "bitfield.h"
 #include "mc_cdx_pcol.h"
@@ -62,11 +63,20 @@ enum cdx_mcdi_cmd_state {
  *	with CDX controller.
  * @mcdi: MCDI interface
  * @mcdi_ops: MCDI operations
+ * @r5_rproc : R5 Remoteproc device handle
+ * @rpdev: RPMsg device
+ * @ept: RPMsg endpoint
+ * @work: Post probe work
  */
 struct cdx_mcdi {
 	/* MCDI interface */
 	struct cdx_mcdi_data *mcdi;
 	const struct cdx_mcdi_ops *mcdi_ops;
+
+	struct rproc *r5_rproc;
+	struct rpmsg_device *rpdev;
+	struct rpmsg_endpoint *ept;
+	struct work_struct work;
 };
 
 struct cdx_mcdi_ops {
Signature · 1 line
2.17.1
author maintainer
#11 lore raw

PATCH v10 7/7 cdx: add device attributes

In reply to Nipun Gupta

Create sysfs entry for CDX devices.

Sysfs entries provided in each of the CDX device detected by the CDX controller
- vendor id
- device id
- remove
- reset of the device.
- driver override

---
 Documentation/ABI/testing/sysfs-bus-cdx |  44 ++++++++
 drivers/cdx/cdx.c                       | 127 ++++++++++++++++++++++++
 drivers/cdx/controller/cdx_controller.c |  18 ++++
 drivers/cdx/controller/mcdi_functions.c |  14 +++
 drivers/cdx/controller/mcdi_functions.h |  11 ++
 include/linux/cdx/cdx_bus.h             |  27 +++++
 6 files changed, 241 insertions(+)
Documentation/ABI/testing/sysfs-bus-cdx +44 -0
index 43b4e161f226..7af477f49998 100644
@@ -10,3 +10,47 @@ Description:
 		For example::
 
 		  # echo 1 > /sys/bus/cdx/rescan
+
+What:		/sys/bus/cdx/devices/.../vendor
+Date:		March 2023
+Contact:	[email protected]
+Description:
+		Vendor ID for this CDX device, in hexadecimal. Vendor ID is
+		16 bit identifier which is specific to the device manufacturer.
+		Combination of Vendor ID and Device ID identifies a device.
+
+What:		/sys/bus/cdx/devices/.../device
+Date:		March 2023
+Contact:	[email protected]
+Description:
+		Device ID for this CDX device, in hexadecimal. Device ID is
+		16 bit identifier to identify a device type within the range
+		of a device manufacturer.
+		Combination of Vendor ID and Device ID identifies a device.
+
+What:		/sys/bus/cdx/devices/.../reset
+Date:		March 2023
+Contact:	[email protected]
+Description:
+		Writing y/1/on to this file resets the CDX device.
+		On resetting the device, the corresponding driver is notified
+		twice, once before the device is being reset, and again after
+		the reset has been complete.
+
+		For example::
+
+		  # echo 1 > /sys/bus/cdx/.../reset
+
+What:		/sys/bus/cdx/devices/.../remove
+Date:		March 2023
+Contact:	[email protected]
+Description:
+		Writing y/1/on to this file removes the corresponding
+		device from the CDX bus. If the device is to be reconfigured
+		reconfigured in the Hardware, the device can be removed, so
+		that the device driver does not access the device while it is
+		being reconfigured.
+
+		For example::
+
+		  # echo 1 > /sys/bus/cdx/devices/.../remove
drivers/cdx/cdx.c +127 -0

145 lines not on this page · raw message

drivers/cdx/controller/cdx_controller.c +18 -0
index 0d1826980935..dc52f95f8978 100644
@@ -45,6 +45,23 @@ void cdx_rpmsg_pre_remove(struct cdx_controller *cdx)
 	cdx_mcdi_wait_for_quiescence(cdx->priv, MCDI_RPC_TIMEOUT);
 }
 
+static int cdx_configure_device(struct cdx_controller *cdx,
+				u8 bus_num, u8 dev_num,
+				struct cdx_device_config *dev_config)
+{
+	int ret = 0;
+
+	switch (dev_config->type) {
+	case CDX_DEV_RESET_CONF:
+		ret = cdx_mcdi_reset_device(cdx->priv, bus_num, dev_num);
+		break;
+	default:
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
 static int cdx_scan_devices(struct cdx_controller *cdx)
 {
 	struct cdx_mcdi *cdx_mcdi = cdx->priv;
@@ -104,6 +121,7 @@ static int cdx_scan_devices(struct cdx_controller *cdx)
 
 static struct cdx_ops cdx_ops = {
 	.scan		= cdx_scan_devices,
+	.dev_configure	= cdx_configure_device,
 };
 
 static int xlnx_cdx_probe(struct platform_device *pdev)
drivers/cdx/controller/mcdi_functions.c +14 -0
index 012b52881dd5..0158f26533dd 100644
@@ -123,3 +123,17 @@ int cdx_mcdi_get_dev_config(struct cdx_mcdi *cdx,
 
 	return 0;
 }
+
+int cdx_mcdi_reset_device(struct cdx_mcdi *cdx, u8 bus_num, u8 dev_num)
+{
+	MCDI_DECLARE_BUF(inbuf, MC_CMD_CDX_DEVICE_RESET_IN_LEN);
+	int ret;
+
+	MCDI_SET_DWORD(inbuf, CDX_DEVICE_RESET_IN_BUS, bus_num);
+	MCDI_SET_DWORD(inbuf, CDX_DEVICE_RESET_IN_DEVICE, dev_num);
+
+	ret = cdx_mcdi_rpc(cdx, MC_CMD_CDX_DEVICE_RESET, inbuf, sizeof(inbuf),
+			   NULL, 0, NULL);
+
+	return ret;
+}
drivers/cdx/controller/mcdi_functions.h +11 -0
index 6bf5a4a0778f..7440ace5539a 100644
@@ -47,4 +47,15 @@ int cdx_mcdi_get_dev_config(struct cdx_mcdi *cdx,
 			    u8 bus_num, u8 dev_num,
 			    struct cdx_dev_params *dev_params);
 
+/**
+ * cdx_mcdi_reset_device - Reset cdx device represented by bus_num:dev_num
+ * @cdx: pointer to MCDI interface.
+ * @bus_num: Bus number.
+ * @dev_num: Device number.
+ *
+ * Return: 0 on success, <0 on failure
+ */
+int cdx_mcdi_reset_device(struct cdx_mcdi *cdx,
+			  u8 bus_num, u8 dev_num);
+
 #endif /* CDX_MCDI_FUNCTIONS_H */
include/linux/cdx/cdx_bus.h +27 -0
index d134e0104724..35ef41d8a61a 100644
@@ -21,8 +21,20 @@
 /* Forward declaration for CDX controller */
 struct cdx_controller;
 
+enum {
+	CDX_DEV_RESET_CONF,
+};
+
+struct cdx_device_config {
+	u8 type;
+};
+
 typedef int (*cdx_scan_cb)(struct cdx_controller *cdx);
 
+typedef int (*cdx_dev_configure_cb)(struct cdx_controller *cdx,
+				    u8 bus_num, u8 dev_num,
+				    struct cdx_device_config *dev_config);
+
 /**
  * CDX_DEVICE_DRIVER_OVERRIDE - macro used to describe a CDX device with
  *                              override_only flags.
@@ -39,9 +51,12 @@ typedef int (*cdx_scan_cb)(struct cdx_controller *cdx);
 /**
  * struct cdx_ops - Callbacks supported by CDX controller.
  * @scan: scan the devices on the controller
+ * @dev_configure: configuration like reset, master_enable,
+ *		   msi_config etc for a CDX device
  */
 struct cdx_ops {
 	cdx_scan_cb scan;
+	cdx_dev_configure_cb dev_configure;
 };
 
 /**
@@ -101,6 +116,8 @@ struct cdx_device {
  * @probe: Function called when a device is added
  * @remove: Function called when a device is removed
  * @shutdown: Function called at shutdown time to quiesce the device
+ * @reset_prepare: Function called before is reset to notify driver
+ * @reset_done: Function called after reset is complete to notify driver
  * @driver_managed_dma: Device driver doesn't use kernel DMA API for DMA.
  *		For most device drivers, no need to care about this flag
  *		as long as all DMAs are handled through the kernel DMA API.
@@ -115,6 +132,8 @@ struct cdx_driver {
 	int (*probe)(struct cdx_device *dev);
 	int (*remove)(struct cdx_device *dev);
 	void (*shutdown)(struct cdx_device *dev);
+	void (*reset_prepare)(struct cdx_device *dev);
+	void (*reset_done)(struct cdx_device *dev);
 	bool driver_managed_dma;
 };
 
@@ -144,4 +163,12 @@ void cdx_driver_unregister(struct cdx_driver *cdx_driver);
 
 extern struct bus_type cdx_bus_type;
 
+/**
+ * cdx_dev_reset - Reset CDX device
+ * @dev: device pointer
+ *
+ * Return: 0 for success, -errno on failure
+ */
+int cdx_dev_reset(struct device *dev);
+
 #endif /* _CDX_BUS_H_ */
Signature · 1 line
2.17.1