Skip to contentSkip to conversation

RFC enable IAF support on PVC.

RFC PATCH In review Maarten Lankhorst 2 participants 10 messages Jun 13, 2025 – Jun 18, 2025

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover RFC enable IAF support on PVC.

A lot of this code is not new, it's mostly based on previous patches by David Kershner.

A lot of this code is lifted from the backport/main branch in
https://github.com/intel-gpu/intel-gpu-i915-backports

With the recent patch series to enable MTD support, it's possible to enable IAF support as well. This series applies on top of the v12 MTD series by Alexander Usyskin.

Patch 1 enables the PSC region in MTD.
Patch 2 adds IAF define to i915-component.
Patch 3 adds MEI support from the backports repo.
Patch 4 is a small modification of the backport of the IAF code. Patch 5 enables loading of the fabric code in xe.
Patch 6 is a UAPI change.
Patch 7 is a small cleanup, should probably be sent separately. Patch 8 enables mapping of DMA-BUF through IAF instead of through PCI-E.

I would like to have a discussion mostly on the last patch, I'm abusing the DMA-BUF api, and would like to start a discussion if this way is acceptable or not, or potentially ways to handle it.

In particular, I have been using the following (pseudo) code:

xe_dma_buf_map(...)

{
	if (dir == DMA_NONE) {
		/* Only allow DMA_NONE for xe <-> xe */
		if (attach->importer_ops != &xe_dma_buf_attach_ops)
			return ERR_PTR(-EOPNOTSUPP);

		iaf = true;
	}
}

bo_map_dma_buf(...)

{
	if (dmabuf->ops == &xe_dmabuf_ops) {
		struct xe_device *src = xe_bo_device(gem_to_xe_bo(dmabuf->priv));
		struct xe_device *dst = xe_bo_device(bo);

		if (iaf_possible(src, dst))
			sg = dma_buf_map_attachment(attach, DMA_NONE);

		if (!IS_ERR(sg)) {
			bo->flags |= XE_BO_FLAG_IAF;
			return sg;
		}

		/* fallback */
	}

	return dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
}

With of course:
bo_unmap_dma_buf(...)

{
	dma_buf_unmap_attachment(attach, sg,
				bo->flags & XE_BO_FLAG_IAF ?
				DMA_NONE : DMA_BIDIRECTIONAL);
}

Maarten Lankhorst (8):
drm/xe: Add PSC region for PVC include/drm/i915_component: Add IAF type.
mei: Add IAF mei component
drm/xe: Add fabric code from i915 backport repository. drm/xe: Add support for IAF devices.
drm/xe/uapi: Add query ioctl for fabric connectivity drm/xe: Remove unused XE_DEFAULT_GTT_SIZE_MB definition. drm/xe: Allow mapping DMA-BUF buffer objects connected through IAF

 drivers/gpu/drm/xe/Kconfig                    |    2 +
 drivers/gpu/drm/xe/Makefile                   |    2 +
 drivers/gpu/drm/xe/fabric/Kconfig             |   53 +
 drivers/gpu/drm/xe/fabric/Makefile            |   42 +
 drivers/gpu/drm/xe/fabric/csr.h               |  497 ++++
 drivers/gpu/drm/xe/fabric/debugfs.c           |  112 +
 drivers/gpu/drm/xe/fabric/debugfs.h           |   26 +
 drivers/gpu/drm/xe/fabric/dev_diag.c          |  723 ++++++
 drivers/gpu/drm/xe/fabric/dev_diag.h          |   15 +
 drivers/gpu/drm/xe/fabric/error.c             | 1490 ++++++++++++
 drivers/gpu/drm/xe/fabric/error.h             |   15 +
 drivers/gpu/drm/xe/fabric/fw.c                | 2089 +++++++++++++++++
 drivers/gpu/drm/xe/fabric/fw.h                |   21 +
 drivers/gpu/drm/xe/fabric/iaf_drv.h           | 1341 +++++++++++
 drivers/gpu/drm/xe/fabric/iaf_netlink.h       |  208 ++
 drivers/gpu/drm/xe/fabric/io.h                |   82 +
 drivers/gpu/drm/xe/fabric/main.c              | 1098 +++++++++
 drivers/gpu/drm/xe/fabric/mbdb.c              | 1173 +++++++++
 drivers/gpu/drm/xe/fabric/mbdb.h              |  171 ++
 drivers/gpu/drm/xe/fabric/mbox.c              |  440 ++++
 drivers/gpu/drm/xe/fabric/mbox.h              |   18 +
 drivers/gpu/drm/xe/fabric/mei_iaf_user.c      |  440 ++++
 drivers/gpu/drm/xe/fabric/mei_iaf_user.h      |   19 +
 drivers/gpu/drm/xe/fabric/netlink.c           | 1532 ++++++++++++
 drivers/gpu/drm/xe/fabric/netlink.h           |   15 +
 drivers/gpu/drm/xe/fabric/ops.c               | 1476 ++++++++++++
 drivers/gpu/drm/xe/fabric/ops.h               |  525 +++++
 drivers/gpu/drm/xe/fabric/parallel.c          |   96 +
 drivers/gpu/drm/xe/fabric/parallel.h          |   33 +
 drivers/gpu/drm/xe/fabric/port.c              | 1884 +++++++++++++++
 drivers/gpu/drm/xe/fabric/port.h              |   41 +
 drivers/gpu/drm/xe/fabric/port_diag.c         | 1892 +++++++++++++++
 drivers/gpu/drm/xe/fabric/port_diag.h         |   19 +
 drivers/gpu/drm/xe/fabric/routing_debug.c     |  484 ++++
 drivers/gpu/drm/xe/fabric/routing_debug.h     |   16 +
 drivers/gpu/drm/xe/fabric/routing_engine.c    |  565 +++++
 drivers/gpu/drm/xe/fabric/routing_engine.h    |   25 +
 drivers/gpu/drm/xe/fabric/routing_event.c     |  249 ++
 drivers/gpu/drm/xe/fabric/routing_event.h     |   19 +
 drivers/gpu/drm/xe/fabric/routing_io.c        |  496 ++++
 drivers/gpu/drm/xe/fabric/routing_io.h        |   15 +
 drivers/gpu/drm/xe/fabric/routing_logic.c     |  934 ++++++++
 drivers/gpu/drm/xe/fabric/routing_logic.h     |   16 +
 drivers/gpu/drm/xe/fabric/routing_p2p.c       |  883 +++++++
 drivers/gpu/drm/xe/fabric/routing_p2p.h       |   22 +
 drivers/gpu/drm/xe/fabric/routing_pause.c     |  282 +++
 drivers/gpu/drm/xe/fabric/routing_pause.h     |   16 +
 drivers/gpu/drm/xe/fabric/routing_topology.c  |  200 ++
 drivers/gpu/drm/xe/fabric/routing_topology.h  |  376 +++
 .../drm/xe/fabric/selftests/routing_mock.c    |  291 +++
 .../drm/xe/fabric/selftests/routing_mock.h    |   22 +
 .../xe/fabric/selftests/routing_selftest.c    |  424 ++++
 .../xe/fabric/selftests/routing_selftest.h    |   12 +
 .../gpu/drm/xe/fabric/selftests/selftest.c    |   73 +
 .../gpu/drm/xe/fabric/selftests/selftest.h    |   34 +
 drivers/gpu/drm/xe/fabric/statedump.c         |  283 +++
 drivers/gpu/drm/xe/fabric/statedump.h         |   32 +
 drivers/gpu/drm/xe/fabric/sysfs.c             |  327 +++
 drivers/gpu/drm/xe/fabric/sysfs.h             |   16 +
 drivers/gpu/drm/xe/fabric/trace.c             |    8 +
 drivers/gpu/drm/xe/fabric/trace.h             |   11 +
 drivers/gpu/drm/xe/fabric/trace_mbx.h         |   99 +
 drivers/gpu/drm/xe/fabric/trace_nl.h          |   54 +
 drivers/gpu/drm/xe/fabric/trace_pm.h          |  102 +
 drivers/gpu/drm/xe/fabric/trace_rt.h          |  110 +
 drivers/gpu/drm/xe/regs/xe_gt_regs.h          |   23 +
 drivers/gpu/drm/xe/xe_bo.c                    |   85 +-
 drivers/gpu/drm/xe/xe_bo.h                    |    4 +-
 drivers/gpu/drm/xe/xe_device.c                |   12 +-
 drivers/gpu/drm/xe/xe_device_types.h          |    3 +
 drivers/gpu/drm/xe/xe_dma_buf.c               |   27 +-
 drivers/gpu/drm/xe/xe_dma_buf.h               |    1 +
 drivers/gpu/drm/xe/xe_ggtt.c                  |    4 +-
 drivers/gpu/drm/xe/xe_gt_types.h              |    3 +
 drivers/gpu/drm/xe/xe_iaf.c                   |  460 ++++
 drivers/gpu/drm/xe/xe_iaf.h                   |   82 +
 drivers/gpu/drm/xe/xe_irq.c                   |   16 +-
 drivers/gpu/drm/xe/xe_nvm.c                   |    1 +
 drivers/gpu/drm/xe/xe_pt.c                    |    4 +
 drivers/gpu/drm/xe/xe_query.c                 |   58 +
 drivers/gpu/drm/xe/xe_ttm_vram_mgr.c          |   23 +-
 drivers/gpu/drm/xe/xe_vm.c                    |    2 +-
 drivers/gpu/drm/xe/xe_vram.c                  |    4 +-
 drivers/misc/mei/Kconfig                      |    1 +
 drivers/misc/mei/Makefile                     |    1 +
 drivers/misc/mei/iaf/Kconfig                  |   12 +
 drivers/misc/mei/iaf/Makefile                 |    7 +
 drivers/misc/mei/iaf/mei_iaf.c                |  292 +++
 drivers/misc/mei/mkhi.h                       |    2 +
 include/drm/intel/i915_component.h            |    1 +
 include/drm/intel/i915_mei_iaf_interface.h    |   25 +
 include/drm/intel/intel_iaf_platform.h        |  145 ++
 include/linux/intel_dg_nvm_aux.h              |    2 +-
 include/uapi/drm/xe_drm.h                     |   32 +
 94 files changed, 25389 insertions(+), 29 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/fabric/Kconfig
 create mode 100644 drivers/gpu/drm/xe/fabric/Makefile
 create mode 100644 drivers/gpu/drm/xe/fabric/csr.h
 create mode 100644 drivers/gpu/drm/xe/fabric/debugfs.c
 create mode 100644 drivers/gpu/drm/xe/fabric/debugfs.h
 create mode 100644 drivers/gpu/drm/xe/fabric/dev_diag.c
 create mode 100644 drivers/gpu/drm/xe/fabric/dev_diag.h
 create mode 100644 drivers/gpu/drm/xe/fabric/error.c
 create mode 100644 drivers/gpu/drm/xe/fabric/error.h
 create mode 100644 drivers/gpu/drm/xe/fabric/fw.c
 create mode 100644 drivers/gpu/drm/xe/fabric/fw.h
 create mode 100644 drivers/gpu/drm/xe/fabric/iaf_drv.h
 create mode 100644 drivers/gpu/drm/xe/fabric/iaf_netlink.h
 create mode 100644 drivers/gpu/drm/xe/fabric/io.h
 create mode 100644 drivers/gpu/drm/xe/fabric/main.c
 create mode 100644 drivers/gpu/drm/xe/fabric/mbdb.c
 create mode 100644 drivers/gpu/drm/xe/fabric/mbdb.h
 create mode 100644 drivers/gpu/drm/xe/fabric/mbox.c
 create mode 100644 drivers/gpu/drm/xe/fabric/mbox.h
 create mode 100644 drivers/gpu/drm/xe/fabric/mei_iaf_user.c
 create mode 100644 drivers/gpu/drm/xe/fabric/mei_iaf_user.h
 create mode 100644 drivers/gpu/drm/xe/fabric/netlink.c
 create mode 100644 drivers/gpu/drm/xe/fabric/netlink.h
 create mode 100644 drivers/gpu/drm/xe/fabric/ops.c
 create mode 100644 drivers/gpu/drm/xe/fabric/ops.h
 create mode 100644 drivers/gpu/drm/xe/fabric/parallel.c
 create mode 100644 drivers/gpu/drm/xe/fabric/parallel.h
 create mode 100644 drivers/gpu/drm/xe/fabric/port.c
 create mode 100644 drivers/gpu/drm/xe/fabric/port.h
 create mode 100644 drivers/gpu/drm/xe/fabric/port_diag.c
 create mode 100644 drivers/gpu/drm/xe/fabric/port_diag.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_debug.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_debug.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_engine.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_engine.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_event.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_event.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_io.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_io.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_logic.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_logic.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_p2p.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_p2p.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_pause.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_pause.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_topology.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_topology.h
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/routing_mock.c
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/routing_mock.h
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/routing_selftest.c
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/routing_selftest.h
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/selftest.c
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/selftest.h
 create mode 100644 drivers/gpu/drm/xe/fabric/statedump.c
 create mode 100644 drivers/gpu/drm/xe/fabric/statedump.h
 create mode 100644 drivers/gpu/drm/xe/fabric/sysfs.c
 create mode 100644 drivers/gpu/drm/xe/fabric/sysfs.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace.c
 create mode 100644 drivers/gpu/drm/xe/fabric/trace.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace_mbx.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace_nl.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace_pm.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace_rt.h
 create mode 100644 drivers/gpu/drm/xe/xe_iaf.c
 create mode 100644 drivers/gpu/drm/xe/xe_iaf.h
 create mode 100644 drivers/misc/mei/iaf/Kconfig
 create mode 100644 drivers/misc/mei/iaf/Makefile
 create mode 100644 drivers/misc/mei/iaf/mei_iaf.c
 create mode 100644 include/drm/intel/i915_mei_iaf_interface.h
 create mode 100644 include/drm/intel/intel_iaf_platform.h
