dma-buf: Add a capabilities directory
RFC PATCH 1/1 dma-buf: Add a capabilities directory
To discover support for new DMA-BUF IOCTLs, user-space has no choice but to try to perform the IOCTL on an existing DMA-BUF. However, user-space may want to figure out whether or not the IOCTL is available before it has a DMA-BUF at hand, e.g. at initialization time in a Wayland compositor.
Add a /sys/kernel/dmabuf/caps directory which allows the DMA-BUF subsystem to advertise supported features. Add a sync_file_import_export entry which indicates that importing and exporting sync_files from/to DMA-BUFs is supported.
Signed-off-by Simon Ser <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Bas Nieuwenhuizen <[email protected]>
Cc Christian König <[email protected]>
---
This depends on:
https://patchwork.freedesktop.org/series/103715/
.../ABI/testing/sysfs-kernel-dmabuf-buffers | 14 ++++++ drivers/dma-buf/Makefile | 2 +- drivers/dma-buf/dma-buf-sysfs-stats.c | 13 +----- drivers/dma-buf/dma-buf-sysfs-stats.h | 6 ++- drivers/dma-buf/dma-buf.c | 43 +++++++++++++++++-- include/uapi/linux/dma-buf.h | 6 +++ 6 files changed, 66 insertions(+), 18 deletions(-)
Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers +14 -0
@@ -22,3 +22,17 @@ KernelVersion: v5.13 Contact: Hridya Valsaraju <[email protected]> Description: This file is read-only and specifies the size of the DMA-BUF in bytes. + +What: /sys/kernel/dmabuf/caps +Date: May 2022 +KernelVersion: v5.19 +Contact: Simon Ser <[email protected]> +Description: This directory advertises DMA-BUF capabilities supported by the + kernel. + +What: /sys/kernel/dmabuf/caps/sync_file_import_export +Date: May 2022 +KernelVersion: v5.19 +Contact: Simon Ser <[email protected]> +Description: This file is read-only and advertises support for importing and + exporting sync_files from/to DMA-BUFs.
drivers/dma-buf/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y := dma-buf.o dma-fence.o dma-fence-array.o dma-fence-chain.o \ - dma-resv.o + dma-resv.o dma-buf-sysfs-caps.o obj-$(CONFIG_DMABUF_HEAPS) += dma-heap.o obj-$(CONFIG_DMABUF_HEAPS) += heaps/ obj-$(CONFIG_SYNC_FILE) += sync_file.o
drivers/dma-buf/dma-buf-sysfs-stats.c +2 -11
@@ -141,21 +141,13 @@ static const struct kset_uevent_ops dmabuf_sysfs_no_uevent_ops = { .filter = dmabuf_sysfs_uevent_filter, }; -static struct kset *dma_buf_stats_kset;static struct kset *dma_buf_per_buffer_stats_kset; -int dma_buf_init_sysfs_statistics (void ) +int dma_buf_init_sysfs_statistics (struct kset *kset) { - dma_buf_stats_kset =kset_create_and_add ("dmabuf" , - &dmabuf_sysfs_no_uevent_ops, - kernel_kobj); -if (!dma_buf_stats_kset) -return -ENOMEM ; - dma_buf_per_buffer_stats_kset =kset_create_and_add ("buffers" , &dmabuf_sysfs_no_uevent_ops, - &dma_buf_stats_kset->kobj); + &kset->kobj);if (!dma_buf_per_buffer_stats_kset) { -kset_unregister (dma_buf_stats_kset);return -ENOMEM ; }
@@ -165,7 +157,6 @@ int dma_buf_init_sysfs_statistics(void)void dma_buf_uninit_sysfs_statistics (void ) {kset_unregister (dma_buf_per_buffer_stats_kset); -kset_unregister (dma_buf_stats_kset); }int dma_buf_stats_setup (struct dma_buf *dmabuf)
drivers/dma-buf/dma-buf-sysfs-stats.h +4 -2
@@ -8,9 +8,11 @@#ifndef _DMA_BUF_SYSFS_STATS_H#define _DMA_BUF_SYSFS_STATS_H +struct kset ; +#ifdef CONFIG_DMABUF_SYSFS_STATS -int dma_buf_init_sysfs_statistics (void ); +int dma_buf_init_sysfs_statistics (struct kset *kset);void dma_buf_uninit_sysfs_statistics (void );int dma_buf_stats_setup (struct dma_buf *dmabuf);
@@ -18,7 +20,7 @@ int dma_buf_stats_setup(struct dma_buf *dmabuf);void dma_buf_stats_teardown (struct dma_buf *dmabuf);#else -static inline int dma_buf_init_sysfs_statistics (void ) +static inline int dma_buf_init_sysfs_statistics (struct kset *kset) {return 0 ; }
drivers/dma-buf/dma-buf.c +39 -4
72 lines not on this page · raw message
include/uapi/linux/dma-buf.h +6 -0
@@ -114,6 +114,9 @@ struct dma_buf_sync {* ordering via these fences, it is the respnosibility of userspace to use * locks or other mechanisms to ensure that no other context adds fences or * submits work between steps 1 and 3 above. +* +* Userspace can check the availability of this API via +* /sys/kernel/dmabuf/caps/sync_file_import_export. */ struct dma_buf_export_sync_file {/**
@@ -146,6 +149,9 @@ struct dma_buf_export_sync_file {* synchronized APIs such as Vulkan to inter-op with dma-buf consumers * which expect implicit synchronization such as OpenGL or most media * drivers/video. +* +* Userspace can check the availability of this API via +* /sys/kernel/dmabuf/caps/sync_file_import_export. */ struct dma_buf_import_sync_file {/**
Signature · 1 line
2.36.1