Commit b5e9c1a2 authored by Maarten Lankhorst's avatar Maarten Lankhorst

drm: Pass dma-buf as argument to gem_prime_import_sg_table

Allows importing dma_reservation_objects from a dma-buf.
Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@canonical.com>
parent 15a996bb
...@@ -316,7 +316,8 @@ struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj) ...@@ -316,7 +316,8 @@ struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
EXPORT_SYMBOL_GPL(drm_gem_cma_prime_get_sg_table); EXPORT_SYMBOL_GPL(drm_gem_cma_prime_get_sg_table);
struct drm_gem_object * struct drm_gem_object *
drm_gem_cma_prime_import_sg_table(struct drm_device *dev, size_t size, drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
struct dma_buf_attachment *attach,
struct sg_table *sgt) struct sg_table *sgt)
{ {
struct drm_gem_cma_object *cma_obj; struct drm_gem_cma_object *cma_obj;
...@@ -325,14 +326,14 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev, size_t size, ...@@ -325,14 +326,14 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev, size_t size,
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
/* Create a CMA GEM buffer. */ /* Create a CMA GEM buffer. */
cma_obj = __drm_gem_cma_create(dev, size); cma_obj = __drm_gem_cma_create(dev, attach->dmabuf->size);
if (IS_ERR(cma_obj)) if (IS_ERR(cma_obj))
return ERR_CAST(cma_obj); return ERR_CAST(cma_obj);
cma_obj->paddr = sg_dma_address(sgt->sgl); cma_obj->paddr = sg_dma_address(sgt->sgl);
cma_obj->sgt = sgt; cma_obj->sgt = sgt;
DRM_DEBUG_PRIME("dma_addr = %pad, size = %zu\n", &cma_obj->paddr, size); DRM_DEBUG_PRIME("dma_addr = %pad, size = %zu\n", &cma_obj->paddr, attach->dmabuf->size);
return &cma_obj->base; return &cma_obj->base;
} }
......
...@@ -525,7 +525,7 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, ...@@ -525,7 +525,7 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
goto fail_detach; goto fail_detach;
} }
obj = dev->driver->gem_prime_import_sg_table(dev, dma_buf->size, sgt); obj = dev->driver->gem_prime_import_sg_table(dev, attach, sgt);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
ret = PTR_ERR(obj); ret = PTR_ERR(obj);
goto fail_unmap; goto fail_unmap;
......
...@@ -171,7 +171,7 @@ struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj); ...@@ -171,7 +171,7 @@ struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj);
void *msm_gem_prime_vmap(struct drm_gem_object *obj); void *msm_gem_prime_vmap(struct drm_gem_object *obj);
void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev, struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
size_t size, struct sg_table *sg); struct dma_buf_attachment *attach, struct sg_table *sg);
int msm_gem_prime_pin(struct drm_gem_object *obj); int msm_gem_prime_pin(struct drm_gem_object *obj);
void msm_gem_prime_unpin(struct drm_gem_object *obj); void msm_gem_prime_unpin(struct drm_gem_object *obj);
void *msm_gem_vaddr_locked(struct drm_gem_object *obj); void *msm_gem_vaddr_locked(struct drm_gem_object *obj);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "msm_drv.h" #include "msm_drv.h"
#include "msm_gem.h" #include "msm_gem.h"
#include <linux/dma-buf.h>
struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj) struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj)
{ {
...@@ -37,9 +38,9 @@ void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) ...@@ -37,9 +38,9 @@ void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
} }
struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev, struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
size_t size, struct sg_table *sg) struct dma_buf_attachment *attach, struct sg_table *sg)
{ {
return msm_gem_import(dev, size, sg); return msm_gem_import(dev, attach->dmabuf->size, sg);
} }
int msm_gem_prime_pin(struct drm_gem_object *obj) int msm_gem_prime_pin(struct drm_gem_object *obj)
......
...@@ -39,7 +39,7 @@ struct reservation_object *nouveau_gem_prime_res_obj(struct drm_gem_object *); ...@@ -39,7 +39,7 @@ struct reservation_object *nouveau_gem_prime_res_obj(struct drm_gem_object *);
extern void nouveau_gem_prime_unpin(struct drm_gem_object *); extern void nouveau_gem_prime_unpin(struct drm_gem_object *);
extern struct sg_table *nouveau_gem_prime_get_sg_table(struct drm_gem_object *); extern struct sg_table *nouveau_gem_prime_get_sg_table(struct drm_gem_object *);
extern struct drm_gem_object *nouveau_gem_prime_import_sg_table( extern struct drm_gem_object *nouveau_gem_prime_import_sg_table(
struct drm_device *, size_t size, struct sg_table *); struct drm_device *, struct dma_buf_attachment *, struct sg_table *);
extern void *nouveau_gem_prime_vmap(struct drm_gem_object *); extern void *nouveau_gem_prime_vmap(struct drm_gem_object *);
extern void nouveau_gem_prime_vunmap(struct drm_gem_object *, void *); extern void nouveau_gem_prime_vunmap(struct drm_gem_object *, void *);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
#include <drm/drmP.h> #include <drm/drmP.h>
#include <linux/dma-buf.h>
#include "nouveau_drm.h" #include "nouveau_drm.h"
#include "nouveau_gem.h" #include "nouveau_gem.h"
...@@ -56,7 +57,7 @@ void nouveau_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) ...@@ -56,7 +57,7 @@ void nouveau_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
} }
struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev, struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev,
size_t size, struct dma_buf_attachment *attach,
struct sg_table *sg) struct sg_table *sg)
{ {
struct nouveau_bo *nvbo; struct nouveau_bo *nvbo;
...@@ -65,7 +66,7 @@ struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev, ...@@ -65,7 +66,7 @@ struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev,
flags = TTM_PL_FLAG_TT; flags = TTM_PL_FLAG_TT;
ret = nouveau_bo_new(dev, size, 0, flags, 0, 0, ret = nouveau_bo_new(dev, attach->dmabuf->size, 0, flags, 0, 0,
sg, &nvbo); sg, &nvbo);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -537,7 +537,7 @@ int qxl_gem_prime_pin(struct drm_gem_object *obj); ...@@ -537,7 +537,7 @@ int qxl_gem_prime_pin(struct drm_gem_object *obj);
void qxl_gem_prime_unpin(struct drm_gem_object *obj); void qxl_gem_prime_unpin(struct drm_gem_object *obj);
struct sg_table *qxl_gem_prime_get_sg_table(struct drm_gem_object *obj); struct sg_table *qxl_gem_prime_get_sg_table(struct drm_gem_object *obj);
struct drm_gem_object *qxl_gem_prime_import_sg_table( struct drm_gem_object *qxl_gem_prime_import_sg_table(
struct drm_device *dev, size_t size, struct drm_device *dev, struct dma_buf_attachment *attach,
struct sg_table *sgt); struct sg_table *sgt);
void *qxl_gem_prime_vmap(struct drm_gem_object *obj); void *qxl_gem_prime_vmap(struct drm_gem_object *obj);
void qxl_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); void qxl_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
......
...@@ -46,7 +46,7 @@ struct sg_table *qxl_gem_prime_get_sg_table(struct drm_gem_object *obj) ...@@ -46,7 +46,7 @@ struct sg_table *qxl_gem_prime_get_sg_table(struct drm_gem_object *obj)
} }
struct drm_gem_object *qxl_gem_prime_import_sg_table( struct drm_gem_object *qxl_gem_prime_import_sg_table(
struct drm_device *dev, size_t size, struct drm_device *dev, struct dma_buf_attachment *attach,
struct sg_table *table) struct sg_table *table)
{ {
WARN_ONCE(1, "not implemented"); WARN_ONCE(1, "not implemented");
......
...@@ -135,7 +135,7 @@ int radeon_mode_dumb_create(struct drm_file *file_priv, ...@@ -135,7 +135,7 @@ int radeon_mode_dumb_create(struct drm_file *file_priv,
struct drm_mode_create_dumb *args); struct drm_mode_create_dumb *args);
struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj); struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj);
struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev, struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev,
size_t size, struct dma_buf_attachment *,
struct sg_table *sg); struct sg_table *sg);
int radeon_gem_prime_pin(struct drm_gem_object *obj); int radeon_gem_prime_pin(struct drm_gem_object *obj);
void radeon_gem_prime_unpin(struct drm_gem_object *obj); void radeon_gem_prime_unpin(struct drm_gem_object *obj);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "radeon.h" #include "radeon.h"
#include <drm/radeon_drm.h> #include <drm/radeon_drm.h>
#include <linux/dma-buf.h>
struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj) struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj)
{ {
...@@ -57,14 +58,14 @@ void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) ...@@ -57,14 +58,14 @@ void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
} }
struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev, struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev,
size_t size, struct dma_buf_attachment *attach,
struct sg_table *sg) struct sg_table *sg)
{ {
struct radeon_device *rdev = dev->dev_private; struct radeon_device *rdev = dev->dev_private;
struct radeon_bo *bo; struct radeon_bo *bo;
int ret; int ret;
ret = radeon_bo_create(rdev, size, PAGE_SIZE, false, ret = radeon_bo_create(rdev, attach->dmabuf->size, PAGE_SIZE, false,
RADEON_GEM_DOMAIN_GTT, 0, sg, &bo); RADEON_GEM_DOMAIN_GTT, 0, sg, &bo);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -87,6 +87,7 @@ struct drm_gem_object; ...@@ -87,6 +87,7 @@ struct drm_gem_object;
struct device_node; struct device_node;
struct videomode; struct videomode;
struct reservation_object; struct reservation_object;
struct dma_buf_attachment;
/* /*
* 4 debug categories are defined: * 4 debug categories are defined:
...@@ -570,7 +571,8 @@ struct drm_driver { ...@@ -570,7 +571,8 @@ struct drm_driver {
struct drm_gem_object *obj); struct drm_gem_object *obj);
struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj); struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
struct drm_gem_object *(*gem_prime_import_sg_table)( struct drm_gem_object *(*gem_prime_import_sg_table)(
struct drm_device *dev, size_t size, struct drm_device *dev,
struct dma_buf_attachment *attach,
struct sg_table *sgt); struct sg_table *sgt);
void *(*gem_prime_vmap)(struct drm_gem_object *obj); void *(*gem_prime_vmap)(struct drm_gem_object *obj);
void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr); void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
......
...@@ -45,7 +45,8 @@ void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m); ...@@ -45,7 +45,8 @@ void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m);
struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj); struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj);
struct drm_gem_object * struct drm_gem_object *
drm_gem_cma_prime_import_sg_table(struct drm_device *dev, size_t size, drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
struct dma_buf_attachment *attach,
struct sg_table *sgt); struct sg_table *sgt);
int drm_gem_cma_prime_mmap(struct drm_gem_object *obj, int drm_gem_cma_prime_mmap(struct drm_gem_object *obj,
struct vm_area_struct *vma); struct vm_area_struct *vma);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment