Skip to content

Commit

Permalink
dma-buf: Support negotiation between exporter and importer
Browse files Browse the repository at this point in the history
Allow the exporter and importer to recognize each other and to set up a
shared region of memory for the purpose of mapping requirement
negotiation.

Tracked-On: OAM-129610
Signed-off-by: Weifeng Liu <weifeng.liu@intel.com>
  • Loading branch information
phreer committed Feb 19, 2025
1 parent 724697d commit b1bd502
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/dma-buf/dma-buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions include/linux/dma-buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand All @@ -609,6 +639,8 @@ struct dma_buf_attachment {

ANDROID_KABI_RESERVE(1);
ANDROID_KABI_RESERVE(2);
unsigned importer_type_id;
void *shared;
};

/**
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b1bd502

Please sign in to comment.