Signature · 1 line
2.45.2
#1 lore raw

RFC PATCH 1/8 drm/xe: Add PSC region for PVC

---
 drivers/gpu/drm/xe/xe_nvm.c      | 1 +
 include/linux/intel_dg_nvm_aux.h | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_nvm.c +1 -0
index 61b0a1531a539..0a703c2612548 100644
@@ -31,6 +31,7 @@ static const struct intel_dg_nvm_region regions[INTEL_DG_NVM_REGIONS] = {
 	[9] = { .name = "PADDING", },
 	[11] = { .name = "OptionROM", },
 	[12] = { .name = "DAM", },
+	[13] = { .name = "PSC" },
 };
 
 static void xe_nvm_release_dev(struct device *dev)
include/linux/intel_dg_nvm_aux.h +1 -1
index 625d46a6b96e5..c51fe68d9a59d 100644
@@ -11,7 +11,7 @@
 #include <linux/ioport.h>
 #include <linux/types.h>
 
-#define INTEL_DG_NVM_REGIONS 13
+#define INTEL_DG_NVM_REGIONS 14
 
 struct intel_dg_nvm_region {
 	const char *name;
Signature · 1 line
2.45.2
#2 lore raw

RFC PATCH 2/8 include/drm/i915_component: Add IAF type.

In reply to Maarten Lankhorst

Required for making IAF subcomponenting work.

---
 include/drm/intel/i915_component.h | 1 +
 1 file changed, 1 insertion(+)
include/drm/intel/i915_component.h +1 -0
index 4ea3b17aa1439..acfeae91785a4 100644
@@ -31,6 +31,7 @@ enum i915_component_type {
 	I915_COMPONENT_HDCP,
 	I915_COMPONENT_PXP,
 	I915_COMPONENT_GSC_PROXY,
+	I915_COMPONENT_IAF,
 };
 
 /* MAX_PORT is the number of port
Signature · 1 line
2.45.2
#3 lore raw

RFC PATCH 3/8 mei: Add IAF mei component

In reply to Maarten Lankhorst

From the backport repository.

---
 drivers/misc/mei/Kconfig                   |   1 +
 drivers/misc/mei/Makefile                  |   1 +
 drivers/misc/mei/iaf/Kconfig               |  12 +
 drivers/misc/mei/iaf/Makefile              |   7 +
 drivers/misc/mei/iaf/mei_iaf.c             | 292 +++++++++++++++++++++
 drivers/misc/mei/mkhi.h                    |   2 +
 include/drm/intel/i915_mei_iaf_interface.h |  25 ++
 7 files changed, 340 insertions(+)
 create mode 100644 drivers/misc/mei/iaf/Kconfig
 create mode 100644 drivers/misc/mei/iaf/Makefile
 create mode 100644 drivers/misc/mei/iaf/mei_iaf.c
 create mode 100644 include/drm/intel/i915_mei_iaf_interface.h
drivers/misc/mei/Kconfig +1 -0
index 7575fee96cc6a..60b2cfa27ebaa 100644
@@ -84,5 +84,6 @@ config INTEL_MEI_VSC
 source "drivers/misc/mei/hdcp/Kconfig"
 source "drivers/misc/mei/pxp/Kconfig"
 source "drivers/misc/mei/gsc_proxy/Kconfig"
+source "drivers/misc/mei/iaf/Kconfig"
 
 endif
drivers/misc/mei/Makefile +1 -0
index 6f9fdbf1a4959..8be787f8ecd41 100644
@@ -31,6 +31,7 @@ CFLAGS_mei-trace.o = -I$(src)
 obj-$(CONFIG_INTEL_MEI_HDCP) += hdcp/
 obj-$(CONFIG_INTEL_MEI_PXP) += pxp/
 obj-$(CONFIG_INTEL_MEI_GSC_PROXY) += gsc_proxy/
+obj-$(CONFIG_INTEL_MEI_IAF) += iaf/
 
 obj-$(CONFIG_INTEL_MEI_VSC_HW) += mei-vsc-hw.o
 mei-vsc-hw-y := vsc-tp.o
drivers/misc/mei/iaf/Kconfig new file +12 -0
new file mode 100644
index 0000000000000..4d131df6cf79f
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020-2021, Intel Corporation. All rights reserved.
+#
+config INTEL_MEI_IAF
+	tristate "Intel Accelerator Fabric services of ME Interface"
+	depends on m
+	select INTEL_MEI_ME
+	depends on DRM_XE
+	help
+	  MEI Support for IAF Services on Intel graphics card.
+
+	  Enables the ME FW services required for IAF support.
drivers/misc/mei/iaf/Makefile new file +7 -0
new file mode 100644
index 0000000000000..1130cbc9c0ccb
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (c) 2020-2021, Intel Corporation. All rights reserved.
+#
+# Makefile - IAF client driver for Intel MEI Bus Driver.
+
+obj-$(CONFIG_INTEL_MEI_IAF) += mei_iaf.o
drivers/misc/mei/iaf/mei_iaf.c new file +292 -0

292 lines not on this page · raw message

drivers/misc/mei/mkhi.h +2 -0
index 1473ea4896662..63d9f02e7341f 100644
@@ -16,6 +16,8 @@
 #define MKHI_GEN_GROUP_ID 0xFF
 #define MKHI_GEN_GET_FW_VERSION_CMD 0x2
 
+#define MCHI_GROUP_ID  0xA
+
 #define MKHI_GROUP_ID_GFX              0x30
 #define MKHI_GFX_RESET_WARN_CMD_REQ    0x0
 #define MKHI_GFX_MEMORY_READY_CMD_REQ  0x1
include/drm/intel/i915_mei_iaf_interface.h new file +25 -0
new file mode 100644
index 0000000000000..dde938dd0ea2c
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: (GPL-2.0+) */
+/*
+ * Copyright © 2020-2021 Intel Corporation
+ */
+
+#ifndef _I915_MEI_IAF_INTERFACE_H_
+#define _I915_MEI_IAF_INTERFACE_H_
+
+#include <linux/device.h>
+
+/**
+ * struct i915_iaf_component_ops- ops for IAF services.
+ * @owner: Module providing the ops
+ * @commit_svn: commits current FW SVN
+ */
+struct i915_iaf_component_ops {
+	/**
+	 * @owner: mei_iaf module
+	 */
+	struct module *owner;
+
+	int (*commit_svn)(const struct device *dev);
+};
+
+#endif /* _I915_MEI_IAF_INTERFACE_H_ */
Signature · 1 line
2.45.2
#4 lore raw

RFC PATCH 4/8 drm/xe: Add fabric code from i915 backport repository.

In reply to Maarten Lankhorst

This is just a rough copy from the backport repository, made to work with the current xe code (compile fixes, etc).

The fabric code attempts to enumerate the PSCBIN through MTD, and thus requires the MTD patch series from Alexander Usyskin to work.

---
 drivers/gpu/drm/xe/Kconfig                    |    2 +
 drivers/gpu/drm/xe/Makefile                   |    1 +
 drivers/gpu/drm/xe/fabric/Kconfig             |   53 +
 drivers/gpu/drm/xe/fabric/Makefile            |   42 +
 drivers/gpu/drm/xe/fabric/csr.h               |  497 ++++
 drivers/gpu/drm/xe/fabric/debugfs.c           |  112 +
 drivers/gpu/drm/xe/fabric/debugfs.h           |   26 +
 drivers/gpu/drm/xe/fabric/dev_diag.c          |  723 ++++++
 drivers/gpu/drm/xe/fabric/dev_diag.h          |   15 +
 drivers/gpu/drm/xe/fabric/error.c             | 1490 ++++++++++++
 drivers/gpu/drm/xe/fabric/error.h             |   15 +
 drivers/gpu/drm/xe/fabric/fw.c                | 2089 +++++++++++++++++
 drivers/gpu/drm/xe/fabric/fw.h                |   21 +
 drivers/gpu/drm/xe/fabric/iaf_drv.h           | 1341 +++++++++++
 drivers/gpu/drm/xe/fabric/iaf_netlink.h       |  208 ++
 drivers/gpu/drm/xe/fabric/io.h                |   82 +
 drivers/gpu/drm/xe/fabric/main.c              | 1098 +++++++++
 drivers/gpu/drm/xe/fabric/mbdb.c              | 1173 +++++++++
 drivers/gpu/drm/xe/fabric/mbdb.h              |  171 ++
 drivers/gpu/drm/xe/fabric/mbox.c              |  440 ++++
 drivers/gpu/drm/xe/fabric/mbox.h              |   18 +
 drivers/gpu/drm/xe/fabric/mei_iaf_user.c      |  440 ++++
 drivers/gpu/drm/xe/fabric/mei_iaf_user.h      |   19 +
 drivers/gpu/drm/xe/fabric/netlink.c           | 1532 ++++++++++++
 drivers/gpu/drm/xe/fabric/netlink.h           |   15 +
 drivers/gpu/drm/xe/fabric/ops.c               | 1476 ++++++++++++
 drivers/gpu/drm/xe/fabric/ops.h               |  525 +++++
 drivers/gpu/drm/xe/fabric/parallel.c          |   96 +
 drivers/gpu/drm/xe/fabric/parallel.h          |   33 +
 drivers/gpu/drm/xe/fabric/port.c              | 1884 +++++++++++++++
 drivers/gpu/drm/xe/fabric/port.h              |   41 +
 drivers/gpu/drm/xe/fabric/port_diag.c         | 1892 +++++++++++++++
 drivers/gpu/drm/xe/fabric/port_diag.h         |   19 +
 drivers/gpu/drm/xe/fabric/routing_debug.c     |  484 ++++
 drivers/gpu/drm/xe/fabric/routing_debug.h     |   16 +
 drivers/gpu/drm/xe/fabric/routing_engine.c    |  565 +++++
 drivers/gpu/drm/xe/fabric/routing_engine.h    |   25 +
 drivers/gpu/drm/xe/fabric/routing_event.c     |  249 ++
 drivers/gpu/drm/xe/fabric/routing_event.h     |   19 +
 drivers/gpu/drm/xe/fabric/routing_io.c        |  496 ++++
 drivers/gpu/drm/xe/fabric/routing_io.h        |   15 +
 drivers/gpu/drm/xe/fabric/routing_logic.c     |  934 ++++++++
 drivers/gpu/drm/xe/fabric/routing_logic.h     |   16 +
 drivers/gpu/drm/xe/fabric/routing_p2p.c       |  883 +++++++
 drivers/gpu/drm/xe/fabric/routing_p2p.h       |   22 +
 drivers/gpu/drm/xe/fabric/routing_pause.c     |  282 +++
 drivers/gpu/drm/xe/fabric/routing_pause.h     |   16 +
 drivers/gpu/drm/xe/fabric/routing_topology.c  |  200 ++
 drivers/gpu/drm/xe/fabric/routing_topology.h  |  376 +++
 .../drm/xe/fabric/selftests/routing_mock.c    |  291 +++
 .../drm/xe/fabric/selftests/routing_mock.h    |   22 +
 .../xe/fabric/selftests/routing_selftest.c    |  424 ++++
 .../xe/fabric/selftests/routing_selftest.h    |   12 +
 .../gpu/drm/xe/fabric/selftests/selftest.c    |   73 +
 .../gpu/drm/xe/fabric/selftests/selftest.h    |   34 +
 drivers/gpu/drm/xe/fabric/statedump.c         |  283 +++
 drivers/gpu/drm/xe/fabric/statedump.h         |   32 +
 drivers/gpu/drm/xe/fabric/sysfs.c             |  327 +++
 drivers/gpu/drm/xe/fabric/sysfs.h             |   16 +
 drivers/gpu/drm/xe/fabric/trace.c             |    8 +
 drivers/gpu/drm/xe/fabric/trace.h             |   11 +
 drivers/gpu/drm/xe/fabric/trace_mbx.h         |   99 +
 drivers/gpu/drm/xe/fabric/trace_nl.h          |   54 +
 drivers/gpu/drm/xe/fabric/trace_pm.h          |  102 +
 drivers/gpu/drm/xe/fabric/trace_rt.h          |  110 +
 include/drm/intel/intel_iaf_platform.h        |  145 ++
 66 files changed, 24230 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/fabric/Kconfig
 create mode 100644 drivers/gpu/drm/xe/fabric/Makefile
 create mode 100644 drivers/gpu/drm/xe/fabric/csr.h
 create mode 100644 drivers/gpu/drm/xe/fabric/debugfs.c
 create mode 100644 drivers/gpu/drm/xe/fabric/debugfs.h
 create mode 100644 drivers/gpu/drm/xe/fabric/dev_diag.c
 create mode 100644 drivers/gpu/drm/xe/fabric/dev_diag.h
 create mode 100644 drivers/gpu/drm/xe/fabric/error.c
 create mode 100644 drivers/gpu/drm/xe/fabric/error.h
 create mode 100644 drivers/gpu/drm/xe/fabric/fw.c
 create mode 100644 drivers/gpu/drm/xe/fabric/fw.h
 create mode 100644 drivers/gpu/drm/xe/fabric/iaf_drv.h
 create mode 100644 drivers/gpu/drm/xe/fabric/iaf_netlink.h
 create mode 100644 drivers/gpu/drm/xe/fabric/io.h
 create mode 100644 drivers/gpu/drm/xe/fabric/main.c
 create mode 100644 drivers/gpu/drm/xe/fabric/mbdb.c
 create mode 100644 drivers/gpu/drm/xe/fabric/mbdb.h
 create mode 100644 drivers/gpu/drm/xe/fabric/mbox.c
 create mode 100644 drivers/gpu/drm/xe/fabric/mbox.h
 create mode 100644 drivers/gpu/drm/xe/fabric/mei_iaf_user.c
 create mode 100644 drivers/gpu/drm/xe/fabric/mei_iaf_user.h
 create mode 100644 drivers/gpu/drm/xe/fabric/netlink.c
 create mode 100644 drivers/gpu/drm/xe/fabric/netlink.h
 create mode 100644 drivers/gpu/drm/xe/fabric/ops.c
 create mode 100644 drivers/gpu/drm/xe/fabric/ops.h
 create mode 100644 drivers/gpu/drm/xe/fabric/parallel.c
 create mode 100644 drivers/gpu/drm/xe/fabric/parallel.h
 create mode 100644 drivers/gpu/drm/xe/fabric/port.c
 create mode 100644 drivers/gpu/drm/xe/fabric/port.h
 create mode 100644 drivers/gpu/drm/xe/fabric/port_diag.c
 create mode 100644 drivers/gpu/drm/xe/fabric/port_diag.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_debug.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_debug.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_engine.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_engine.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_event.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_event.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_io.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_io.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_logic.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_logic.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_p2p.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_p2p.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_pause.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_pause.h
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_topology.c
 create mode 100644 drivers/gpu/drm/xe/fabric/routing_topology.h
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/routing_mock.c
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/routing_mock.h
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/routing_selftest.c
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/routing_selftest.h
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/selftest.c
 create mode 100644 drivers/gpu/drm/xe/fabric/selftests/selftest.h
 create mode 100644 drivers/gpu/drm/xe/fabric/statedump.c
 create mode 100644 drivers/gpu/drm/xe/fabric/statedump.h
 create mode 100644 drivers/gpu/drm/xe/fabric/sysfs.c
 create mode 100644 drivers/gpu/drm/xe/fabric/sysfs.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace.c
 create mode 100644 drivers/gpu/drm/xe/fabric/trace.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace_mbx.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace_nl.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace_pm.h
 create mode 100644 drivers/gpu/drm/xe/fabric/trace_rt.h
 create mode 100644 include/drm/intel/intel_iaf_platform.h
drivers/gpu/drm/xe/Kconfig +2 -0
index c57f1da0791d9..1bfaba0a5b2e0 100644
@@ -134,3 +134,5 @@ menu "drm/xe Profile Guided Optimisation"
 	depends on DRM_XE
 	source "drivers/gpu/drm/xe/Kconfig.profile"
 endmenu
+
+source "drivers/gpu/drm/xe/fabric/Kconfig"
drivers/gpu/drm/xe/Makefile +1 -0
index 4c51fe3520dcc..7b6fee7fd1a65 100644
@@ -321,6 +321,7 @@ xe-$(CONFIG_DRM_XE_DP_TUNNEL) += \
 
 obj-$(CONFIG_DRM_XE) += xe.o
 obj-$(CONFIG_DRM_XE_KUNIT_TEST) += tests/
+obj-$(CONFIG_DRM_INTEL_FABRIC) += fabric/
 
 # header test
 hdrtest_find_args := -not -path xe_rtp_helpers.h
drivers/gpu/drm/xe/fabric/Kconfig new file +53 -0

53 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/Makefile new file +42 -0

42 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/csr.h new file +497 -0

497 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/debugfs.c new file +112 -0

112 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/debugfs.h new file +26 -0
new file mode 100644
index 0000000000000..6227f0620fab0
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright(c) 2022 Intel Corporation.
+ *
+ */
+
+#ifndef DEBUGFS_H_INCLUDED
+#define DEBUGFS_H_INCLUDED
+
+#include <linux/dcache.h>
+
+#include "iaf_drv.h"
+
+#define F_DENTRY(filp) ((filp)->f_path.dentry)
+
+__printf(4, 5)
+void print_diag(char *buf, size_t *buf_offset, size_t buf_size, const char *fmt, ...);
+struct dentry *get_debugfs_root_node(void);
+ssize_t blob_read(struct file *file, char __user *user_buffer, size_t count, loff_t *ppos);
+int blob_release(struct inode *inode, struct file *file);
+void init_debugfs(struct fdev *dev);
+void remove_debugfs(struct fdev *dev);
+void create_debugfs_root_nodes(void);
+void remove_debugfs_root_nodes(void);
+
+#endif
drivers/gpu/drm/xe/fabric/dev_diag.c new file +723 -0

723 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/dev_diag.h new file +15 -0
new file mode 100644
index 0000000000000..f42aea854c6d2
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright(c) 2022 Intel Corporation.
+ *
+ */
+
+#ifndef DEV_DIAG_H_INCLUDED
+#define DEV_DIAG_H_INCLUDED
+
+#include "iaf_drv.h"
+
+void create_optional_dev_debugfs_files(struct fsubdev *sd);
+void create_dev_debugfs_dir(struct fsubdev *sd);
+
+#endif
drivers/gpu/drm/xe/fabric/error.c new file +1490 -0

1,490 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/error.h new file +15 -0
new file mode 100644
index 0000000000000..0033f56326110
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright(c) 2022 Intel Corporation.
+ *
+ */
+
+#ifndef IAF_ERROR_H_INCLUDED
+#define IAF_ERROR_H_INCLUDED
+
+#include "iaf_drv.h"
+
+void reset_errors(struct fsubdev *sd);
+
+#endif /* IAF_ERROR_H_INCLUDED */
+
drivers/gpu/drm/xe/fabric/fw.c new file +2089 -0

15 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/fw.h new file +21 -0
new file mode 100644
index 0000000000000..4562e7eecedf4

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/iaf_drv.h new file +1341 -0

1,341 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/iaf_netlink.h new file +208 -0

208 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/io.h new file +82 -0

82 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/main.c new file +1098 -0

1,098 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/mbdb.c new file +1173 -0

1,173 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/mbdb.h new file +171 -0

171 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/mbox.c new file +440 -0

440 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/mbox.h new file +18 -0
new file mode 100644
index 0000000000000..3ba4fcec822b7

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/mei_iaf_user.c new file +440 -0

440 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/mei_iaf_user.h new file +19 -0
new file mode 100644
index 0000000000000..0d70044d1d55e

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/netlink.c new file +1532 -0

1,532 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/netlink.h new file +15 -0
new file mode 100644
index 0000000000000..ba06575917d26

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/ops.c new file +1476 -0

1,476 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/ops.h new file +525 -0

525 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/parallel.c new file +96 -0

96 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/parallel.h new file +33 -0
new file mode 100644
index 0000000000000..22d554b9f7ac4

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/port.c new file +1884 -0

1,884 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/port.h new file +41 -0

41 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/port_diag.c new file +1892 -0

1,892 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/port_diag.h new file +19 -0
new file mode 100644
index 0000000000000..3091b89eeb8fb

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/routing_debug.c new file +484 -0

484 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/routing_debug.h new file +16 -0
new file mode 100644
index 0000000000000..e22601f9011ea

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/routing_engine.c new file +565 -0

565 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/routing_engine.h new file +25 -0
new file mode 100644
index 0000000000000..76223f2731252

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/routing_event.c new file +249 -0

249 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/routing_event.h new file +19 -0
new file mode 100644
index 0000000000000..85bc6789135f2

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/routing_io.c new file +496 -0

496 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/routing_io.h new file +15 -0
new file mode 100644
index 0000000000000..c3a6769690250

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/routing_logic.c new file +934 -0

934 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/routing_logic.h new file +16 -0
new file mode 100644
index 0000000000000..771b35bf513ad

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/routing_p2p.c new file +883 -0

883 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/routing_p2p.h new file +22 -0
new file mode 100644
index 0000000000000..cf8742ea5fef5

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/routing_pause.c new file +282 -0

282 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/routing_pause.h new file +16 -0
new file mode 100644
index 0000000000000..5b878c8dfea4d

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/routing_topology.c new file +200 -0

200 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/routing_topology.h new file +376 -0

376 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/selftests/routing_mock.c new file +291 -0

291 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/selftests/routing_mock.h new file +22 -0
new file mode 100644
index 0000000000000..a8d39f81dd9d9

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/selftests/routing_selftest.c new file +424 -0

424 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/selftests/routing_selftest.h new file +12 -0
new file mode 100644
index 0000000000000..7a9efc431cdad

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/selftests/selftest.c new file +73 -0

73 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/selftests/selftest.h new file +34 -0
new file mode 100644
index 0000000000000..c29a703e8081f

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/statedump.c new file +283 -0

283 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/statedump.h new file +32 -0
new file mode 100644
index 0000000000000..c23d529168fb7

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/sysfs.c new file +327 -0

327 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/sysfs.h new file +16 -0
new file mode 100644
index 0000000000000..059a89a31b0a1

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/trace.c new file +8 -0
new file mode 100644
index 0000000000000..d22f04a5de78b

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/trace.h new file +11 -0
new file mode 100644
index 0000000000000..8503b6fb50639

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/xe/fabric/trace_mbx.h new file +99 -0

99 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/trace_nl.h new file +54 -0

54 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/trace_pm.h new file +102 -0

102 lines not on this page · raw message

drivers/gpu/drm/xe/fabric/trace_rt.h new file +110 -0

110 lines not on this page · raw message

include/drm/intel/intel_iaf_platform.h new file +145 -0

145 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.45.2

Part of the diff is not shown here. View the raw message.

#5 lore raw

RFC PATCH 5/8 drm/xe: Add support for IAF devices.

In reply to Maarten Lankhorst

Use the AUX bus interface to connect to the intel fabric device. This code is based on intel-gpu-backports tag I915_25WW18.2_1099.17_25.1.17_250113.16

---
 drivers/gpu/drm/xe/Makefile          |   1 +
 drivers/gpu/drm/xe/regs/xe_gt_regs.h |  23 ++
 drivers/gpu/drm/xe/xe_device.c       |  12 +-
 drivers/gpu/drm/xe/xe_device_types.h |   3 +
 drivers/gpu/drm/xe/xe_gt_types.h     |   3 +
 drivers/gpu/drm/xe/xe_iaf.c          | 405 +++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_iaf.h          |  57 ++++
 drivers/gpu/drm/xe/xe_irq.c          |  16 +-
 drivers/gpu/drm/xe/xe_vram.c         |   4 +-
 9 files changed, 520 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/xe_iaf.c
 create mode 100644 drivers/gpu/drm/xe/xe_iaf.h
drivers/gpu/drm/xe/Makefile +1 -0
index 7b6fee7fd1a65..a83f3c775f3a5 100644
@@ -74,6 +74,7 @@ xe-y += xe_bb.o \
 	xe_hw_engine_class_sysfs.o \
 	xe_hw_engine_group.o \
 	xe_hw_fence.o \
+	xe_iaf.o \
 	xe_irq.o \
 	xe_lrc.o \
 	xe_migrate.o \
drivers/gpu/drm/xe/regs/xe_gt_regs.h +23 -0
index 5cd5ab8529c5c..0d436947ff81f 100644
@@ -85,6 +85,11 @@
 #define XE2_GAMREQSTRM_CTRL			XE_REG_MCR(0x4194)
 #define   CG_DIS_CNTLBUS			REG_BIT(6)
 
+#define PKG_ADDR_RANGE				XE_REG(0x41B0)
+#define   PKG_ADDR_RANGE_RANGE_SHIFT		20
+#define   PKG_ADDR_RANGE_BASE_SHIFT		1
+#define   PKG_ADDR_RANGE_ENABLE			1
+
 #define CCS_AUX_INV				XE_REG(0x4208)
 
 #define VD0_AUX_INV				XE_REG(0x4218)
@@ -96,6 +101,11 @@
 #define XE2_LMEM_CFG				XE_REG(0x48b0)
 
 #define XEHP_TILE_ADDR_RANGE(_idx)		XE_REG_MCR(0x4900 + (_idx) * 4)
+#define   XEHP_TILE_LMEM_RANGE_SHIFT            8
+#define   XEHP_TILE_LMEM_BASE_SHIFT             1
+#define   XEHP_TILE_LMEM_BASE_MASK              REG_GENMASK(7, 1)
+#define   XEHP_TILE_LMEM_RANGE_MASK             REG_GENMASK(14, 8)
+
 #define XEHP_FLAT_CCS_BASE_ADDR			XE_REG_MCR(0x4910)
 #define XEHP_FLAT_CCS_PTR			REG_GENMASK(31, 8)
 
@@ -560,6 +570,11 @@
 #define   CCS_MODE_CSLICE(cslice, ccs) \
 	((ccs) << ((cslice) * CCS_MODE_CSLICE_WIDTH))
 
+#define PKG_ADDR_BASE				XE_REG(0x108390)
+#define   PKG_ADDR_BASE_RANGE_SHIFT		20
+#define   PKG_ADDR_BASE_BASE_SHIFT		1
+#define   PKG_ADDR_BASE_ENABLE			1
+
 #define FORCEWAKE_ACK_GT			XE_REG(0x130044)
 
 /* Applicable for all FORCEWAKE_DOMAIN and FORCEWAKE_ACK_DOMAIN regs */
@@ -594,4 +609,12 @@
 
 #define SFC_DONE(n)				XE_REG(0x1cc000 + (n) * 0x1000)
 
+#define PUNIT_MMIO_CR_POC_STRAPS		XE_REG(0x281078)
+#define NUM_TILES_MASK				REG_GENMASK(1, 0)
+#define CD_ALIVE				REG_BIT(2)
+#define SOCKET_ID_MASK				REG_GENMASK(7, 3)
+
+#define CD_BASE_OFFSET				0x291000
+#define CD_BAR_LENGTH				0x40000
+
 #endif
drivers/gpu/drm/xe/xe_device.c +11 -1
index c7d50b098b5cb..9d4a3f3f3bbf1 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: MIT
 /*
- * Copyright © 2021 Intel Corporation
+ * Copyright © 2021 - 2025 Intel Corporation
  */
 
 #include "xe_device.h"
@@ -43,6 +43,7 @@
 #include "xe_hw_engine_group.h"
 #include "xe_hwmon.h"
 #include "xe_irq.h"
+#include "xe_iaf.h"
 #include "xe_memirq.h"
 #include "xe_mmio.h"
 #include "xe_module.h"
@@ -841,6 +842,11 @@ int xe_device_probe(struct xe_device *xe)
 	if (err)
 		return err;
 
+	/* Needs to be called before xe_vram_probe() */
+	err = xe_iaf_init(xe);
+	if (err)
+		return err;
+
 	err = xe_vram_probe(xe);
 	if (err)
 		return err;
@@ -918,6 +924,10 @@ int xe_device_probe(struct xe_device *xe)
 	if (err)
 		goto err_unregister_display;
 
+	err = xe_iaf_init_aux(xe);
+	if (err)
+		goto err_unregister_display;
+
 	xe_debugfs_register(xe);
 
 	err = xe_hwmon_register(xe);
drivers/gpu/drm/xe/xe_device_types.h +3 -0
index 6bb8f5487c3a0..6998ee0b1a220 100644
@@ -590,6 +590,9 @@ struct xe_device {
 	u8 vm_inject_error_position;
 #endif
 
+	/** @iaf: Fabric specific struct */
+	struct xe_iaf *iaf;
+
 	/* private: */
 
 #if IS_ENABLED(CONFIG_DRM_XE_DISPLAY)
drivers/gpu/drm/xe/xe_gt_types.h +3 -0
index 7def0959da35d..331b726f7c562 100644
@@ -445,6 +445,9 @@ struct xe_gt {
 
 	/** @eu_stall: EU stall counters subsystem per gt info */
 	struct xe_eu_stall_gt *eu_stall;
+
+	/** @iaf_irq: IRQ value for IAF interrupts to be raised */
+	int iaf_irq;
 };
 
 #endif
drivers/gpu/drm/xe/xe_iaf.c new file +405 -0

405 lines not on this page · raw message

drivers/gpu/drm/xe/xe_iaf.h new file +57 -0

57 lines not on this page · raw message

drivers/gpu/drm/xe/xe_irq.c +15 -1
index 5362d3174b060..439748987168e 100644
@@ -1,10 +1,11 @@
 // SPDX-License-Identifier: MIT
 /*
- * Copyright © 2021 Intel Corporation
+ * Copyright © 2021 - 2025 Intel Corporation
  */
 
 #include "xe_irq.h"
 
+#include <linux/irq.h>
 #include <linux/sched/clock.h>
 
 #include <drm/drm_managed.h>
@@ -31,6 +32,9 @@
 #define IIR(offset)				XE_REG(offset + 0x8)
 #define IER(offset)				XE_REG(offset + 0xc)
 
+#define GEN12_IAF_IRQ BIT(8)
+#define CPORT_MBDB_INT_ENABLE_MASK		XE_REG(0x297008)
+
 static int xe_irq_msix_init(struct xe_device *xe);
 static void xe_irq_msix_free(struct xe_device *xe);
 static int xe_irq_msix_request_irqs(struct xe_device *xe);
@@ -419,6 +423,12 @@ static void dg1_intr_enable(struct xe_device *xe, bool stall)
 		xe_mmio_read32(mmio, DG1_MSTR_TILE_INTR);
 }
 
+static void iaf_irq_handler(struct xe_gt *gt, const u32 master_ctl)
+{
+	if (master_ctl & GEN12_IAF_IRQ)
+		generic_handle_irq(gt->iaf_irq);
+}
+
 /*
  * Top-level interrupt handler for Xe_LP+ and beyond.  These platforms have
  * a "master tile" interrupt register which must be consulted before the
@@ -478,6 +488,7 @@ static irqreturn_t dg1_irq_handler(int irq, void *arg)
 			xe_display_irq_handler(xe, master_ctl);
 			gu_misc_iir = gu_misc_irq_ack(xe, master_ctl);
 		}
+		iaf_irq_handler(tile->primary_gt, master_ctl);
 	}
 
 	dg1_intr_enable(xe, false);
@@ -534,6 +545,9 @@ static void gt_irq_reset(struct xe_tile *tile)
 	xe_mmio_write32(mmio, GPM_WGBOXPERF_INTR_MASK,  ~0);
 	xe_mmio_write32(mmio, GUC_SG_INTR_ENABLE,	 0);
 	xe_mmio_write32(mmio, GUC_SG_INTR_MASK,		~0);
+
+	if (tile_to_xe(tile)->iaf)
+		xe_mmio_write32(mmio, CPORT_MBDB_INT_ENABLE_MASK, 0);
 }
 
 static void xelp_irq_reset(struct xe_tile *tile)
drivers/gpu/drm/xe/xe_vram.c +2 -2
index e421a74fb87c6..e4e4fdb62c82a 100644
@@ -16,6 +16,7 @@
 #include "xe_force_wake.h"
 #include "xe_gt_mcr.h"
 #include "xe_gt_sriov_vf.h"
+#include "xe_iaf.h"
 #include "xe_mmio.h"
 #include "xe_module.h"
 #include "xe_sriov.h"
@@ -152,8 +153,7 @@ static int determine_lmem_bar_size(struct xe_device *xe)
 	if (!xe->mem.vram.io_size)
 		return -EIO;
 
-	/* XXX: Need to change when xe link code is ready */
-	xe->mem.vram.dpa_base = 0;
+	xe->mem.vram.dpa_base = xe_iaf_dpa_base(xe);
 
 	/* set up a map to the total memory area. */
 	xe->mem.vram.mapping = ioremap_wc(xe->mem.vram.io_start, xe->mem.vram.io_size);
Signature · 1 line
2.45.2
#6 lore raw

RFC PATCH 6/8 drm/xe/uapi: Add query ioctl for fabric connectivity

In reply to Maarten Lankhorst

UMDs need to understand if two devices have connectivity, and what that connectivity is.

Add to the query_ioctl the ability to determine if a fabric id and current device have connectivity.

---
 drivers/gpu/drm/xe/xe_iaf.c   | 13 ++++++++
 drivers/gpu/drm/xe/xe_iaf.h   |  9 ++++++
 drivers/gpu/drm/xe/xe_query.c | 58 +++++++++++++++++++++++++++++++++++
 include/uapi/drm/xe_drm.h     | 32 +++++++++++++++++++
 4 files changed, 112 insertions(+)
drivers/gpu/drm/xe/xe_iaf.c +13 -0
index d93b13d30fbcd..431d20fea5369 100644
@@ -403,3 +403,16 @@ u64 xe_iaf_dpa_base(struct xe_device *xe)
 	return xe->iaf->dpa;
 }
 
