mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
drm-misc-next for 5.11:
UAPI Changes:
- doc: rules for EBUSY on non-blocking commits; requirements for fourcc
modifiers; on parsing EDID
- fbdev/sbuslib: Remove unused FBIOSCURSOR32
- fourcc: deprecate DRM_FORMAT_MOD_NONE
- virtio: Support blob resources for memory allocations; Expose host-visible
and cross-device features
Cross-subsystem Changes:
- devicetree: Add vendor Prefix for Yes Optoelectronics, Shanghai Top Display
Optoelectronics
- dma-buf: Add struct dma_buf_map that stores DMA pointer and I/O-memory flag;
dma_buf_vmap()/vunmap() return address in dma_buf_map; Use struct_size() macro
Core Changes:
- atomic: pass full state to CRTC atomic enable/disable; warn for EBUSY during
non-blocking commits
- dp: Prepare for DP 2.0 DPCD
- dp_mst: Receive extended DPCD caps
- dma-buf: Documentation
- doc: Format modifiers; dma-buf-map; Cleanups
- fbdev: Don't use compat_alloc_user_space(); mark as orphaned
- fb-helper: Take lock in drm_fb_helper_restore_work_fb()
- gem: Convert implementation and drivers to GEM object functions, remove
GEM callbacks from struct drm_driver (expect gem_prime_mmap)
- panel: Cleanups
- pci: Add legacy infix to drm_irq_by_busid()
- sched: Avoid infinite waits in drm_sched_entity_destroy()
- switcheroo: Cleanups
- ttm: Remove AGP support; Don't modify caching during swapout; Major
refactoring of the implementation and API that affects all depending
drivers; Add ttm_bo_wait_ctx(); Add ttm_bo_pin()/unpin() in favor of
TTM_PL_FLAG_NO_EVICT; Remove ttm_bo_create(); Remove fault_reserve_notify()
callback; Push move() implementation into drivers; Remove TTM_PAGE_FLAG_WRITE;
Replace caching flags with init-time cache setting; Push ttm_tt_bind() into
drivers; Replace move_notify() with delete_mem_notify(); No overlapping memcpy();
no more ttm_set_populated()
- vram-helper: Fix BO top-down placement; TTM-related changes; Init GEM
object functions with defaults; Default placement in system memory; Cleanups
Driver Changes:
- amdgpu: Use GEM object functions
- armada: Use GEM object functions
- aspeed: Configure output via sysfs; Init struct drm_driver with
- ast: Reload LUT after FB format changes
- bridge: Add driver and DT bindings for anx7625; Cleanups
- bridge/dw-hdmi: Constify ops
- bridge/ti-sn65dsi86: Add retries for link training
- bridge/lvds-codec: Add support for regulator
- bridge/tc358768: Restore connector support DRM_GEM_CMA_DRIVEROPS; Cleanups
- display/ti,j721e-dss: Add DT properies assigned-clocks, assigned-clocks-parent and
dma-coherent
- display/ti,am65s-dss: Add DT properies assigned-clocks, assigned-clocks-parent and
dma-coherent
- etnaviv: Use GEM object functions
- exynos: Use GEM object functions
- fbdev: Cleanups and compiler fixes throughout framebuffer drivers
- fbdev/cirrusfb: Avoid division by 0
- gma500: Use GEM object functions; Fix double-free of connector; Cleanups
- hisilicon/hibmc: I2C-based DDC support; Use to_hibmc_drm_device(); Cleanups
- i915: Use GEM object functions
- imx/dcss: Init driver with DRM_GEM_CMA_DRIVER_OPS; Cleanups
- ingenic: Reset pixel clock when parent clock changes; support reserved
memory; Alloc F0 and F1 DMA channels at once; Support different pixel formats;
Revert support for cached mmap buffers
on F0/F1; support 30-bit/24-bit/8-bit-palette modes
- komeda: Use DEFINE_SHOW_ATTRIBUTE
- mcde: Detect platform_get_irq() errors
- mediatek: Use GEM object functions
- msm: Use GEM object functions
- nouveau: Cleanups; TTM-related changes; Use GEM object functions
- omapdrm: Use GEM object functions
- panel: Add driver and DT bindings for Novatak nt36672a; Add driver and DT
bindings for YTC700TLAG-05-201C; Add driver and DT bindings for TDO TL070WSH30;
Cleanups
- panel/mantix: Fix reset; Fix deref of NULL pointer in mantix_get_modes()
- panel/otm8009a: Allow non-continuous dsi clock; Cleanups
- panel/rm68200: Allow non-continuous dsi clock; Fix mode to 50 FPS
- panfrost: Fix job timeout handling; Cleanups
- pl111: Use GEM object functions
- qxl: Cleanups; TTM-related changes; Pin new BOs with ttm_bo_init_reserved()
- radeon: Cleanups; TTM-related changes; Use GEM object functions
- rockchip: Use GEM object functions
- shmobile: Cleanups
- tegra: Use GEM object functions
- tidss: Set drm_plane_helper_funcs.prepare_fb
- tilcdc: Don't keep vblank interrupt enabled all the time
- tve200: Detect platform_get_irq() errors
- vc4: Use GEM object functions; Only register components once DSI is attached;
Add Maxime as maintainer
- vgem: Use GEM object functions
- via: Simplify critical section in via_mem_alloc()
- virtgpu: Use GEM object functions
- virtio: Implement blob resources, host-visible and cross-device features;
Support mapping of host-allocated resources; Use UUID APi; Cleanups
- vkms: Use GEM object functions; Switch to SHMEM
- vmwgfx: TTM-related changes; Inline ttm_bo_swapout_all()
- xen: Use GEM object functions
- xlnx: Use GEM object functions
Signed-off-by: Dave Airlie <airlied@redhat.com>
From: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20201027100936.GA4858@linux-uq9g
289 lines
6.9 KiB
C
289 lines
6.9 KiB
C
/*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* Copyright 2012 Red Hat Inc
|
|
*/
|
|
|
|
#include <linux/dma-buf.h>
|
|
#include <linux/highmem.h>
|
|
#include <linux/dma-resv.h>
|
|
|
|
#include "i915_drv.h"
|
|
#include "i915_gem_object.h"
|
|
#include "i915_scatterlist.h"
|
|
|
|
static struct drm_i915_gem_object *dma_buf_to_obj(struct dma_buf *buf)
|
|
{
|
|
return to_intel_bo(buf->priv);
|
|
}
|
|
|
|
static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachment,
|
|
enum dma_data_direction dir)
|
|
{
|
|
struct drm_i915_gem_object *obj = dma_buf_to_obj(attachment->dmabuf);
|
|
struct sg_table *st;
|
|
struct scatterlist *src, *dst;
|
|
int ret, i;
|
|
|
|
ret = i915_gem_object_pin_pages(obj);
|
|
if (ret)
|
|
goto err;
|
|
|
|
/* Copy sg so that we make an independent mapping */
|
|
st = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
|
|
if (st == NULL) {
|
|
ret = -ENOMEM;
|
|
goto err_unpin_pages;
|
|
}
|
|
|
|
ret = sg_alloc_table(st, obj->mm.pages->nents, GFP_KERNEL);
|
|
if (ret)
|
|
goto err_free;
|
|
|
|
src = obj->mm.pages->sgl;
|
|
dst = st->sgl;
|
|
for (i = 0; i < obj->mm.pages->nents; i++) {
|
|
sg_set_page(dst, sg_page(src), src->length, 0);
|
|
dst = sg_next(dst);
|
|
src = sg_next(src);
|
|
}
|
|
|
|
ret = dma_map_sgtable(attachment->dev, st, dir, DMA_ATTR_SKIP_CPU_SYNC);
|
|
if (ret)
|
|
goto err_free_sg;
|
|
|
|
return st;
|
|
|
|
err_free_sg:
|
|
sg_free_table(st);
|
|
err_free:
|
|
kfree(st);
|
|
err_unpin_pages:
|
|
i915_gem_object_unpin_pages(obj);
|
|
err:
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
|
|
struct sg_table *sg,
|
|
enum dma_data_direction dir)
|
|
{
|
|
struct drm_i915_gem_object *obj = dma_buf_to_obj(attachment->dmabuf);
|
|
|
|
dma_unmap_sgtable(attachment->dev, sg, dir, DMA_ATTR_SKIP_CPU_SYNC);
|
|
sg_free_table(sg);
|
|
kfree(sg);
|
|
|
|
i915_gem_object_unpin_pages(obj);
|
|
}
|
|
|
|
static int i915_gem_dmabuf_vmap(struct dma_buf *dma_buf, struct dma_buf_map *map)
|
|
{
|
|
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
|
|
void *vaddr;
|
|
|
|
vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
|
|
if (IS_ERR(vaddr))
|
|
return PTR_ERR(vaddr);
|
|
|
|
dma_buf_map_set_vaddr(map, vaddr);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void i915_gem_dmabuf_vunmap(struct dma_buf *dma_buf, struct dma_buf_map *map)
|
|
{
|
|
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
|
|
|
|
i915_gem_object_flush_map(obj);
|
|
i915_gem_object_unpin_map(obj);
|
|
}
|
|
|
|
static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
|
|
{
|
|
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
|
|
int ret;
|
|
|
|
if (obj->base.size < vma->vm_end - vma->vm_start)
|
|
return -EINVAL;
|
|
|
|
if (!obj->base.filp)
|
|
return -ENODEV;
|
|
|
|
ret = call_mmap(obj->base.filp, vma);
|
|
if (ret)
|
|
return ret;
|
|
|
|
fput(vma->vm_file);
|
|
vma->vm_file = get_file(obj->base.filp);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction)
|
|
{
|
|
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
|
|
bool write = (direction == DMA_BIDIRECTIONAL || direction == DMA_TO_DEVICE);
|
|
int err;
|
|
|
|
err = i915_gem_object_pin_pages(obj);
|
|
if (err)
|
|
return err;
|
|
|
|
err = i915_gem_object_lock_interruptible(obj, NULL);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = i915_gem_object_set_to_cpu_domain(obj, write);
|
|
i915_gem_object_unlock(obj);
|
|
|
|
out:
|
|
i915_gem_object_unpin_pages(obj);
|
|
return err;
|
|
}
|
|
|
|
static int i915_gem_end_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction)
|
|
{
|
|
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
|
|
int err;
|
|
|
|
err = i915_gem_object_pin_pages(obj);
|
|
if (err)
|
|
return err;
|
|
|
|
err = i915_gem_object_lock_interruptible(obj, NULL);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = i915_gem_object_set_to_gtt_domain(obj, false);
|
|
i915_gem_object_unlock(obj);
|
|
|
|
out:
|
|
i915_gem_object_unpin_pages(obj);
|
|
return err;
|
|
}
|
|
|
|
static const struct dma_buf_ops i915_dmabuf_ops = {
|
|
.map_dma_buf = i915_gem_map_dma_buf,
|
|
.unmap_dma_buf = i915_gem_unmap_dma_buf,
|
|
.release = drm_gem_dmabuf_release,
|
|
.mmap = i915_gem_dmabuf_mmap,
|
|
.vmap = i915_gem_dmabuf_vmap,
|
|
.vunmap = i915_gem_dmabuf_vunmap,
|
|
.begin_cpu_access = i915_gem_begin_cpu_access,
|
|
.end_cpu_access = i915_gem_end_cpu_access,
|
|
};
|
|
|
|
struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags)
|
|
{
|
|
struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
|
|
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
|
|
|
|
exp_info.ops = &i915_dmabuf_ops;
|
|
exp_info.size = gem_obj->size;
|
|
exp_info.flags = flags;
|
|
exp_info.priv = gem_obj;
|
|
exp_info.resv = obj->base.resv;
|
|
|
|
if (obj->ops->dmabuf_export) {
|
|
int ret = obj->ops->dmabuf_export(obj);
|
|
if (ret)
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
return drm_gem_dmabuf_export(gem_obj->dev, &exp_info);
|
|
}
|
|
|
|
static int i915_gem_object_get_pages_dmabuf(struct drm_i915_gem_object *obj)
|
|
{
|
|
struct sg_table *pages;
|
|
unsigned int sg_page_sizes;
|
|
|
|
pages = dma_buf_map_attachment(obj->base.import_attach,
|
|
DMA_BIDIRECTIONAL);
|
|
if (IS_ERR(pages))
|
|
return PTR_ERR(pages);
|
|
|
|
sg_page_sizes = i915_sg_page_sizes(pages->sgl);
|
|
|
|
__i915_gem_object_set_pages(obj, pages, sg_page_sizes);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void i915_gem_object_put_pages_dmabuf(struct drm_i915_gem_object *obj,
|
|
struct sg_table *pages)
|
|
{
|
|
dma_buf_unmap_attachment(obj->base.import_attach, pages,
|
|
DMA_BIDIRECTIONAL);
|
|
}
|
|
|
|
static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = {
|
|
.name = "i915_gem_object_dmabuf",
|
|
.get_pages = i915_gem_object_get_pages_dmabuf,
|
|
.put_pages = i915_gem_object_put_pages_dmabuf,
|
|
};
|
|
|
|
struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
|
|
struct dma_buf *dma_buf)
|
|
{
|
|
static struct lock_class_key lock_class;
|
|
struct dma_buf_attachment *attach;
|
|
struct drm_i915_gem_object *obj;
|
|
int ret;
|
|
|
|
/* is this one of own objects? */
|
|
if (dma_buf->ops == &i915_dmabuf_ops) {
|
|
obj = dma_buf_to_obj(dma_buf);
|
|
/* is it from our device? */
|
|
if (obj->base.dev == dev) {
|
|
/*
|
|
* Importing dmabuf exported from out own gem increases
|
|
* refcount on gem itself instead of f_count of dmabuf.
|
|
*/
|
|
return &i915_gem_object_get(obj)->base;
|
|
}
|
|
}
|
|
|
|
/* need to attach */
|
|
attach = dma_buf_attach(dma_buf, dev->dev);
|
|
if (IS_ERR(attach))
|
|
return ERR_CAST(attach);
|
|
|
|
get_dma_buf(dma_buf);
|
|
|
|
obj = i915_gem_object_alloc();
|
|
if (obj == NULL) {
|
|
ret = -ENOMEM;
|
|
goto fail_detach;
|
|
}
|
|
|
|
drm_gem_private_object_init(dev, &obj->base, dma_buf->size);
|
|
i915_gem_object_init(obj, &i915_gem_object_dmabuf_ops, &lock_class);
|
|
obj->base.import_attach = attach;
|
|
obj->base.resv = dma_buf->resv;
|
|
|
|
/* We use GTT as shorthand for a coherent domain, one that is
|
|
* neither in the GPU cache nor in the CPU cache, where all
|
|
* writes are immediately visible in memory. (That's not strictly
|
|
* true, but it's close! There are internal buffers such as the
|
|
* write-combined buffer or a delay through the chipset for GTT
|
|
* writes that do require us to treat GTT as a separate cache domain.)
|
|
*/
|
|
obj->read_domains = I915_GEM_DOMAIN_GTT;
|
|
obj->write_domain = 0;
|
|
|
|
return &obj->base;
|
|
|
|
fail_detach:
|
|
dma_buf_detach(dma_buf, attach);
|
|
dma_buf_put(dma_buf);
|
|
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
|
|
#include "selftests/mock_dmabuf.c"
|
|
#include "selftests/i915_gem_dmabuf.c"
|
|
#endif
|