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
-----BEGIN PGP SIGNATURE-----
iQEzBAABCAAdFiEEchf7rIzpz2NEoWjlaA3BHVMLeiMFAl+X8N4ACgkQaA3BHVML
eiPulggAu/RudQn0GmWPcDg9DpM30zE/ppBrmKk+WGWqj6M2DgK9gy+KhJps+Uht
Fb2jMnUirNS5ZNa5kVhkdazOKqHq5jHHV+SbRPziySzV56TW8lbPU/HOUhKSQbkF
FUB/YCWbb2kJA23So9VwNkjSJUXKpy896WoVxH7b/gLYL7c+sHUK9TOWAlsbFEmD
t3kjxQgsHdVhqaZIKE7zg72Vi1AkkhjCVraPQeZY1GgmmLxdQeEKhNO8xdfG3OzY
US4MYwJ51RfaCDTFr5t1UA224ODxoJtV3dTDDtrx4R5sf4MYJUC4SJYZHIyHyUkm
9KXjFFzB9+Hd0JjpUHFUyl+4k8JjHQ==
=GWwb
-----END PGP SIGNATURE-----
Merge tag 'drm-misc-next-2020-10-27' of git://anongit.freedesktop.org/drm/drm-misc into drm-next
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
283 lines
6.6 KiB
C
283 lines
6.6 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (c) 2015 MediaTek Inc.
|
|
*/
|
|
|
|
#include <linux/dma-buf.h>
|
|
|
|
#include <drm/drm.h>
|
|
#include <drm/drm_device.h>
|
|
#include <drm/drm_gem.h>
|
|
#include <drm/drm_gem_cma_helper.h>
|
|
#include <drm/drm_prime.h>
|
|
|
|
#include "mtk_drm_drv.h"
|
|
#include "mtk_drm_gem.h"
|
|
|
|
static const struct drm_gem_object_funcs mtk_drm_gem_object_funcs = {
|
|
.free = mtk_drm_gem_free_object,
|
|
.get_sg_table = mtk_gem_prime_get_sg_table,
|
|
.vmap = mtk_drm_gem_prime_vmap,
|
|
.vunmap = mtk_drm_gem_prime_vunmap,
|
|
.vm_ops = &drm_gem_cma_vm_ops,
|
|
};
|
|
|
|
static struct mtk_drm_gem_obj *mtk_drm_gem_init(struct drm_device *dev,
|
|
unsigned long size)
|
|
{
|
|
struct mtk_drm_gem_obj *mtk_gem_obj;
|
|
int ret;
|
|
|
|
size = round_up(size, PAGE_SIZE);
|
|
|
|
mtk_gem_obj = kzalloc(sizeof(*mtk_gem_obj), GFP_KERNEL);
|
|
if (!mtk_gem_obj)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
mtk_gem_obj->base.funcs = &mtk_drm_gem_object_funcs;
|
|
|
|
ret = drm_gem_object_init(dev, &mtk_gem_obj->base, size);
|
|
if (ret < 0) {
|
|
DRM_ERROR("failed to initialize gem object\n");
|
|
kfree(mtk_gem_obj);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
return mtk_gem_obj;
|
|
}
|
|
|
|
struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev,
|
|
size_t size, bool alloc_kmap)
|
|
{
|
|
struct mtk_drm_private *priv = dev->dev_private;
|
|
struct mtk_drm_gem_obj *mtk_gem;
|
|
struct drm_gem_object *obj;
|
|
int ret;
|
|
|
|
mtk_gem = mtk_drm_gem_init(dev, size);
|
|
if (IS_ERR(mtk_gem))
|
|
return ERR_CAST(mtk_gem);
|
|
|
|
obj = &mtk_gem->base;
|
|
|
|
mtk_gem->dma_attrs = DMA_ATTR_WRITE_COMBINE;
|
|
|
|
if (!alloc_kmap)
|
|
mtk_gem->dma_attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
|
|
|
|
mtk_gem->cookie = dma_alloc_attrs(priv->dma_dev, obj->size,
|
|
&mtk_gem->dma_addr, GFP_KERNEL,
|
|
mtk_gem->dma_attrs);
|
|
if (!mtk_gem->cookie) {
|
|
DRM_ERROR("failed to allocate %zx byte dma buffer", obj->size);
|
|
ret = -ENOMEM;
|
|
goto err_gem_free;
|
|
}
|
|
|
|
if (alloc_kmap)
|
|
mtk_gem->kvaddr = mtk_gem->cookie;
|
|
|
|
DRM_DEBUG_DRIVER("cookie = %p dma_addr = %pad size = %zu\n",
|
|
mtk_gem->cookie, &mtk_gem->dma_addr,
|
|
size);
|
|
|
|
return mtk_gem;
|
|
|
|
err_gem_free:
|
|
drm_gem_object_release(obj);
|
|
kfree(mtk_gem);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
void mtk_drm_gem_free_object(struct drm_gem_object *obj)
|
|
{
|
|
struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj);
|
|
struct mtk_drm_private *priv = obj->dev->dev_private;
|
|
|
|
if (mtk_gem->sg)
|
|
drm_prime_gem_destroy(obj, mtk_gem->sg);
|
|
else
|
|
dma_free_attrs(priv->dma_dev, obj->size, mtk_gem->cookie,
|
|
mtk_gem->dma_addr, mtk_gem->dma_attrs);
|
|
|
|
/* release file pointer to gem object. */
|
|
drm_gem_object_release(obj);
|
|
|
|
kfree(mtk_gem);
|
|
}
|
|
|
|
int mtk_drm_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
|
|
struct drm_mode_create_dumb *args)
|
|
{
|
|
struct mtk_drm_gem_obj *mtk_gem;
|
|
int ret;
|
|
|
|
args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
|
|
args->size = args->pitch * args->height;
|
|
|
|
mtk_gem = mtk_drm_gem_create(dev, args->size, false);
|
|
if (IS_ERR(mtk_gem))
|
|
return PTR_ERR(mtk_gem);
|
|
|
|
/*
|
|
* allocate a id of idr table where the obj is registered
|
|
* and handle has the id what user can see.
|
|
*/
|
|
ret = drm_gem_handle_create(file_priv, &mtk_gem->base, &args->handle);
|
|
if (ret)
|
|
goto err_handle_create;
|
|
|
|
/* drop reference from allocate - handle holds it now. */
|
|
drm_gem_object_put(&mtk_gem->base);
|
|
|
|
return 0;
|
|
|
|
err_handle_create:
|
|
mtk_drm_gem_free_object(&mtk_gem->base);
|
|
return ret;
|
|
}
|
|
|
|
static int mtk_drm_gem_object_mmap(struct drm_gem_object *obj,
|
|
struct vm_area_struct *vma)
|
|
|
|
{
|
|
int ret;
|
|
struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj);
|
|
struct mtk_drm_private *priv = obj->dev->dev_private;
|
|
|
|
/*
|
|
* dma_alloc_attrs() allocated a struct page table for mtk_gem, so clear
|
|
* VM_PFNMAP flag that was set by drm_gem_mmap_obj()/drm_gem_mmap().
|
|
*/
|
|
vma->vm_flags &= ~VM_PFNMAP;
|
|
|
|
ret = dma_mmap_attrs(priv->dma_dev, vma, mtk_gem->cookie,
|
|
mtk_gem->dma_addr, obj->size, mtk_gem->dma_attrs);
|
|
if (ret)
|
|
drm_gem_vm_close(vma);
|
|
|
|
return ret;
|
|
}
|
|
|
|
int mtk_drm_gem_mmap_buf(struct drm_gem_object *obj, struct vm_area_struct *vma)
|
|
{
|
|
int ret;
|
|
|
|
ret = drm_gem_mmap_obj(obj, obj->size, vma);
|
|
if (ret)
|
|
return ret;
|
|
|
|
return mtk_drm_gem_object_mmap(obj, vma);
|
|
}
|
|
|
|
int mtk_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
|
|
{
|
|
struct drm_gem_object *obj;
|
|
int ret;
|
|
|
|
ret = drm_gem_mmap(filp, vma);
|
|
if (ret)
|
|
return ret;
|
|
|
|
obj = vma->vm_private_data;
|
|
|
|
/*
|
|
* Set vm_pgoff (used as a fake buffer offset by DRM) to 0 and map the
|
|
* whole buffer from the start.
|
|
*/
|
|
vma->vm_pgoff = 0;
|
|
|
|
return mtk_drm_gem_object_mmap(obj, vma);
|
|
}
|
|
|
|
/*
|
|
* Allocate a sg_table for this GEM object.
|
|
* Note: Both the table's contents, and the sg_table itself must be freed by
|
|
* the caller.
|
|
* Returns a pointer to the newly allocated sg_table, or an ERR_PTR() error.
|
|
*/
|
|
struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj)
|
|
{
|
|
struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj);
|
|
struct mtk_drm_private *priv = obj->dev->dev_private;
|
|
struct sg_table *sgt;
|
|
int ret;
|
|
|
|
sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
|
|
if (!sgt)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
ret = dma_get_sgtable_attrs(priv->dma_dev, sgt, mtk_gem->cookie,
|
|
mtk_gem->dma_addr, obj->size,
|
|
mtk_gem->dma_attrs);
|
|
if (ret) {
|
|
DRM_ERROR("failed to allocate sgt, %d\n", ret);
|
|
kfree(sgt);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
return sgt;
|
|
}
|
|
|
|
struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev,
|
|
struct dma_buf_attachment *attach, struct sg_table *sg)
|
|
{
|
|
struct mtk_drm_gem_obj *mtk_gem;
|
|
|
|
/* check if the entries in the sg_table are contiguous */
|
|
if (drm_prime_get_contiguous_size(sg) < attach->dmabuf->size) {
|
|
DRM_ERROR("sg_table is not contiguous");
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
|
|
mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size);
|
|
if (IS_ERR(mtk_gem))
|
|
return ERR_CAST(mtk_gem);
|
|
|
|
mtk_gem->dma_addr = sg_dma_address(sg->sgl);
|
|
mtk_gem->sg = sg;
|
|
|
|
return &mtk_gem->base;
|
|
}
|
|
|
|
void *mtk_drm_gem_prime_vmap(struct drm_gem_object *obj)
|
|
{
|
|
struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj);
|
|
struct sg_table *sgt;
|
|
unsigned int npages;
|
|
|
|
if (mtk_gem->kvaddr)
|
|
return mtk_gem->kvaddr;
|
|
|
|
sgt = mtk_gem_prime_get_sg_table(obj);
|
|
if (IS_ERR(sgt))
|
|
return NULL;
|
|
|
|
npages = obj->size >> PAGE_SHIFT;
|
|
mtk_gem->pages = kcalloc(npages, sizeof(*mtk_gem->pages), GFP_KERNEL);
|
|
if (!mtk_gem->pages)
|
|
goto out;
|
|
|
|
drm_prime_sg_to_page_addr_arrays(sgt, mtk_gem->pages, NULL, npages);
|
|
|
|
mtk_gem->kvaddr = vmap(mtk_gem->pages, npages, VM_MAP,
|
|
pgprot_writecombine(PAGE_KERNEL));
|
|
|
|
out:
|
|
kfree(sgt);
|
|
|
|
return mtk_gem->kvaddr;
|
|
}
|
|
|
|
void mtk_drm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
|
|
{
|
|
struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj);
|
|
|
|
if (!mtk_gem->pages)
|
|
return;
|
|
|
|
vunmap(vaddr);
|
|
mtk_gem->kvaddr = 0;
|
|
kfree(mtk_gem->pages);
|
|
}
|