+struct query_info *xe_iaf_connectivity_query(struct xe_iaf *iaf, u32 fabric_id)
+{
+	if (!iaf)
+		return ERR_PTR(-ENODEV);
+
+	if (iaf->fabric_id == fabric_id)
+		return NULL;
+
+	if (!iaf->ops)
+		return ERR_PTR(-EOPNOTSUPP);
+
+	return iaf->ops->connectivity_query(iaf->handle, fabric_id);
+}
drivers/gpu/drm/xe/xe_iaf.h +9 -0
index 78d7cca447983..df6b8f9f2bc5f 100644
@@ -8,6 +8,9 @@
 
 #include <linux/types.h>
 
+struct query_info;
+struct xe_iaf;
+
 /*
  * Define the maximum number of devices instances based on the amount of
  * FID space.
@@ -34,6 +37,7 @@ struct xe_device;
 int xe_iaf_init(struct xe_device *xe);
 int xe_iaf_init_aux(struct xe_device *xe);
 u64 xe_iaf_dpa_base(struct xe_device *xe);
+struct query_info *xe_iaf_connectivity_query(struct xe_iaf *iaf, u32 fabric_id);
 
 #else
 
@@ -52,6 +56,11 @@ static inline u64 xe_iaf_dpa_base(struct xe_device *xe)
 	return 0ULL;
 }
 
+struct query_info *xe_iaf_connectivity_query(struct xe_iaf *iaf, u32 fabric_id)
+{
+	return ERR_PTR(-ENODEV);
+}
+
 #endif
 
 #endif
drivers/gpu/drm/xe/xe_query.c +58 -0

82 lines not on this page · raw message

include/uapi/drm/xe_drm.h +32 -0
index 6a702ba7817c3..9d30876cc8e91 100644
@@ -668,6 +668,33 @@ struct drm_xe_query_pxp_status {
 	__u32 supported_session_types;
 };
 
+/**
+ * struct drm_xe_query_fabric_info
+ *
+ * With the given fabric id, query fabric info wrt the device.
+ * Higher bandwidth is better.  0 means no fabric.
+ * Latency is averaged latency (from all paths)
+ *
+ * fabric_id can be obtained from
+ *    /sys/class/drm/cardx/device/iaf.y/iaf_fabric_id
+ * Bandwidth is in Gigabits per second (max value of 8 * 4 * 90)
+ *    8 possible ports
+ *    4 lanes max per port
+ *   90 gigabits per lane
+ * Latency is in tenths of path length. 10 == 1 fabric link between src and dst
+ *   POR is max 1 link (zero hops).
+ */
+struct drm_xe_query_fabric_info {
+	/** @fabric_id: (in) Fabric id associated with info */
+	__u32 fabric_id;
+	/** @bandwidth: minimum bandwidth of all connected ports, if 0 no fabric */
+	__u32 bandwidth;
+	/** @latency: latency averaged across all connected ports. */
+	__u32 latency;
+	/** @pad: MBZ */
+	__u32 pad;
+};
+
 /**
  * struct drm_xe_device_query - Input of &DRM_IOCTL_XE_DEVICE_QUERY - main
  * structure to query device information
@@ -687,7 +714,11 @@ struct drm_xe_query_pxp_status {
  *    attributes.
  *  - %DRM_XE_DEVICE_QUERY_GT_TOPOLOGY
  *  - %DRM_XE_DEVICE_QUERY_ENGINE_CYCLES
+ *  - %DRM_XE_DEVICE_QUERY_UC_FW_VERSION
+ *  - %DRM_XE_DEVICE_QUERY_OA_UNITS
  *  - %DRM_XE_DEVICE_QUERY_PXP_STATUS
+ *  - %DRM_XE_DEVICE_QUERY_EU_STALL
+ *  - %DRM_XE_DEVICE_QUERY_FABRIC_INFO
  *
  * If size is set to 0, the driver fills it with the required size for
  * the requested type of data to query. If size is equal to the required
@@ -742,6 +773,7 @@ struct drm_xe_device_query {
 #define DRM_XE_DEVICE_QUERY_OA_UNITS		8
 #define DRM_XE_DEVICE_QUERY_PXP_STATUS		9
 #define DRM_XE_DEVICE_QUERY_EU_STALL		10
+#define DRM_XE_DEVICE_QUERY_FABRIC_INFO		11
 	/** @query: The type of data to query */
 	__u32 query;
 
Signature · 1 line
2.45.2
#7 lore raw

RFC PATCH 7/8 drm/xe: Remove unused XE_DEFAULT_GTT_SIZE_MB definition.

In reply to Maarten Lankhorst

The #define went unused since mid 2023, remove it. Relevant commit: 1a545ed74b33 ("drm/xe: fix pvc unload issue")

---
 drivers/gpu/drm/xe/xe_bo.h | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/xe/xe_bo.h +0 -2
index 02ada1fb8a235..ecb5fe3b1c1dc 100644
@@ -13,8 +13,6 @@
 #include "xe_vm_types.h"
 #include "xe_vm.h"
 
-#define XE_DEFAULT_GTT_SIZE_MB          3072ULL /* 3GB by default */
-
 #define XE_BO_FLAG_USER		BIT(0)
 /* The bits below need to be contiguous, or things break */
 #define XE_BO_FLAG_SYSTEM		BIT(1)
Signature · 1 line
2.45.2
#8 lore raw

RFC PATCH 8/8 drm/xe: Allow mapping DMA-BUF buffer objects connected through IAF

In reply to Maarten Lankhorst

IAF allows multiple xe devices to import VRAM from each other. It's mapped as local VRAM, but outside the local device range.

To support this, Xe is changed to allow a special case of same-implementation importing with direction = DMA_NONE.

