0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/module.h>
0009 #include <linux/virtio_dma_buf.h>
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 struct dma_buf *virtio_dma_buf_export
0021 (const struct dma_buf_export_info *exp_info)
0022 {
0023 const struct virtio_dma_buf_ops *virtio_ops =
0024 container_of(exp_info->ops,
0025 const struct virtio_dma_buf_ops, ops);
0026
0027 if (!exp_info->ops ||
0028 exp_info->ops->attach != &virtio_dma_buf_attach ||
0029 !virtio_ops->get_uuid) {
0030 return ERR_PTR(-EINVAL);
0031 }
0032
0033 return dma_buf_export(exp_info);
0034 }
0035 EXPORT_SYMBOL(virtio_dma_buf_export);
0036
0037
0038
0039
0040 int virtio_dma_buf_attach(struct dma_buf *dma_buf,
0041 struct dma_buf_attachment *attach)
0042 {
0043 int ret;
0044 const struct virtio_dma_buf_ops *ops =
0045 container_of(dma_buf->ops,
0046 const struct virtio_dma_buf_ops, ops);
0047
0048 if (ops->device_attach) {
0049 ret = ops->device_attach(dma_buf, attach);
0050 if (ret)
0051 return ret;
0052 }
0053 return 0;
0054 }
0055 EXPORT_SYMBOL(virtio_dma_buf_attach);
0056
0057
0058
0059
0060
0061 bool is_virtio_dma_buf(struct dma_buf *dma_buf)
0062 {
0063 return dma_buf->ops->attach == &virtio_dma_buf_attach;
0064 }
0065 EXPORT_SYMBOL(is_virtio_dma_buf);
0066
0067
0068
0069
0070
0071
0072
0073
0074 int virtio_dma_buf_get_uuid(struct dma_buf *dma_buf,
0075 uuid_t *uuid)
0076 {
0077 const struct virtio_dma_buf_ops *ops =
0078 container_of(dma_buf->ops,
0079 const struct virtio_dma_buf_ops, ops);
0080
0081 if (!is_virtio_dma_buf(dma_buf))
0082 return -EINVAL;
0083
0084 return ops->get_uuid(dma_buf, uuid);
0085 }
0086 EXPORT_SYMBOL(virtio_dma_buf_get_uuid);
0087
0088 MODULE_LICENSE("GPL");
0089 MODULE_IMPORT_NS(DMA_BUF);