Skip to content

drm/i915/guc: Refactor ADS access to use dma_buf_map

Lucas De Marchi dri-devel intel-gfx linux-media lkml llvm oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest19 patches 34 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/19dma-buf-map: Add read/write helpersinclude/linux/dma-buf-map.h+81 -07 replies
2/19dma-buf-map: Add helper to initialize second mapinclude/linux/dma-buf-map.h+29 -021 replies
3/19drm/i915/gt: Add helper for shmem copy to dma_buf_mapdrivers/gpu/drm/i915/gt/shmem_utils.c drivers/gpu/drm/i915/gt/shmem_utils.h+35 -00 replies
4/19drm/i915/guc: Keep dma_buf_map of ads_blob arounddrivers/gpu/drm/i915/gt/uc/intel_guc.h drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+9 -10 replies
5/19drm/i915/guc: Add read/write helpers for ADS blobdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+8 -00 replies
6/19drm/i915/guc: Convert golden context init to dma_buf_mapdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+13 -120 replies
7/19drm/i915/guc: Convert policies update to dma_buf_mapdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+23 -180 replies
8/19drm/i915/guc: Convert engine record to dma_buf_mapdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c+15 -130 replies
9/19dma-buf-map: Add wrapper over memsetinclude/linux/dma-buf-map.h+17 -04 replies
10/19drm/i915/guc: Convert guc_ads_private_data_reset to dma_buf_mapdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+3 -20 replies
11/19drm/i915/guc: Convert golden context prep to dma_buf_mapdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+32 -200 replies
12/19drm/i915/guc: Replace check for golden context sizedrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+3 -30 replies
13/19drm/i915/guc: Convert mapping table to dma_buf_mapdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+6 -60 replies
14/19drm/i915/guc: Convert capture list to dma_buf_mapdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+5 -50 replies
15/19drm/i915/guc: Prepare for error propagationdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+18 -130 replies
16/19drm/i915/guc: Use a single pass to calculate regsetdrivers/gpu/drm/i915/gt/uc/intel_guc.h drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+79 -452 replies
17/19drm/i915/guc: Convert guc_mmio_reg_state_init to dma_buf_mapdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+18 -120 replies
18/19drm/i915/guc: Convert __guc_ads_init to dma_buf_mapdrivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+14 -110 replies
19/19drm/i915/guc: Remove plain ads_blob pointerdrivers/gpu/drm/i915/gt/uc/intel_guc.h drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c+5 -60 replies

Reviews trailers per patch

1 of 19 patches has a Reviewed-by or Acked-by.

PatchDaniel Vetter
1/19
2/19A-b
3/19
4/19
5/19
6/19
7/19
8/19
9/19
10/19
11/19
12/19
13/19
14/19
15/19
16/19
17/19
18/19
19/19

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 00/19] drm/i915/guc: Refactor ADS access to use dma_buf_map

While porting i915 to arm64 we noticed some issues accessing lmem. Some writes were getting corrupted and the final state of the buffer didn't have exactly what we wrote. This became evident when enabling GuC submission: depending on the number of engines the ADS struct was being corrupted and GuC would reject it, refusin to initialize.

From Documentation/core-api/bus-virt-phys-mapping.rst:

This memory is called "PCI memory" or "shared memory" or "IO memory" or whatever, and there is only one way to access it: the readb/writeb and related functions. You should never take the address of such memory, because there is really nothing you can do with such an address: it's not conceptually in the same memory space as "real memory" at all, so you cannot just dereference a pointer. (Sadly, on x86 it **is** in the same memory space, so on x86 it actually works to just deference a pointer, but it's not portable).

When reading or writing words directly to IO memory, in order to be portable the Linux kernel provides the abstraction detailed in section "Differences between I/O access functions" of Documentation/driver-api/device-io.rst.

This limits our ability to simply overlay our structs on top a buffer and directly access it since that buffer may come from IO memory rather than system memory. Hence the approach taken in intel_guc_ads.c needs to be refactored. This is not the only place in i915 that neeed to be changed, but the one causing the most problems, with a real reproducer. This first set of patch focuses on fixing the gem object to pass the ADS

After the addition of a few helpers in the dma_buf_map API, most of intel_guc_ads.c can be converted to use it. The exception is the regset
initialization: we'd incur into a lot of extra indirection when reading/writting each register. So the regset is converted to use a temporary buffer allocated on probe, which is then copied to its final location when finishing the initialization or on gt reset.

Testing on some discrete cards, after this change we can correctly pass the ADS struct to GuC and have it initialized correctly.

thanks
Lucas De Marchi

Cc Christian König <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Daniele Ceraolo Spurio <[email protected]>
Cc David Airlie <[email protected]>
Cc John Harrison <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Matt Roper <[email protected]>
Cc Matthew Auld <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Sumit Semwal <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Tvrtko Ursulin <[email protected]>

Lucas De Marchi (19):
dma-buf-map: Add read/write helpers
dma-buf-map: Add helper to initialize second map drm/i915/gt: Add helper for shmem copy to dma_buf_map drm/i915/guc: Keep dma_buf_map of ads_blob around drm/i915/guc: Add read/write helpers for ADS blob drm/i915/guc: Convert golden context init to dma_buf_map drm/i915/guc: Convert policies update to dma_buf_map drm/i915/guc: Convert engine record to dma_buf_map
dma-buf-map: Add wrapper over memset
drm/i915/guc: Convert guc_ads_private_data_reset to dma_buf_map drm/i915/guc: Convert golden context prep to dma_buf_map drm/i915/guc: Replace check for golden context size drm/i915/guc: Convert mapping table to dma_buf_map drm/i915/guc: Convert capture list to dma_buf_map drm/i915/guc: Prepare for error propagation drm/i915/guc: Use a single pass to calculate regset drm/i915/guc: Convert guc_mmio_reg_state_init to dma_buf_map drm/i915/guc: Convert __guc_ads_init to dma_buf_map drm/i915/guc: Remove plain ads_blob pointer

 drivers/gpu/drm/i915/gt/shmem_utils.c         |  32 ++
 drivers/gpu/drm/i915/gt/shmem_utils.h         |   3 +
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |  14 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c    | 374 +++++++++++-------
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h    |   3 +-
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c |  11 +-
 include/linux/dma-buf-map.h                   | 127 ++++++
 7 files changed, 405 insertions(+), 159 deletions(-)
Signature · 1 line
2.35.0