If this DMA direction is used, the physical VRAM addresses are exported, and can be imported into a xe_vm with the device memory bit set.

In order to prevent bugs, we ensure that this is only allowed for xe <-> xe imports/exports, and only when the VRAM flag is set.

If any of the steps required fails for IAF-import, the default non-IAF import path is attempted.

---
 drivers/gpu/drm/xe/xe_bo.c           | 85 ++++++++++++++++++++++++----
 drivers/gpu/drm/xe/xe_bo.h           |  2 +
 drivers/gpu/drm/xe/xe_dma_buf.c      | 27 ++++++++-
 drivers/gpu/drm/xe/xe_dma_buf.h      |  1 +
 drivers/gpu/drm/xe/xe_ggtt.c         |  4 +-
 drivers/gpu/drm/xe/xe_iaf.c          | 42 ++++++++++++++
 drivers/gpu/drm/xe/xe_iaf.h          | 16 ++++++
 drivers/gpu/drm/xe/xe_pt.c           |  4 ++
 drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 23 +++++---
 drivers/gpu/drm/xe/xe_vm.c           |  2 +-
 10 files changed, 184 insertions(+), 22 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +75 -10
index 4e39188a021ab..13f0c685a012f 100644
@@ -24,6 +24,7 @@
 #include "xe_drm_client.h"
 #include "xe_ggtt.h"
 #include "xe_gt.h"
+#include "xe_iaf.h"
 #include "xe_map.h"
 #include "xe_migrate.h"
 #include "xe_pm.h"
@@ -82,6 +83,11 @@ bool mem_type_is_vram(u32 mem_type)
 	return mem_type >= XE_PL_VRAM0 && mem_type != XE_PL_STOLEN;
 }
 
+bool xe_bo_is_iaf(struct xe_bo *bo)
+{
+	return bo->flags & XE_BO_FLAG_IAF;
+}
+
 static bool resource_is_stolen_vram(struct xe_device *xe, struct ttm_resource *res)
 {
 	return res->mem_type == XE_PL_STOLEN && IS_DGFX(xe);
@@ -656,6 +662,68 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 	return ret;
 }
 
+static void bo_unmap_dma_buf(struct xe_bo *bo)
+{
+	enum dma_data_direction dir = DMA_BIDIRECTIONAL;
+	struct dma_buf_attachment *attach = bo->ttm.base.import_attach;
+	struct dma_buf *dmabuf;
+
+	if (xe_bo_is_iaf(bo))
+		dir = DMA_NONE;
+
+	dma_buf_unmap_attachment(attach, bo->ttm.sg, dir);
+	bo->ttm.sg = NULL;
+
+	if (xe_bo_is_iaf(bo)) {
+		/* Cleanup IAF bindings */
+		dmabuf = attach->dmabuf;
+		xe_iaf_mapping_put(xe_bo_device(gem_to_xe_bo(dmabuf->priv))->iaf);
+		xe_iaf_mapping_put(xe_bo_device(bo)->iaf);
+		bo->flags &= ~XE_BO_FLAG_IAF;
+	}
+}
+
+static struct sg_table *bo_map_dma_buf(struct xe_bo *bo)
+{
+	struct dma_buf_attachment *attach = bo->ttm.base.import_attach;
+	struct dma_buf *dmabuf = attach->dmabuf;
+	struct sg_table *sg;
+
+	if (is_xe_dma_buf(dmabuf)) {
+		struct xe_device *src = xe_bo_device(gem_to_xe_bo(dmabuf->priv));
+		struct xe_device *dst = xe_bo_device(bo);
+		int err;
+
+		if (!xe_iaf_fabrics_connected(dst->iaf, src->iaf))
+			goto no_iaf;
+
+		err = xe_iaf_mapping_get(dst->iaf);
+		if (err) {
+			drm_warn(&dst->drm, "Getting DST IAF mapping ref failed with %pe", ERR_PTR(err));
+			goto no_iaf;
+		}
+
+		err = xe_iaf_mapping_get(src->iaf);
+		if (err) {
+			drm_warn(&src->drm, "Getting SRC IAF mapping ref failed with %pe", ERR_PTR(err));
+			goto err_put_dst;
+		}
+
+		sg = dma_buf_map_attachment(attach, DMA_NONE);
+		if (!IS_ERR(sg)) {
+			bo->flags |= XE_BO_FLAG_IAF;
+			return sg;
+		}
+
+		xe_iaf_mapping_put(src->iaf);
+err_put_dst:
+		xe_iaf_mapping_put(dst->iaf);
+	}
+
+no_iaf:
+	return dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
+}
+
 /*
  * The dma-buf map_attachment() / unmap_attachment() is hooked up here.
  * Note that unmapping the attachment is deferred to the next
@@ -665,9 +733,9 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
  * backing store out. Should that assumption not hold, then we will be able
  * to unconditionally call unmap_attachment() when moving out to system.
  */
