mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-15 17:43:59 +00:00
a780278472
Acquire the buffer object's reservation lock in drm_gem_pin() and remove locking the drivers' GEM callbacks where necessary. Same for unpin(). DRM drivers and memory managers modified by this patch will now have correct dma-buf locking semantics: the caller is responsible for holding the reservation lock when calling the pin or unpin callback. DRM drivers and memory managers that are not modified will now be protected against concurent invocation of their pin and unpin callbacks. PRIME does not implement struct dma_buf_ops.pin, which requires the caller to hold the reservation lock. It does implement struct dma_buf_ops.attach, which requires to callee to acquire the reservation lock. The PRIME code uses drm_gem_pin(), so locks are now taken as specified. Same for unpin and detach. The patch harmonizes GEM pin and unpin to have non-interruptible reservation locking across all drivers, as is already the case for vmap and vunmap. This affects gem-shmem, gem-vram, loongson, qxl and radeon. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Christian König <christian.koenig@amd.com> Reviewed-by: Zack Rusin <zack.rusin@broadcom.com> Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> # virtio-gpu Link: https://patchwork.freedesktop.org/patch/msgid/20240227113853.8464-10-tzimmermann@suse.de
70 lines
1.4 KiB
C
70 lines
1.4 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (C) 2013 Red Hat
|
|
* Author: Rob Clark <robdclark@gmail.com>
|
|
*/
|
|
|
|
#include <linux/dma-buf.h>
|
|
|
|
#include <drm/drm_prime.h>
|
|
|
|
#include "msm_drv.h"
|
|
#include "msm_gem.h"
|
|
|
|
struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj)
|
|
{
|
|
struct msm_gem_object *msm_obj = to_msm_bo(obj);
|
|
int npages = obj->size >> PAGE_SHIFT;
|
|
|
|
if (WARN_ON(!msm_obj->pages)) /* should have already pinned! */
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
return drm_prime_pages_to_sg(obj->dev, msm_obj->pages, npages);
|
|
}
|
|
|
|
int msm_gem_prime_vmap(struct drm_gem_object *obj, struct iosys_map *map)
|
|
{
|
|
void *vaddr;
|
|
|
|
vaddr = msm_gem_get_vaddr_locked(obj);
|
|
if (IS_ERR(vaddr))
|
|
return PTR_ERR(vaddr);
|
|
iosys_map_set_vaddr(map, vaddr);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void msm_gem_prime_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
|
|
{
|
|
msm_gem_put_vaddr_locked(obj);
|
|
}
|
|
|
|
struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
|
|
struct dma_buf_attachment *attach, struct sg_table *sg)
|
|
{
|
|
return msm_gem_import(dev, attach->dmabuf, sg);
|
|
}
|
|
|
|
int msm_gem_prime_pin(struct drm_gem_object *obj)
|
|
{
|
|
struct page **pages;
|
|
int ret = 0;
|
|
|
|
if (obj->import_attach)
|
|
return 0;
|
|
|
|
pages = msm_gem_pin_pages_locked(obj);
|
|
if (IS_ERR(pages))
|
|
ret = PTR_ERR(pages);
|
|
|
|
return ret;
|
|
}
|
|
|
|
void msm_gem_prime_unpin(struct drm_gem_object *obj)
|
|
{
|
|
if (obj->import_attach)
|
|
return;
|
|
|
|
msm_gem_unpin_pages_locked(obj);
|
|
}
|