drivers/infiniband/core/uverbs_std_types_dmabuf.c

Source file repositories/reference/linux-study-clean/drivers/infiniband/core/uverbs_std_types_dmabuf.c

File Facts

System
Linux kernel
Corpus path
drivers/infiniband/core/uverbs_std_types_dmabuf.c
Extension
.c
Size
5555 bytes
Lines
203
Domain
Driver Families
Bucket
drivers/infiniband
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/*
 * Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved
 */

#include <linux/dma-buf-mapping.h>
#include <linux/pci-p2pdma.h>
#include <linux/dma-resv.h>
#include <rdma/uverbs_std_types.h>
#include "rdma_core.h"
#include "uverbs.h"

MODULE_IMPORT_NS("DMA_BUF");

static int uverbs_dmabuf_attach(struct dma_buf *dmabuf,
				struct dma_buf_attachment *attachment)
{
	if (!attachment->peer2peer)
		return -EOPNOTSUPP;

	return 0;
}

static struct sg_table *
uverbs_dmabuf_map(struct dma_buf_attachment *attachment,
		  enum dma_data_direction dir)
{
	struct ib_uverbs_dmabuf_file *priv = attachment->dmabuf->priv;
	struct sg_table *ret;

	dma_resv_assert_held(priv->dmabuf->resv);

	if (priv->revoked)
		return ERR_PTR(-ENODEV);

	ret = dma_buf_phys_vec_to_sgt(attachment, priv->provider,
				      &priv->phys_vec, 1, priv->phys_vec.len,
				      dir);
	if (IS_ERR(ret))
		return ret;

	kref_get(&priv->kref);
	return ret;
}

static void uverbs_dmabuf_unmap(struct dma_buf_attachment *attachment,
				struct sg_table *sgt,
				enum dma_data_direction dir)
{
	struct ib_uverbs_dmabuf_file *priv = attachment->dmabuf->priv;

	dma_resv_assert_held(priv->dmabuf->resv);
	dma_buf_free_sgt(attachment, sgt, dir);
	kref_put(&priv->kref, ib_uverbs_dmabuf_done);
}

static int uverbs_dmabuf_pin(struct dma_buf_attachment *attach)
{
	return -EOPNOTSUPP;
}

static void uverbs_dmabuf_unpin(struct dma_buf_attachment *attach)
{
}

static void uverbs_dmabuf_release(struct dma_buf *dmabuf)
{
	struct ib_uverbs_dmabuf_file *priv = dmabuf->priv;

	/*
	 * This can only happen if the fput came from alloc_abort_fd_uobject()
	 */
	if (!priv->uobj.context)
		return;

	uverbs_uobject_release(&priv->uobj);
}

static const struct dma_buf_ops uverbs_dmabuf_ops = {
	.attach = uverbs_dmabuf_attach,
	.map_dma_buf = uverbs_dmabuf_map,
	.unmap_dma_buf = uverbs_dmabuf_unmap,
	.pin = uverbs_dmabuf_pin,
	.unpin = uverbs_dmabuf_unpin,
	.release = uverbs_dmabuf_release,
};

static int UVERBS_HANDLER(UVERBS_METHOD_DMABUF_ALLOC)(
	struct uverbs_attr_bundle *attrs)
{

Annotation

Implementation Notes