-static int xe_bo_move_dmabuf(struct ttm_buffer_object *ttm_bo,
-			     struct ttm_resource *new_res)
+static int xe_bo_move_dmabuf(struct xe_bo *bo, struct ttm_resource *new_res)
 {
+	struct ttm_buffer_object *ttm_bo = &bo->ttm;
 	struct dma_buf_attachment *attach = ttm_bo->base.import_attach;
 	struct xe_ttm_tt *xe_tt = container_of(ttm_bo->ttm, struct xe_ttm_tt,
 					       ttm);
@@ -682,19 +750,16 @@ static int xe_bo_move_dmabuf(struct ttm_buffer_object *ttm_bo,
 	    ttm_bo->sg) {
 		dma_resv_wait_timeout(ttm_bo->base.resv, DMA_RESV_USAGE_BOOKKEEP,
 				      false, MAX_SCHEDULE_TIMEOUT);
-		dma_buf_unmap_attachment(attach, ttm_bo->sg, DMA_BIDIRECTIONAL);
-		ttm_bo->sg = NULL;
+		bo_unmap_dma_buf(bo);
 	}
 
 	if (new_res->mem_type == XE_PL_SYSTEM)
 		goto out;
 
-	if (ttm_bo->sg) {
-		dma_buf_unmap_attachment(attach, ttm_bo->sg, DMA_BIDIRECTIONAL);
-		ttm_bo->sg = NULL;
-	}
+	if (ttm_bo->sg)
+		bo_unmap_dma_buf(bo);
 
-	sg = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
+	sg = bo_map_dma_buf(bo);
 	if (IS_ERR(sg))
 		return PTR_ERR(sg);
 
@@ -797,7 +862,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
 	if (ttm_bo->type == ttm_bo_type_sg) {
 		ret = xe_bo_move_notify(bo, ctx);
 		if (!ret)
-			ret = xe_bo_move_dmabuf(ttm_bo, new_mem);
+			ret = xe_bo_move_dmabuf(bo, new_mem);
 		return ret;
 	}
 
drivers/gpu/drm/xe/xe_bo.h +2 -0
index ecb5fe3b1c1dc..210ee49d6a04d 100644
@@ -44,6 +44,7 @@
 #define XE_BO_FLAG_GGTT2		BIT(22)
 #define XE_BO_FLAG_GGTT3		BIT(23)
 #define XE_BO_FLAG_CPU_ADDR_MIRROR	BIT(24)
+#define XE_BO_FLAG_IAF			BIT(25)
 
 /* this one is trigger internally only */
 #define XE_BO_FLAG_INTERNAL_TEST	BIT(30)
@@ -262,6 +263,7 @@ void xe_bo_vunmap(struct xe_bo *bo);
 int xe_bo_read(struct xe_bo *bo, u64 offset, void *dst, int size);
 
 bool mem_type_is_vram(u32 mem_type);
+bool xe_bo_is_iaf(struct xe_bo *bo);
 bool xe_bo_is_vram(struct xe_bo *bo);
 bool xe_bo_is_stolen(struct xe_bo *bo);
 bool xe_bo_is_stolen_devmem(struct xe_bo *bo);
drivers/gpu/drm/xe/xe_dma_buf.c +24 -3
index 346f857f38374..2e8aca5d572ae 100644
@@ -86,6 +86,8 @@ static void xe_dma_buf_unpin(struct dma_buf_attachment *attach)
 	xe_bo_unpin_external(bo);
 }
 
+static const struct dma_buf_attach_ops xe_dma_buf_attach_ops;
+
 static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach,
 				       enum dma_data_direction dir)
 {
@@ -94,12 +96,21 @@ static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach,
 	struct xe_bo *bo = gem_to_xe_bo(obj);
 	struct sg_table *sgt;
 	int r = 0;
+	bool iaf = false;
+
+	if (dir == DMA_NONE) {
+		if (attach->importer_ops != &xe_dma_buf_attach_ops)
+			return ERR_PTR(-EOPNOTSUPP);
+
+		iaf = true;
+	}
 
-	if (!attach->peer2peer && !xe_bo_can_migrate(bo, XE_PL_TT))
+	if (!attach->peer2peer && !iaf &&
+	    !xe_bo_can_migrate(bo, XE_PL_TT))
 		return ERR_PTR(-EOPNOTSUPP);
 
 	if (!xe_bo_is_pinned(bo)) {
-		if (!attach->peer2peer)
+		if (!attach->peer2peer && !iaf)
 			r = xe_bo_migrate(bo, XE_PL_TT);
 		else
 			r = xe_bo_validate(bo, NULL, false);
@@ -109,6 +120,10 @@ static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach,
 
 	switch (bo->ttm.resource->mem_type) {
 	case XE_PL_TT:
+		/* IAF only available for VRAM */
+		if (iaf)
+			return ERR_PTR(-EOPNOTSUPP);
+
 		sgt = drm_prime_pages_to_sg(obj->dev,
 					    bo->ttm.ttm->pages,
 					    bo->ttm.ttm->num_pages);
@@ -146,7 +161,8 @@ static void xe_dma_buf_unmap(struct dma_buf_attachment *attach,
 			     enum dma_data_direction dir)
 {
 	if (sg_page(sgt->sgl)) {
-		dma_unmap_sgtable(attach->dev, sgt, dir, 0);
+		if (dir != DMA_NONE)
+			dma_unmap_sgtable(attach->dev, sgt, dir, 0);
 		sg_free_table(sgt);
 		kfree(sgt);
 	} else {
@@ -187,6 +203,11 @@ static const struct dma_buf_ops xe_dmabuf_ops = {
 	.vunmap = drm_gem_dmabuf_vunmap,
 };
 
+bool is_xe_dma_buf(struct dma_buf *dma_buf)
+{
+	return dma_buf->ops == &xe_dmabuf_ops;
+}
+
 struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags)
 {
 	struct xe_bo *bo = gem_to_xe_bo(obj);
drivers/gpu/drm/xe/xe_dma_buf.h +1 -0
index 861dd28a862c7..80d12c624b921 100644
@@ -11,5 +11,6 @@
 struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags);
 struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
 					   struct dma_buf *dma_buf);
+bool is_xe_dma_buf(struct dma_buf *dma_buf);
 
 #endif
drivers/gpu/drm/xe/xe_ggtt.c +3 -1
index b8e1b44452e4d..c6ff18deb9db1 100644
@@ -122,7 +122,9 @@ static u64 xelp_ggtt_pte_flags(struct xe_bo *bo, u16 pat_index)
 {
 	u64 pte = XE_PAGE_PRESENT;
 
-	if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo))
+	if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo) ||
+	    /* It's likely legal to map IAF to GGTT, but it should be impossible? */
+	    drm_WARN_ON(bo->ttm.base.dev, xe_bo_is_iaf(bo)))
 		pte |= XE_GGTT_PTE_DM;
 
 	return pte;
drivers/gpu/drm/xe/xe_iaf.c +42 -0

45 lines not on this page · raw message

drivers/gpu/drm/xe/xe_iaf.h +16 -0
index df6b8f9f2bc5f..b8e75640e8967 100644
@@ -38,6 +38,9 @@ int xe_iaf_init(struct xe_device *xe);
 int xe_iaf_init_aux(struct xe_device *xe);
 u64 xe_iaf_dpa_base(struct xe_device *xe);
 struct query_info *xe_iaf_connectivity_query(struct xe_iaf *iaf, u32 fabric_id);
+bool xe_iaf_fabrics_connected(struct xe_iaf *src, struct xe_iaf *dst);
+int xe_iaf_mapping_get(struct xe_iaf *iaf);
+void xe_iaf_mapping_put(struct xe_iaf *iaf);
 
 #else
 
@@ -61,6 +64,19 @@ struct query_info *xe_iaf_connectivity_query(struct xe_iaf *iaf, u32 fabric_id)
 	return ERR_PTR(-ENODEV);
 }
 
+static inline int xe_iaf_mapping_get(struct xe_iaf *iaf)
+{
+	return -ENODEV;
+}
+
+static inline void xe_iaf_mapping_put(struct xe_iaf *iaf)
+{}
+
+static inline bool xe_iaf_fabrics_connected(struct xe_iaf *src, struct xe_iaf *dst)
+{
+	return false;
+}
+
 #endif
 
 #endif
drivers/gpu/drm/xe/xe_pt.c +4 -0
index f39d5cc9f411e..2231882b2bc45 100644
@@ -764,6 +764,10 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
 		else
 			xe_res_first_sg(xe_bo_sg(bo), xe_vma_bo_offset(vma),
 					xe_vma_size(vma), &curs);
+
+		/* When IAF is used, the bo requires the DM flag */
+		if (xe_bo_is_iaf(bo))
+			curs.mem_type = XE_PL_VRAM0;
 	} else if (!range) {
 		curs.size = xe_vma_size(vma);
 	}
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +16 -7
index 9e375a40aee90..94a572693e139 100644
@@ -396,11 +396,16 @@ int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe,
 		size_t size = min_t(u64, cursor.size, SZ_2G);
 		dma_addr_t addr;
 
-		addr = dma_map_resource(dev, phys, size, dir,
-					DMA_ATTR_SKIP_CPU_SYNC);
-		r = dma_mapping_error(dev, addr);
-		if (r)
-			goto error_unmap;
+		if (valid_dma_direction(dir)) {
+			addr = dma_map_resource(dev, phys, size, dir,
+						DMA_ATTR_SKIP_CPU_SYNC);
+			r = dma_mapping_error(dev, addr);
+			if (r)
+				goto error_unmap;
+		} else {
+			/* Only want the SG table for fabric */
+			addr = cursor.start + tile->mem.vram.dpa_base;
+		}
 
 		sg_set_page(sg, NULL, size, 0);
 		sg_dma_address(sg) = addr;
