diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 4580df83576e..72dbeef16d75 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -978,8 +978,9 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_dynamic_attach, DMA_BUF); */ struct dma_buf_attachment * ____dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev, - const struct dma_buf_attach_ops *importer_ops, - void *importer_priv, bool p2p) + unsigned importer_type_id, void *shared, + const struct dma_buf_attach_ops *importer_ops, + void *importer_priv, bool p2p) { struct dma_buf_attachment *attach; int ret; @@ -995,6 +996,8 @@ ____dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev, return ERR_PTR(-ENOMEM); attach->dev = dev; + attach->importer_type_id = importer_type_id; + attach->shared = shared; attach->dmabuf = dmabuf; if (importer_ops) attach->peer2peer = importer_ops->allow_peer2peer; diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index af88955ce432..bfbd8e98eeb5 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -533,8 +533,34 @@ struct dma_buf { ANDROID_KABI_RESERVE(1); ANDROID_KABI_RESERVE(2); + + /** + * @exporter_id: + * + * Globally unique id for importer identifying exporter type (driver). + * Based on this info, the importer could leverage shared field in + * dmabuf attachment for negotiation. + */ + unsigned exporter_type_id; }; +#define DMA_BUF_DRIVER_TYPE_ID_GENERAL 0 +#define DMA_BUF_DRIVER_TYPE_ID_I915_BACKPORTS 1 +#define DMA_BUF_DRIVER_TYPE_ID_VIRTIO_GPU 2 + +#define VIRTIO_GPU_DMABUF_ATTACH_SHARED_CURRENT_VERSION 1 +#define VIRTIO_GPU_DMABUF_ATTACH_SHARED_FLAG_LMEM (1lu << 0) + +struct virtio_gpu_dmabuf_attach_shared { + uint32_t version; + union { + struct { + uint32_t flags; + } v1; + } shared; +}; + + /** * struct dma_buf_attach_ops - importer operations for an attachment * @@ -585,6 +611,10 @@ struct dma_buf_attach_ops { * @importer_priv: importer specific attachment data. * @dma_map_attrs: DMA attributes to be used when the exporter maps the buffer * through dma_buf_map_attachment. + * @importer_type_id: used by exporter for identifying the importer + * @shared: shared by both exporter and importer for negotiation on the + * DMA mapping requirements. Should be used only when importer recognizes the + * exporter and be allocated/cleaned up by the importer. * * This structure holds the attachment information between the dma_buf buffer * and its user device(s). The list contains one attachment struct per device @@ -609,6 +639,8 @@ struct dma_buf_attachment { ANDROID_KABI_RESERVE(1); ANDROID_KABI_RESERVE(2); + unsigned importer_type_id; + void *shared; }; /** @@ -700,6 +732,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev, void *importer_priv); struct dma_buf_attachment * ____dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev, + unsigned importer_type_id, void *shared, const struct dma_buf_attach_ops *importer_ops, void *importer_priv, bool p2p); void dma_buf_detach(struct dma_buf *dmabuf,