@@ -711,36 +711,50 @@ struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_object *obj)
EXPORT_SYMBOL_GPL(drm_gem_shmem_get_pages_sgt);
/**
- * drm_gem_shmem_prime_import_sg_table - Produce a shmem GEM object from
- * another driver's scatter/gather table of pinned pages
+ * drm_gem_shmem_prime_create_object - Produce a shmem GEM object from
+ * another driver's DMA-BUF attachment
* @dev: Device to import into
* @attach: DMA-BUF attachment
- * @sgt: Scatter/gather table of pinned pages
*
- * This function imports a scatter/gather table exported via DMA-BUF by
- * another driver. Drivers that use the shmem helpers should set this as their
- * &drm_driver.gem_prime_import_sg_table callback.
+ * This function imports a DMA-BUF attachment exported by another driver.
+ * If supported, it sets a scatter/gather table of pinned pages. Drivers
+ * that use the shmem helpers should set this as their
+ * &drm_driver.gem_prime_create_object callback.
*
* Returns:
* A pointer to a newly created GEM object or an ERR_PTR-encoded negative
* error code on failure.
*/
struct drm_gem_object *
-drm_gem_shmem_prime_import_sg_table(struct drm_device *dev,
- struct dma_buf_attachment *attach,
- struct sg_table *sgt)
+drm_gem_shmem_prime_create_object(struct drm_device *dev,
+ struct dma_buf_attachment *attach)
{
size_t size = PAGE_ALIGN(attach->dmabuf->size);
+ struct sg_table *sgt = NULL;
struct drm_gem_shmem_object *shmem;
+ int ret;
+
+ if (dev->dev->dma_mask) {
+ sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
+ if (IS_ERR(sgt))
+ return ERR_CAST(sgt);
+ }
shmem = __drm_gem_shmem_create(dev, size, true);
- if (IS_ERR(shmem))
- return ERR_CAST(shmem);
+ if (IS_ERR(shmem)) {
+ ret = PTR_ERR(shmem);
+ goto err;
+ }
shmem->sgt = sgt;
DRM_DEBUG_PRIME("size = %zu\n", size);
return &shmem->base;
+
+err:
+ if (sgt)
+ dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL);
+ return ERR_PTR(ret);
}
-EXPORT_SYMBOL_GPL(drm_gem_shmem_prime_import_sg_table);
+EXPORT_SYMBOL_GPL(drm_gem_shmem_prime_create_object);
@@ -277,8 +277,8 @@ static const struct drm_driver lima_drm_driver = {
.gem_create_object = lima_gem_create_object,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
- .gem_prime_import_sg_table = drm_gem_shmem_prime_import_sg_table,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
+ .gem_prime_create_object = drm_gem_shmem_prime_create_object,
.gem_prime_mmap = drm_gem_prime_mmap,
};
@@ -564,7 +564,7 @@ static const struct drm_driver panfrost_drm_driver = {
.gem_create_object = panfrost_gem_create_object,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
- .gem_prime_import_sg_table = panfrost_gem_prime_import_sg_table,
+ .gem_prime_create_object = panfrost_gem_prime_create_object,
.gem_prime_mmap = drm_gem_prime_mmap,
};
@@ -269,14 +269,12 @@ panfrost_gem_create_with_handle(struct drm_file *file_priv,
}
struct drm_gem_object *
-panfrost_gem_prime_import_sg_table(struct drm_device *dev,
- struct dma_buf_attachment *attach,
- struct sg_table *sgt)
+panfrost_gem_prime_create_object(struct drm_device *dev, struct dma_buf_attachment *attach)
{
struct drm_gem_object *obj;
struct panfrost_gem_object *bo;
- obj = drm_gem_shmem_prime_import_sg_table(dev, attach, sgt);
+ obj = drm_gem_shmem_prime_create_object(dev, attach);
if (IS_ERR(obj))
return ERR_CAST(obj);
@@ -64,9 +64,7 @@ drm_mm_node_to_panfrost_mapping(struct drm_mm_node *node)
struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t size);
struct drm_gem_object *
-panfrost_gem_prime_import_sg_table(struct drm_device *dev,
- struct dma_buf_attachment *attach,
- struct sg_table *sgt);
+panfrost_gem_prime_create_object(struct drm_device *dev, struct dma_buf_attachment *attach);
struct panfrost_gem_object *
panfrost_gem_create_with_handle(struct drm_file *file_priv,
@@ -601,12 +601,6 @@ static const uint64_t gm12u320_pipe_modifiers[] = {
DEFINE_DRM_GEM_FOPS(gm12u320_fops);
-static struct drm_gem_object *gm12u320_gem_prime_create_object(struct drm_device *dev,
- struct dma_buf_attachment *attach)
-{
- return drm_gem_shmem_prime_import_sg_table(dev, attach, NULL);
-}
-
static const struct drm_driver gm12u320_drm_driver = {
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
@@ -618,7 +612,6 @@ static const struct drm_driver gm12u320_drm_driver = {
.fops = &gm12u320_fops,
DRM_GEM_SHMEM_DRIVER_OPS,
- .gem_prime_create_object = gm12u320_gem_prime_create_object,
};
static const struct drm_mode_config_funcs gm12u320_mode_config_funcs = {
@@ -34,19 +34,12 @@ static int udl_usb_resume(struct usb_interface *interface)
DEFINE_DRM_GEM_FOPS(udl_driver_fops);
-static struct drm_gem_object *udl_gem_prime_create_object(struct drm_device *dev,
- struct dma_buf_attachment *attach)
-{
- return drm_gem_shmem_prime_import_sg_table(dev, attach, NULL);
-}
-
static const struct drm_driver driver = {
.driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
/* GEM hooks */
.fops = &udl_driver_fops,
DRM_GEM_SHMEM_DRIVER_OPS,
- .gem_prime_create_object = udl_gem_prime_create_object,
.name = DRIVER_NAME,
.desc = DRIVER_DESC,
@@ -146,14 +146,12 @@ struct v3d_bo *v3d_bo_create(struct drm_device *dev, struct drm_file *file_priv,
}
struct drm_gem_object *
-v3d_prime_import_sg_table(struct drm_device *dev,
- struct dma_buf_attachment *attach,
- struct sg_table *sgt)
+v3d_prime_create_object(struct drm_device *dev, struct dma_buf_attachment *attach)
{
struct drm_gem_object *obj;
int ret;
- obj = drm_gem_shmem_prime_import_sg_table(dev, attach, sgt);
+ obj = drm_gem_shmem_prime_create_object(dev, attach);
if (IS_ERR(obj))
return obj;
@@ -173,7 +173,7 @@ static const struct drm_driver v3d_drm_driver = {
.gem_create_object = v3d_create_object,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
- .gem_prime_import_sg_table = v3d_prime_import_sg_table,
+ .gem_prime_create_object = v3d_prime_create_object,
.gem_prime_mmap = drm_gem_prime_mmap,
.ioctls = v3d_drm_ioctls,
@@ -310,9 +310,8 @@ int v3d_mmap_bo_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv);
int v3d_get_bo_offset_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv);
-struct drm_gem_object *v3d_prime_import_sg_table(struct drm_device *dev,
- struct dma_buf_attachment *attach,
- struct sg_table *sgt);
+struct drm_gem_object *v3d_prime_create_object(struct drm_device *dev,
+ struct dma_buf_attachment *attach);
/* v3d_debugfs.c */
void v3d_debugfs_init(struct drm_minor *minor);
@@ -143,9 +143,7 @@ void drm_gem_shmem_print_info(struct drm_printer *p, unsigned int indent,
struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_object *obj);
struct drm_gem_object *
-drm_gem_shmem_prime_import_sg_table(struct drm_device *dev,
- struct dma_buf_attachment *attach,
- struct sg_table *sgt);
+drm_gem_shmem_prime_create_object(struct drm_device *dev, struct dma_buf_attachment *attach);
struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_object *obj);
@@ -158,7 +156,7 @@ struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_object *obj);
#define DRM_GEM_SHMEM_DRIVER_OPS \
.prime_handle_to_fd = drm_gem_prime_handle_to_fd, \
.prime_fd_to_handle = drm_gem_prime_fd_to_handle, \
- .gem_prime_import_sg_table = drm_gem_shmem_prime_import_sg_table, \
+ .gem_prime_create_object = drm_gem_shmem_prime_create_object, \
.gem_prime_mmap = drm_gem_prime_mmap, \
.dumb_create = drm_gem_shmem_dumb_create
Moves the scatter/gather-table setup from PRIME helpers into SHMEM helpers. USB-based drivers don't support DMA, so make the sg table optional. This cleans up rsp code in udl and gm12u320. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> --- drivers/gpu/drm/drm_gem_shmem_helper.c | 38 +++++++++++++++++-------- drivers/gpu/drm/lima/lima_drv.c | 2 +- drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +- drivers/gpu/drm/panfrost/panfrost_gem.c | 6 ++-- drivers/gpu/drm/panfrost/panfrost_gem.h | 4 +-- drivers/gpu/drm/tiny/gm12u320.c | 7 ----- drivers/gpu/drm/udl/udl_drv.c | 7 ----- drivers/gpu/drm/v3d/v3d_bo.c | 6 ++-- drivers/gpu/drm/v3d/v3d_drv.c | 2 +- drivers/gpu/drm/v3d/v3d_drv.h | 5 ++-- include/drm/drm_gem_shmem_helper.h | 6 ++-- 11 files changed, 38 insertions(+), 47 deletions(-)