@@ -413,7 +418,7 @@ int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe,
 
 error_unmap:
 	for_each_sgtable_sg((*sgt), sg, i) {
-		if (!sg->length)
+		if (!sg->length || !valid_dma_direction(dir))
 			continue;
 
 		dma_unmap_resource(dev, sg->dma_address,
@@ -433,10 +438,14 @@ void xe_ttm_vram_mgr_free_sgt(struct device *dev, enum dma_data_direction dir,
 	struct scatterlist *sg;
 	int i;
 
-	for_each_sgtable_sg(sgt, sg, i)
+	for_each_sgtable_sg(sgt, sg, i) {
+		if (!valid_dma_direction(dir))
+			continue;
+
 		dma_unmap_resource(dev, sg->dma_address,
 				   sg->length, dir,
 				   DMA_ATTR_SKIP_CPU_SYNC);
+	}
 	sg_free_table(sgt);
 	kfree(sgt);
 }
drivers/gpu/drm/xe/xe_vm.c +1 -1
index 18f967ce1f1a6..f3dd38c95deb5 100644
@@ -1534,7 +1534,7 @@ static u64 xelp_pte_encode_bo(struct xe_bo *bo, u64 bo_offset,
 	pte |= pte_encode_pat_index(pat_index, pt_level);
 	pte |= pte_encode_ps(pt_level);
 
-	if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo))
+	if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo) || xe_bo_is_iaf(bo))
 		pte |= XE_PPGTT_PTE_DM;
 
 	return pte;
Signature · 1 line
2.45.2
#9 lore raw

Re: [RFC PATCH 8/8] drm/xe: Allow mapping DMA-BUF buffer objects connected through IAF

Quoted 80 lines · Maarten Lankhorst

IAF allows multiple xe devices to import VRAM from each other. It's mapped as local VRAM, but outside the local device range.

To support this, Xe is changed to allow a special case of same-implementation importing with direction = DMA_NONE.

If this DMA direction is used, the physical VRAM addresses are exported, and can be imported into a xe_vm with the device memory bit set.

In order to prevent bugs, we ensure that this is only allowed for xe <-> xe imports/exports, and only when the VRAM flag is set.

If any of the steps required fails for IAF-import, the default non-IAF import path is attempted.

---
 drivers/gpu/drm/xe/xe_bo.c           | 85 ++++++++++++++++++++++++----
 drivers/gpu/drm/xe/xe_bo.h           |  2 +
 drivers/gpu/drm/xe/xe_dma_buf.c      | 27 ++++++++-
 drivers/gpu/drm/xe/xe_dma_buf.h      |  1 +
 drivers/gpu/drm/xe/xe_ggtt.c         |  4 +-
 drivers/gpu/drm/xe/xe_iaf.c          | 42 ++++++++++++++
 drivers/gpu/drm/xe/xe_iaf.h          | 16 ++++++
 drivers/gpu/drm/xe/xe_pt.c           |  4 ++
 drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 23 +++++---
 drivers/gpu/drm/xe/xe_vm.c           |  2 +-
 10 files changed, 184 insertions(+), 22 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +29 -0
index 4e39188a021ab..13f0c685a012f 100644
@@ -24,6 +24,7 @@
 #include "xe_drm_client.h"
 #include "xe_ggtt.h"
 #include "xe_gt.h"
+#include "xe_iaf.h"
 #include "xe_map.h"
 #include "xe_migrate.h"
 #include "xe_pm.h"
@@ -82,6 +83,11 @@ bool mem_type_is_vram(u32 mem_type)
 	return mem_type >= XE_PL_VRAM0 && mem_type != XE_PL_STOLEN;
 }
 
+bool xe_bo_is_iaf(struct xe_bo *bo)
+{
+	return bo->flags & XE_BO_FLAG_IAF;
+}
+
 static bool resource_is_stolen_vram(struct xe_device *xe, struct ttm_resource *res)
 {
 	return res->mem_type == XE_PL_STOLEN && IS_DGFX(xe);
@@ -656,6 +662,68 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 	return ret;
 }
 
+static void bo_unmap_dma_buf(struct xe_bo *bo)
+{
+	enum dma_data_direction dir = DMA_BIDIRECTIONAL;
+	struct dma_buf_attachment *attach = bo->ttm.base.import_attach;
+	struct dma_buf *dmabuf;
+
+	if (xe_bo_is_iaf(bo))
+		dir = DMA_NONE;
+
+	dma_buf_unmap_attachment(attach, bo->ttm.sg, dir);
+	bo->ttm.sg = NULL;
+
+	if (xe_bo_is_iaf(bo)) {
+		/* Cleanup IAF bindings */
+		dmabuf = attach->dmabuf;
+		xe_iaf_mapping_put(xe_bo_device(gem_to_xe_bo(dmabuf->priv))->iaf);
+		xe_iaf_mapping_put(xe_bo_device(bo)->iaf);
+		bo->flags &= ~XE_BO_FLAG_IAF;
+	}
+}
+
+static struct sg_table *bo_map_dma_buf(struct xe_bo *bo)
+{

drivers/gpu/drm/xe/xe_bo.c static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, · line 697

Quoted 10 lines
drivers/gpu/drm/xe/xe_bo.c +10 -0
+	struct dma_buf_attachment *attach = bo->ttm.base.import_attach;
+	struct dma_buf *dmabuf = attach->dmabuf;
+	struct sg_table *sg;
+
+	if (is_xe_dma_buf(dmabuf)) {
+		struct xe_device *src = xe_bo_device(gem_to_xe_bo(dmabuf->priv));
+		struct xe_device *dst = xe_bo_device(bo);
+		int err;
+
+		if (!xe_iaf_fabrics_connected(dst->iaf, src->iaf))

Ok, so bunch of comments on the actual interface below, but I also looked at the iaf patches to see how that's all implemented. And it's not the worst hand-rolled locking and refcounting I've seen, but I'm pretty sure it's buggy. Specifically the wait_for_completion_killable() in mappings_ref_wait() means that a simple ^C on module unload or sysfs unbind gives you a nice kernel UAF.

[Aside: the other wait_for_completion_killable() also look equally fishy]

I think the right way to sort that issue out is:

- refcount the structures with a proper kref_t.

- no waiting for access to cease (that needs to be protected by the separate mutex you have, and not dropping that lock between checkis and ref acquisition here is another reason why I think you want a single xe_iaf_() interface that takes care of everything). Instead all functions need to check whether the hw is gone and just bail out in that case.

- You need to nuke all dma_buf mappings with the move_notify stuff. That's needed for p2p dma already anyway, so if that's not there we have bigger issues. IAF just makes this problem bigger.

I think ideally we'd not hand-roll this all, but component doesn't really fit that well for reasons. And I'm not sure anything else exists that makes sense. I've had some chats with amd folks over the years about how to do this all, and it's a ton of work. The important part is to have at least some refcounting instead of only relying on locking, you have that, so for me this is good enough. But the implementation needs to be fixed to not be exploitable with a SIGKILL ;-)

Quoted 5 lines
drivers/gpu/drm/xe/xe_bo.c +5 -0
+			goto no_iaf;
+
+		err = xe_iaf_mapping_get(dst->iaf);
+		if (err) {
+			drm_warn(&dst->drm, "Getting DST IAF mapping ref failed with %pe", ERR_PTR(err));

drivers/gpu/drm/xe/xe_bo.c static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, · line 712

Quoted 10 lines
drivers/gpu/drm/xe/xe_bo.c +10 -0
+			goto no_iaf;
+		}
+
+		err = xe_iaf_mapping_get(src->iaf);
+		if (err) {
+			drm_warn(&src->drm, "Getting SRC IAF mapping ref failed with %pe", ERR_PTR(err));
+			goto err_put_dst;
+		}
+
+		sg = dma_buf_map_attachment(attach, DMA_NONE);

I think this is a bit too much of a hack, especially since you also need to do a bunch of refcounting outside of the dma_buf call, so you definitely have a different contract here. I think much better would be to just have an xe_iaf_map_attachment, which does it all:

	if (is_xe_dma_buf(dmabuf)) {
		err = xe_iaf_map_attachment(attach);
		if (err)
			goto no_iaf;
	}	

I also think there's a missing fallback here for the case where you can't migrate the bo into vram. I guess eventually you want a mode that forces iaf access mode, but that would need to be checked in VM_BIND or similar:
Essentially checking that the placements are vram only and you have iaf connectivity to everything, and you probably also want to grab all the refcounts there.

You might want to split out the bo move into the caller here, depending how the placement hints all work out, but I think that's the only thing you want to pull out from that single function.

Of course the implementation of xe_iaf_map_attachment can and should probably share a lot of code with the map_attachment callback for dma_buf. But that really shouldn't go through the dma_buf layer in any shape or form.

Quoted 96 lines
drivers/gpu/drm/xe/xe_bo.c +21 -10
+		if (!IS_ERR(sg)) {
+			bo->flags |= XE_BO_FLAG_IAF;
+			return sg;
+		}
+
+		xe_iaf_mapping_put(src->iaf);
+err_put_dst:
+		xe_iaf_mapping_put(dst->iaf);
+	}
+
+no_iaf:
+	return dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
+}
+
 /*
  * The dma-buf map_attachment() / unmap_attachment() is hooked up here.
  * Note that unmapping the attachment is deferred to the next
@@ -665,9 +733,9 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
  * backing store out. Should that assumption not hold, then we will be able
  * to unconditionally call unmap_attachment() when moving out to system.
  */
-static int xe_bo_move_dmabuf(struct ttm_buffer_object *ttm_bo,
-			     struct ttm_resource *new_res)
+static int xe_bo_move_dmabuf(struct xe_bo *bo, struct ttm_resource *new_res)
 {
+	struct ttm_buffer_object *ttm_bo = &bo->ttm;
 	struct dma_buf_attachment *attach = ttm_bo->base.import_attach;
 	struct xe_ttm_tt *xe_tt = container_of(ttm_bo->ttm, struct xe_ttm_tt,
 					       ttm);
@@ -682,19 +750,16 @@ static int xe_bo_move_dmabuf(struct ttm_buffer_object *ttm_bo,
 	    ttm_bo->sg) {
 		dma_resv_wait_timeout(ttm_bo->base.resv, DMA_RESV_USAGE_BOOKKEEP,
 				      false, MAX_SCHEDULE_TIMEOUT);
-		dma_buf_unmap_attachment(attach, ttm_bo->sg, DMA_BIDIRECTIONAL);
-		ttm_bo->sg = NULL;
+		bo_unmap_dma_buf(bo);
 	}
 
 	if (new_res->mem_type == XE_PL_SYSTEM)
 		goto out;
 
-	if (ttm_bo->sg) {
-		dma_buf_unmap_attachment(attach, ttm_bo->sg, DMA_BIDIRECTIONAL);
-		ttm_bo->sg = NULL;
-	}
+	if (ttm_bo->sg)
+		bo_unmap_dma_buf(bo);
 
-	sg = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
+	sg = bo_map_dma_buf(bo);
 	if (IS_ERR(sg))
 		return PTR_ERR(sg);
 
@@ -797,7 +862,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
 	if (ttm_bo->type == ttm_bo_type_sg) {
 		ret = xe_bo_move_notify(bo, ctx);
 		if (!ret)
-			ret = xe_bo_move_dmabuf(ttm_bo, new_mem);
+			ret = xe_bo_move_dmabuf(bo, new_mem);
 		return ret;
 	}
 
drivers/gpu/drm/xe/xe_bo.h +2 -0
index ecb5fe3b1c1dc..210ee49d6a04d 100644
@@ -44,6 +44,7 @@
 #define XE_BO_FLAG_GGTT2		BIT(22)
 #define XE_BO_FLAG_GGTT3		BIT(23)
 #define XE_BO_FLAG_CPU_ADDR_MIRROR	BIT(24)
+#define XE_BO_FLAG_IAF			BIT(25)
 
 /* this one is trigger internally only */
 #define XE_BO_FLAG_INTERNAL_TEST	BIT(30)
@@ -262,6 +263,7 @@ void xe_bo_vunmap(struct xe_bo *bo);
 int xe_bo_read(struct xe_bo *bo, u64 offset, void *dst, int size);
 
 bool mem_type_is_vram(u32 mem_type);
+bool xe_bo_is_iaf(struct xe_bo *bo);
 bool xe_bo_is_vram(struct xe_bo *bo);
 bool xe_bo_is_stolen(struct xe_bo *bo);
 bool xe_bo_is_stolen_devmem(struct xe_bo *bo);
drivers/gpu/drm/xe/xe_dma_buf.c +2 -0
index 346f857f38374..2e8aca5d572ae 100644
@@ -86,6 +86,8 @@ static void xe_dma_buf_unpin(struct dma_buf_attachment *attach)
 	xe_bo_unpin_external(bo);
 }
 
+static const struct dma_buf_attach_ops xe_dma_buf_attach_ops;
+
 static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach,
 				       enum dma_data_direction dir)
 {

drivers/gpu/drm/xe/xe_dma_buf.c static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach, · line 103

Quoted 8 lines
drivers/gpu/drm/xe/xe_dma_buf.c +5 -0
@@ -94,12 +96,21 @@ static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach,
 	struct xe_bo *bo = gem_to_xe_bo(obj);
 	struct sg_table *sgt;
 	int r = 0;
+	bool iaf = false;
+
+	if (dir == DMA_NONE) {
+		if (attach->importer_ops != &xe_dma_buf_attach_ops)
+			return ERR_PTR(-EOPNOTSUPP);

I think this check here is the giveaway that you _really_ want a direct function call here, since this only works if both importer and exporter exactly agree on what they're doing. Hence xe_iaf_map_attachment.

That also prepares you for a future where other drivers might want to be involved in this interconnect special path. And it mirrors the design we already have for vfio buffers and their magic uuid. You can also use that pattern for handling multiple exporters, see virtio_dma_buf_attach().

Quoted 178 lines
drivers/gpu/drm/xe/xe_dma_buf.c +17 -3
+
+		iaf = true;
+	}
 
-	if (!attach->peer2peer && !xe_bo_can_migrate(bo, XE_PL_TT))
+	if (!attach->peer2peer && !iaf &&
+	    !xe_bo_can_migrate(bo, XE_PL_TT))
 		return ERR_PTR(-EOPNOTSUPP);
 
 	if (!xe_bo_is_pinned(bo)) {
-		if (!attach->peer2peer)
+		if (!attach->peer2peer && !iaf)
 			r = xe_bo_migrate(bo, XE_PL_TT);
 		else
 			r = xe_bo_validate(bo, NULL, false);
@@ -109,6 +120,10 @@ static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach,
 
 	switch (bo->ttm.resource->mem_type) {
 	case XE_PL_TT:
+		/* IAF only available for VRAM */
+		if (iaf)
+			return ERR_PTR(-EOPNOTSUPP);
+
 		sgt = drm_prime_pages_to_sg(obj->dev,
 					    bo->ttm.ttm->pages,
 					    bo->ttm.ttm->num_pages);
@@ -146,7 +161,8 @@ static void xe_dma_buf_unmap(struct dma_buf_attachment *attach,
 			     enum dma_data_direction dir)
 {
 	if (sg_page(sgt->sgl)) {
-		dma_unmap_sgtable(attach->dev, sgt, dir, 0);
+		if (dir != DMA_NONE)
+			dma_unmap_sgtable(attach->dev, sgt, dir, 0);
 		sg_free_table(sgt);
 		kfree(sgt);
 	} else {
@@ -187,6 +203,11 @@ static const struct dma_buf_ops xe_dmabuf_ops = {
 	.vunmap = drm_gem_dmabuf_vunmap,
 };
 
+bool is_xe_dma_buf(struct dma_buf *dma_buf)
+{
+	return dma_buf->ops == &xe_dmabuf_ops;
+}
+
 struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags)
 {
 	struct xe_bo *bo = gem_to_xe_bo(obj);
drivers/gpu/drm/xe/xe_dma_buf.h +1 -0
index 861dd28a862c7..80d12c624b921 100644
@@ -11,5 +11,6 @@
 struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags);
 struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
 					   struct dma_buf *dma_buf);
+bool is_xe_dma_buf(struct dma_buf *dma_buf);
 
 #endif
drivers/gpu/drm/xe/xe_ggtt.c +3 -1
index b8e1b44452e4d..c6ff18deb9db1 100644
@@ -122,7 +122,9 @@ static u64 xelp_ggtt_pte_flags(struct xe_bo *bo, u16 pat_index)
 {
 	u64 pte = XE_PAGE_PRESENT;
 
-	if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo))
+	if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo) ||
+	    /* It's likely legal to map IAF to GGTT, but it should be impossible? */
+	    drm_WARN_ON(bo->ttm.base.dev, xe_bo_is_iaf(bo)))
 		pte |= XE_GGTT_PTE_DM;
 
 	return pte;
drivers/gpu/drm/xe/xe_iaf.c +42 -0
index 431d20fea5369..af2a8d045b593 100644
@@ -416,3 +416,45 @@ struct query_info *xe_iaf_connectivity_query(struct xe_iaf *iaf, u32 fabric_id)
 
 	return iaf->ops->connectivity_query(iaf->handle, fabric_id);
 }
+
+bool xe_iaf_fabrics_connected(struct xe_iaf *src, struct xe_iaf *dst)
+{
+	struct query_info *qi;
+	bool connected;
+
+	if (!src || !dst || !src->ops || !dst->ops)
+		return false;
+
+	qi = xe_iaf_connectivity_query(src, dst->fabric_id);
+	if (IS_ERR(qi))
+		return false;
+
+	if (WARN_ON_ONCE(!qi))
+		return true;
+
+	connected = true;
+	for (int i = 0, n = qi->src_cnt * qi->dst_cnt; i < n; i++)
+		if (!qi->sd2sd[i].bandwidth) {
+			connected = false;
+			break;
+		}
+
+	kfree(qi);
+	return connected;
+}
+
+int xe_iaf_mapping_get(struct xe_iaf *iaf)
+{
+	if (!iaf || !iaf->ops)
+		return -ENODEV;
+
+	return iaf->ops->parent_event(iaf->handle, IAF_PARENT_MAPPING_GET);
+}
+
+void xe_iaf_mapping_put(struct xe_iaf *iaf)
+{
+	if (!iaf || !iaf->ops)
+		return;
+
+	iaf->ops->parent_event(iaf->handle, IAF_PARENT_MAPPING_PUT);
+}
drivers/gpu/drm/xe/xe_iaf.h +16 -0
index df6b8f9f2bc5f..b8e75640e8967 100644
@@ -38,6 +38,9 @@ int xe_iaf_init(struct xe_device *xe);
 int xe_iaf_init_aux(struct xe_device *xe);
 u64 xe_iaf_dpa_base(struct xe_device *xe);
 struct query_info *xe_iaf_connectivity_query(struct xe_iaf *iaf, u32 fabric_id);
+bool xe_iaf_fabrics_connected(struct xe_iaf *src, struct xe_iaf *dst);
+int xe_iaf_mapping_get(struct xe_iaf *iaf);
+void xe_iaf_mapping_put(struct xe_iaf *iaf);
 
 #else
 
@@ -61,6 +64,19 @@ struct query_info *xe_iaf_connectivity_query(struct xe_iaf *iaf, u32 fabric_id)
 	return ERR_PTR(-ENODEV);
 }
 
+static inline int xe_iaf_mapping_get(struct xe_iaf *iaf)
+{
+	return -ENODEV;
+}
+
+static inline void xe_iaf_mapping_put(struct xe_iaf *iaf)
+{}
+
+static inline bool xe_iaf_fabrics_connected(struct xe_iaf *src, struct xe_iaf *dst)
+{
+	return false;
+}
+
 #endif
 
 #endif
drivers/gpu/drm/xe/xe_pt.c +4 -0
index f39d5cc9f411e..2231882b2bc45 100644
@@ -764,6 +764,10 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
 		else
 			xe_res_first_sg(xe_bo_sg(bo), xe_vma_bo_offset(vma),
 					xe_vma_size(vma), &curs);
+
+		/* When IAF is used, the bo requires the DM flag */
+		if (xe_bo_is_iaf(bo))
+			curs.mem_type = XE_PL_VRAM0;
 	} else if (!range) {
 		curs.size = xe_vma_size(vma);
 	}
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +0 -0
index 9e375a40aee90..94a572693e139 100644

drivers/gpu/drm/xe/xe_ttm_vram_mgr.c int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe, · line 399

Quoted 9 lines
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +1 -5
@@ -396,11 +396,16 @@ int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe,
 		size_t size = min_t(u64, cursor.size, SZ_2G);
 		dma_addr_t addr;
 
-		addr = dma_map_resource(dev, phys, size, dir,
-					DMA_ATTR_SKIP_CPU_SYNC);
-		r = dma_mapping_error(dev, addr);
-		if (r)
-			goto error_unmap;
+		if (valid_dma_direction(dir)) {

I guess you want additional flags or an XE_DMA_MODE enum with a special XE_XIAF flag instead of abusing DMA_NONE in a pile of places.

drivers/gpu/drm/xe/xe_ttm_vram_mgr.c int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe, · line 407

Quoted 8 lines
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +8 -0
+			addr = dma_map_resource(dev, phys, size, dir,
+						DMA_ATTR_SKIP_CPU_SYNC);
+			r = dma_mapping_error(dev, addr);
+			if (r)
+				goto error_unmap;
+		} else {
+			/* Only want the SG table for fabric */
+			addr = cursor.start + tile->mem.vram.dpa_base;

I guess we do have the discussion of whether it's really ok to stuff this into an sg table or not. But for lack of better options I think this is all fine, but please make sure xe_iaf_map_attachment has it all properly documented - especially if/once that gets exported to other drivers.

Cheers, Sima

Quoted 45 lines
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +7 -2
+		}
 
 		sg_set_page(sg, NULL, size, 0);
 		sg_dma_address(sg) = addr;
@@ -413,7 +418,7 @@ int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe,
 
 error_unmap:
 	for_each_sgtable_sg((*sgt), sg, i) {
-		if (!sg->length)
+		if (!sg->length || !valid_dma_direction(dir))
 			continue;
 
 		dma_unmap_resource(dev, sg->dma_address,
@@ -433,10 +438,14 @@ void xe_ttm_vram_mgr_free_sgt(struct device *dev, enum dma_data_direction dir,
 	struct scatterlist *sg;
 	int i;
 
-	for_each_sgtable_sg(sgt, sg, i)
+	for_each_sgtable_sg(sgt, sg, i) {
+		if (!valid_dma_direction(dir))
+			continue;
+
 		dma_unmap_resource(dev, sg->dma_address,
 				   sg->length, dir,
 				   DMA_ATTR_SKIP_CPU_SYNC);
+	}
 	sg_free_table(sgt);
 	kfree(sgt);
 }
drivers/gpu/drm/xe/xe_vm.c +1 -1
index 18f967ce1f1a6..f3dd38c95deb5 100644
@@ -1534,7 +1534,7 @@ static u64 xelp_pte_encode_bo(struct xe_bo *bo, u64 bo_offset,
 	pte |= pte_encode_pat_index(pat_index, pt_level);
 	pte |= pte_encode_ps(pt_level);
 
-	if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo))
+	if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo) || xe_bo_is_iaf(bo))
 		pte |= XE_PPGTT_PTE_DM;
 
 	return pte;
Signature · 1 line
2.45.2
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch