VC4 3D rendering support.
Subsystems (3)
v2 cover VC4 3D rendering support.
Updated version of the patch series for Emil's comments about vc4_drm.h. I also pulled in some improvements to the validation code which I'd written in Mesa and failed to propagate to this branch.
The series can be found at:
https://github.com/anholt/linux/tree/vc4-kms-v3d-squash-2
and a version for booting and testing can be found at:
https://github.com/anholt/linux/tree/vc4-kms-v3d-squash-2-boot
Eric Anholt (9):
drm: Create a driver hook for allocating GEM object structs. drm/vc4: Add a BO cache.
drm/vc4: Add create and map BO ioctls.
drm/vc4: Add an API for creating GPU shaders in GEM BOs. drm/vc4: Fix a typo in a V3D debug register.
drm/vc4: Bind and initialize the V3D engine.
drm/vc4: Add support for drawing 3D frames.
drm/vc4: Add support for async pageflips.
drm/vc4: Add an interface for capturing the GPU state after a hang.
drivers/gpu/drm/drm_gem_cma_helper.c | 10 +- drivers/gpu/drm/vc4/Makefile | 11 +- drivers/gpu/drm/vc4/vc4_bo.c | 517 ++++++++++++++++- drivers/gpu/drm/vc4/vc4_crtc.c | 99 +++- drivers/gpu/drm/vc4/vc4_debugfs.c | 3 + drivers/gpu/drm/vc4/vc4_drv.c | 36 +- drivers/gpu/drm/vc4/vc4_drv.h | 318 +++++++++- drivers/gpu/drm/vc4/vc4_gem.c | 867 +++++++++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_irq.c | 210 +++++++ drivers/gpu/drm/vc4/vc4_kms.c | 149 ++++- drivers/gpu/drm/vc4/vc4_packet.h | 399 +++++++++++++ drivers/gpu/drm/vc4/vc4_plane.c | 40 ++ drivers/gpu/drm/vc4/vc4_qpu_defines.h | 264 +++++++++ drivers/gpu/drm/vc4/vc4_regs.h | 2 +- drivers/gpu/drm/vc4/vc4_render_cl.c | 634 ++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_trace.h | 63 ++ drivers/gpu/drm/vc4/vc4_trace_points.c | 14 + drivers/gpu/drm/vc4/vc4_v3d.c | 262 +++++++++ drivers/gpu/drm/vc4/vc4_validate.c | 900 +++++++++++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_validate_shaders.c | 513 ++++++++++++++++ include/drm/drmP.h | 7 + include/uapi/drm/Kbuild | 1 + include/uapi/drm/vc4_drm.h | 279 +++++++++ 23 files changed, 5577 insertions(+), 21 deletions(-) create mode 100644 drivers/gpu/drm/vc4/vc4_gem.c create mode 100644 drivers/gpu/drm/vc4/vc4_irq.c create mode 100644 drivers/gpu/drm/vc4/vc4_packet.h create mode 100644 drivers/gpu/drm/vc4/vc4_qpu_defines.h create mode 100644 drivers/gpu/drm/vc4/vc4_render_cl.c create mode 100644 drivers/gpu/drm/vc4/vc4_trace.h create mode 100644 drivers/gpu/drm/vc4/vc4_trace_points.c create mode 100644 drivers/gpu/drm/vc4/vc4_v3d.c create mode 100644 drivers/gpu/drm/vc4/vc4_validate.c create mode 100644 drivers/gpu/drm/vc4/vc4_validate_shaders.c create mode 100644 include/uapi/drm/vc4_drm.h
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 1/9 drm: Create a driver hook for allocating GEM object structs.
The CMA helpers had no way for a driver to extend the struct with its own fields. Since the CMA helpers are mostly "Allocate a drm_gem_cma_object, then fill in a few fields", it's hard to write as pure helpers without passing in a driver callback for the allocate step.
--- drivers/gpu/drm/drm_gem_cma_helper.c | 10 ++++++---- include/drm/drmP.h | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem_cma_helper.c +6 -4
@@ -59,11 +59,13 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size)struct drm_gem_object *gem_obj;int ret; - cma_obj =kzalloc (sizeof (*cma_obj),GFP_KERNEL ); -if (!cma_obj) +if (drm->driver->gem_create_object) + gem_obj = drm->driver->gem_create_object (drm, size); +else + gem_obj =kzalloc (sizeof (*cma_obj),GFP_KERNEL ); +if (!gem_obj)return ERR_PTR (-ENOMEM ); - - gem_obj = &cma_obj->base; + cma_obj = container_of(gem_obj, struct drm_gem_cma_object, base); ret =drm_gem_object_init (drm, gem_obj, size);if (ret)
include/drm/drmP.h +7 -0
@@ -580,6 +580,13 @@ struct drm_driver {int (*gem_open_object) (struct drm_gem_object *,struct drm_file *);void (*gem_close_object) (struct drm_gem_object *,struct drm_file *); +/** +* Hook for allocating the GEM object struct, for use by core +* helpers. +*/ +struct drm_gem_object *(*gem_create_object)(struct drm_device *dev, +size_t size); +/* prime: */ /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */ int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 2/9 drm/vc4: Add a BO cache.
In reply to Eric AnholtWe need to allocate new BOs in the kernel as part of each frame, but the CMA allocator is way too slow for that. As an optimization, keep track of recently-freed BOs and reuse them, with a 1 second timeout to fully free them back to the system.
This improves 3D performance by about 15%.
--- drivers/gpu/drm/vc4/vc4_bo.c | 336 +++++++++++++++++++++++++++++++++++++- drivers/gpu/drm/vc4/vc4_debugfs.c | 1 + drivers/gpu/drm/vc4/vc4_drv.c | 6 +- drivers/gpu/drm/vc4/vc4_drv.h | 49 +++++- 4 files changed, 384 insertions(+), 8 deletions(-)
drivers/gpu/drm/vc4/vc4_bo.c +330 -6
@@ -12,19 +12,229 @@* access to system memory with no MMU in between. To support it, we * use the GEM CMA helper functions to allocate contiguous ranges of * physical memory for our BOs. +* +* Since the CMA allocator is very slow, we keep a cache of recently +* freed BOs around so that the kernel's allocation of objects for 3D +* rendering can return quickly. */ #include "vc4_drv.h" -struct vc4_bo *vc4_bo_create (struct drm_device *dev,size_t size) +static void vc4_bo_stats_dump (struct vc4_dev *vc4) +{ +DRM_INFO ("num bos allocated: %d\n" , + vc4->bo_stats.num_allocated); +DRM_INFO ("size bos allocated: %dkb\n" , + vc4->bo_stats.size_allocated /1024 ); +DRM_INFO ("num bos used: %d\n" , + vc4->bo_stats.num_allocated - vc4->bo_stats.num_cached); +DRM_INFO ("size bos used: %dkb\n" , + (vc4->bo_stats.size_allocated - + vc4->bo_stats.size_cached) /1024 ); +DRM_INFO ("num bos cached: %d\n" , + vc4->bo_stats.num_cached); +DRM_INFO ("size bos cached: %dkb\n" , + vc4->bo_stats.size_cached /1024 ); +} + +#ifdef CONFIG_DEBUG_FS +int vc4_bo_stats_debugfs (struct seq_file *m,void *unused) +{ +struct drm_info_node *node = (struct drm_info_node *)m->private; +struct drm_device *dev = node->minor->dev; +struct vc4_dev *vc4 =to_vc4_dev (dev); +struct vc4_bo_stats stats; + +/* Take a snapshot of the current stats with the lock held. */ +mutex_lock (&vc4->bo_lock); + stats = vc4->bo_stats; +mutex_unlock (&vc4->bo_lock); + +seq_printf (m,"num bos allocated: %d\n" , + stats.num_allocated); +seq_printf (m,"size bos allocated: %dkb\n" , + stats.size_allocated /1024 ); +seq_printf (m,"num bos used: %d\n" , + stats.num_allocated - stats.num_cached); +seq_printf (m,"size bos used: %dkb\n" , + (stats.size_allocated - stats.size_cached) /1024 ); +seq_printf (m,"num bos cached: %d\n" , + stats.num_cached); +seq_printf (m,"size bos cached: %dkb\n" , + stats.size_cached /1024 ); + +return 0 ; +} +#endif + +static uint32_t bo_page_index (size_t size) +{ +return (size /PAGE_SIZE ) -1 ; +} + +/* Must be called with bo_lock held. */ +static void vc4_bo_destroy (struct vc4_bo *bo) { +struct drm_gem_object *obj = &bo->base.base; +struct vc4_dev *vc4 =to_vc4_dev (obj->dev); + + vc4->bo_stats.num_allocated--; + vc4->bo_stats.size_allocated -= obj->size; +drm_gem_cma_free_object (obj); +} + +/* Must be called with bo_lock held. */ +static void vc4_bo_remove_from_cache (struct vc4_bo *bo) +{ +struct drm_gem_object *obj = &bo->base.base; +struct vc4_dev *vc4 =to_vc4_dev (obj->dev); + + vc4->bo_stats.num_cached--; + vc4->bo_stats.size_cached -= obj->size; + +list_del (&bo->unref_head); +list_del (&bo->size_head); +} + +static struct list_head *vc4_get_cache_list_for_size (struct drm_device *dev, +size_t size) +{ +struct vc4_dev *vc4 =to_vc4_dev (dev); +uint32_t page_index =bo_page_index (size); + +if (vc4->bo_cache.size_list_size <= page_index) { +uint32_t new_size =max (vc4->bo_cache.size_list_size *2 , + page_index +1 ); +struct list_head *new_list; +uint32_t i; + + new_list =kmalloc_array (new_size,sizeof (struct list_head ), +GFP_KERNEL ); +if (!new_list) +return NULL ; + +/* Rebase the old cached BO lists to their new list +* head locations. +*/ +for (i =0 ; i < vc4->bo_cache.size_list_size; i++) { +struct list_head *old_list = + &vc4->bo_cache.size_list[i]; + +if (list_empty (old_list)) +INIT_LIST_HEAD (&new_list[i]); +else +list_replace (old_list, &new_list[i]); + } +/* And initialize the brand new BO list heads. */ +for (i = vc4->bo_cache.size_list_size; i < new_size; i++) +INIT_LIST_HEAD (&new_list[i]); + +kfree (vc4->bo_cache.size_list); + vc4->bo_cache.size_list = new_list; + vc4->bo_cache.size_list_size = new_size; + } + +return &vc4->bo_cache.size_list[page_index]; +} + +void vc4_bo_cache_purge (struct drm_device *dev) +{ +struct vc4_dev *vc4 =to_vc4_dev (dev); + +mutex_lock (&vc4->bo_lock); +while (!list_empty (&vc4->bo_cache.time_list)) { +struct vc4_bo *bo =list_last_entry (&vc4->bo_cache.time_list, + struct vc4_bo, unref_head); +vc4_bo_remove_from_cache (bo); +vc4_bo_destroy (bo); + } +mutex_unlock (&vc4->bo_lock); +} + +static struct vc4_bo *vc4_bo_get_from_cache (struct drm_device *dev, +uint32_t size) +{ +struct vc4_dev *vc4 =to_vc4_dev (dev); +uint32_t page_index =bo_page_index (size); +struct vc4_bo *bo =NULL ; + + size =roundup (size,PAGE_SIZE ); + +mutex_lock (&vc4->bo_lock); +if (page_index >= vc4->bo_cache.size_list_size) + goto out; + +if (list_empty (&vc4->bo_cache.size_list[page_index])) + goto out; + + bo =list_first_entry (&vc4->bo_cache.size_list[page_index], + struct vc4_bo, size_head); +vc4_bo_remove_from_cache (bo); +kref_init (&bo->base.base.refcount); + +out: +mutex_unlock (&vc4->bo_lock); +return bo; +} + +/** +* vc4_gem_create_object - Implementation of driver->gem_create_object. +* +* This lets the CMA helpers allocate object structs for us, and keep +* our BO stats correct. +*/ +struct drm_gem_object *vc4_create_object (struct drm_device *dev,size_t size) +{ +struct vc4_dev *vc4 =to_vc4_dev (dev); +struct vc4_bo *bo; + + bo =kzalloc (sizeof (*bo),GFP_KERNEL ); +if (!bo) +return ERR_PTR (-ENOMEM ); + +mutex_lock (&vc4->bo_lock); + vc4->bo_stats.num_allocated++; + vc4->bo_stats.size_allocated += size; +mutex_unlock (&vc4->bo_lock); + +return &bo->base.base; +} + +struct vc4_bo *vc4_bo_create (struct drm_device *dev,size_t unaligned_size, +bool from_cache) +{ +size_t size =roundup (unaligned_size,PAGE_SIZE ); +struct vc4_dev *vc4 =to_vc4_dev (dev);struct drm_gem_cma_object *cma_obj; - cma_obj =drm_gem_cma_create (dev, size); -if (IS_ERR (cma_obj)) +if (size ==0 )return NULL ; -else -return to_vc4_bo (&cma_obj->base); + +/* First, try to get a vc4_bo from the kernel BO cache. */ +if (from_cache) { +struct vc4_bo *bo =vc4_bo_get_from_cache (dev, size); + +if (bo) +return bo; + } + + cma_obj =drm_gem_cma_create (dev, size); +if (IS_ERR (cma_obj)) { +/* +* If we've run out of CMA memory, kill the cache of +* CMA allocations we've got laying around and try again. +*/ +vc4_bo_cache_purge (dev); + + cma_obj =drm_gem_cma_create (dev, size); +if (IS_ERR (cma_obj)) { +DRM_ERROR ("Failed to allocate from CMA:\n" ); +vc4_bo_stats_dump (vc4); +return NULL ; + } + } + +return to_vc4_bo (&cma_obj->base); } int vc4_dumb_create(struct drm_file *file_priv,
@@ -41,7 +251,7 @@ int vc4_dumb_create(struct drm_file *file_priv,if (args->size < args->pitch * args->height) args->size = args->pitch * args->height; - bo =vc4_bo_create (dev,roundup (args->size,PAGE_SIZE )); + bo =vc4_bo_create (dev, args->size, false);if (!bo)return -ENOMEM ;
@@ -50,3 +260,117 @@ int vc4_dumb_create(struct drm_file *file_priv,return ret; } + +/* Must be called with bo_lock held. */ +static void vc4_bo_cache_free_old (struct drm_device *dev) +{ +struct vc4_dev *vc4 =to_vc4_dev (dev); +unsigned long expire_time = jiffies -msecs_to_jiffies (1000 ); + +while (!list_empty (&vc4->bo_cache.time_list)) { +struct vc4_bo *bo =list_last_entry (&vc4->bo_cache.time_list, + struct vc4_bo, unref_head); +if (time_before (expire_time, bo->free_time)) { +mod_timer (&vc4->bo_cache.time_timer, +round_jiffies_up (jiffies + +msecs_to_jiffies (1000 ))); +return ; + } + +vc4_bo_remove_from_cache (bo); +vc4_bo_destroy (bo); + } +} + +/* Called on the last userspace/kernel unreference of the BO. Returns +* it to the BO cache if possible, otherwise frees it. +* +* Note that this is called with the struct_mutex held. +*/ +void vc4_free_object (struct drm_gem_object *gem_bo) +{ +struct drm_device *dev = gem_bo->dev; +struct vc4_dev *vc4 =to_vc4_dev (dev); +struct vc4_bo *bo =to_vc4_bo (gem_bo); +struct list_head *cache_list; + +mutex_lock (&vc4->bo_lock); +/* If the object references someone else's memory, we can't cache it. +*/ +if (gem_bo->import_attach) { +vc4_bo_destroy (bo); + goto out; + } + +/* Don't cache if it was publicly named. */ +if (gem_bo->name) { +vc4_bo_destroy (bo); + goto out; + } + + cache_list =vc4_get_cache_list_for_size (dev, gem_bo->size); +if (!cache_list) { +vc4_bo_destroy (bo); + goto out; + } + + bo->free_time = jiffies; +list_add (&bo->size_head, cache_list); +list_add (&bo->unref_head, &vc4->bo_cache.time_list); + + vc4->bo_stats.num_cached++; + vc4->bo_stats.size_cached += gem_bo->size; + +vc4_bo_cache_free_old (dev); + +out: +mutex_unlock (&vc4->bo_lock); +} + +static void vc4_bo_cache_time_work (struct work_struct *work) +{ +struct vc4_dev *vc4 = + container_of(work, struct vc4_dev, bo_cache.time_work); +struct drm_device *dev = vc4->dev; + +mutex_lock (&vc4->bo_lock); +vc4_bo_cache_free_old (dev); +mutex_unlock (&vc4->bo_lock); +} + +static void vc4_bo_cache_time_timer (unsigned long data) +{ +struct drm_device *dev = (struct drm_device *)data; +struct vc4_dev *vc4 =to_vc4_dev (dev); + +schedule_work (&vc4->bo_cache.time_work); +} + +void vc4_bo_cache_init (struct drm_device *dev) +{ +struct vc4_dev *vc4 =to_vc4_dev (dev); + +mutex_init (&vc4->bo_lock); + +INIT_LIST_HEAD (&vc4->bo_cache.time_list); + +INIT_WORK (&vc4->bo_cache.time_work, vc4_bo_cache_time_work); +setup_timer (&vc4->bo_cache.time_timer, + vc4_bo_cache_time_timer, + (unsigned long )dev); +} + +void vc4_bo_cache_destroy (struct drm_device *dev) +{ +struct vc4_dev *vc4 =to_vc4_dev (dev); + +del_timer (&vc4->bo_cache.time_timer); +cancel_work_sync (&vc4->bo_cache.time_work); + +vc4_bo_cache_purge (dev); + +if (vc4->bo_stats.num_allocated) { +DRM_ERROR ("Destroying BO cache while BOs still allocated:\n" ); +vc4_bo_stats_dump (vc4); + } +}
drivers/gpu/drm/vc4/vc4_debugfs.c +1 -0
@@ -16,6 +16,7 @@#include "vc4_regs.h" static const struct drm_info_list vc4_debugfs_list[] = { + {"bo_stats" , vc4_bo_stats_debugfs,0 }, {"hdmi_regs" , vc4_hdmi_debugfs_regs,0 }, {"hvs_regs" , vc4_hvs_debugfs_regs,0 }, {"crtc0_regs" , vc4_crtc_debugfs_regs,0 , (void *)(uintptr_t )0 },
drivers/gpu/drm/vc4/vc4_drv.c +5 -1
@@ -92,7 +92,8 @@ static struct drm_driver vc4_drm_driver = { .debugfs_cleanup = vc4_debugfs_cleanup, #endif - .gem_free_object = drm_gem_cma_free_object, + .gem_create_object = vc4_create_object, + .gem_free_object = vc4_free_object, .gem_vm_ops = &drm_gem_cma_vm_ops, .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
@@ -170,6 +171,8 @@ static int vc4_drm_bind(struct device *dev)drm_dev_set_unique (drm,dev_name (dev)); +vc4_bo_cache_init (drm); +drm_mode_config_init (drm);if (ret) goto unref;
@@ -202,6 +205,7 @@ unbind_all:component_unbind_all (dev, drm); unref:drm_dev_unref (drm); +vc4_bo_cache_destroy (drm);return ret; }
drivers/gpu/drm/vc4/vc4_drv.h +48 -1
73 lines not on this page · raw message
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 3/9 drm/vc4: Add create and map BO ioctls.
In reply to Eric AnholtWhile there exist dumb APIs for creating and mapping BOs, one of the rules is that drivers doing 3D acceleration have to provide their own APIs for buffer allocation (besides, the pitch/height parameters of the dumb alloc don't really make sense for a lot of 3D allocations).
---
v2: Use __u32-style types, use "drm.h" instead of <drm/drm.h>.
drivers/gpu/drm/vc4/vc4_bo.c | 41 ++++++++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_drv.c | 3 ++ drivers/gpu/drm/vc4/vc4_drv.h | 4 +++ include/uapi/drm/Kbuild | 1 + include/uapi/drm/vc4_drm.h | 68 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 include/uapi/drm/vc4_drm.h
drivers/gpu/drm/vc4/vc4_bo.c +41 -0
@@ -19,6 +19,7 @@*/ #include "vc4_drv.h" +#include "uapi/drm/vc4_drm.h" static void vc4_bo_stats_dump (struct vc4_dev *vc4) {
@@ -346,6 +347,46 @@ static void vc4_bo_cache_time_timer(unsigned long data)schedule_work (&vc4->bo_cache.time_work); } +int vc4_create_bo_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_vc4_create_bo *args = data; +struct vc4_bo *bo =NULL ; +int ret; + +/* +* We can't allocate from the BO cache, because the BOs don't +* get zeroed, and that might leak data between users. +*/ + bo =vc4_bo_create (dev, args->size, false); +if (!bo) +return -ENOMEM ; + + ret =drm_gem_handle_create (file_priv, &bo->base.base, &args->handle); +drm_gem_object_unreference_unlocked (&bo->base.base); + +return ret; +} + +int vc4_mmap_bo_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_vc4_mmap_bo *args = data; +struct drm_gem_object *gem_obj; + + gem_obj =drm_gem_object_lookup (dev, file_priv, args->handle); +if (!gem_obj) { +DRM_ERROR ("Failed to look up GEM BO %d\n" , args->handle); +return -EINVAL ; + } + +/* The mmap offset was set up at BO allocation time. */ + args->offset =drm_vma_node_offset_addr (&gem_obj->vma_node); + +drm_gem_object_unreference_unlocked (gem_obj); +return 0 ; +} +void vc4_bo_cache_init (struct drm_device *dev) {struct vc4_dev *vc4 =to_vc4_dev (dev);
drivers/gpu/drm/vc4/vc4_drv.c +3 -0
@@ -16,6 +16,7 @@#include <linux/platform_device.h> #include "drm_fb_cma_helper.h" +#include "uapi/drm/vc4_drm.h" #include "vc4_drv.h" #include "vc4_regs.h"
@@ -73,6 +74,8 @@ static const struct file_operations vc4_drm_fops = { };static const struct drm_ioctl_desc vc4_drm_ioctls[] = { +DRM_IOCTL_DEF_DRV (VC4_CREATE_BO , vc4_create_bo_ioctl,0 ), +DRM_IOCTL_DEF_DRV (VC4_MMAP_BO , vc4_mmap_bo_ioctl,0 ), };static struct drm_driver vc4_drm_driver = {
drivers/gpu/drm/vc4/vc4_drv.h +4 -0
@@ -155,6 +155,10 @@ int vc4_dumb_create(struct drm_file *file_priv, struct drm_mode_create_dumb *args);struct dma_buf *vc4_prime_export (struct drm_device *dev,struct drm_gem_object *obj,int flags); +int vc4_create_bo_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv); +int vc4_mmap_bo_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv);void vc4_bo_cache_init (struct drm_device *dev);void vc4_bo_cache_destroy (struct drm_device *dev);int vc4_bo_stats_debugfs (struct seq_file *m,void *arg);
include/uapi/drm/Kbuild +1 -0
@@ -17,4 +17,5 @@ header-y += tegra_drm.h header-y += via_drm.h header-y += vmwgfx_drm.h header-y += msm_drm.h +header-y += vc4_drm.h header-y += virtgpu_drm.h
include/uapi/drm/vc4_drm.h new file +68 -0
68 lines not on this page · raw message
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 4/9 drm/vc4: Add an API for creating GPU shaders in GEM BOs.
In reply to Eric AnholtSince we have no MMU, the kernel needs to validate that the submitted shader code won't make any accesses to memory that the user doesn't control, which involves banning some operations (general purpose DMA writes), and tracking where we need to write out pointers for other operations (texture sampling). Once it's validated, we return a GEM BO containing the shader, which doesn't allow mapping for write or exporting to other subsystems.
---
v2: Use __u32-style types.
drivers/gpu/drm/vc4/Makefile | 3 +- drivers/gpu/drm/vc4/vc4_bo.c | 140 ++++++++ drivers/gpu/drm/vc4/vc4_drv.c | 9 +- drivers/gpu/drm/vc4/vc4_drv.h | 50 +++ drivers/gpu/drm/vc4/vc4_qpu_defines.h | 264 +++++++++++++++ drivers/gpu/drm/vc4/vc4_validate_shaders.c | 513 +++++++++++++++++++++++++++++ include/uapi/drm/vc4_drm.h | 25 ++ 7 files changed, 999 insertions(+), 5 deletions(-) create mode 100644 drivers/gpu/drm/vc4/vc4_qpu_defines.h create mode 100644 drivers/gpu/drm/vc4/vc4_validate_shaders.c
drivers/gpu/drm/vc4/Makefile +2 -1
@@ -10,7 +10,8 @@ vc4-y := \ vc4_kms.o \ vc4_hdmi.o \ vc4_hvs.o \ - vc4_plane.o + vc4_plane.o \ + vc4_validate_shaders.o vc4-$(CONFIG_DEBUG_FS) += vc4_debugfs.o
drivers/gpu/drm/vc4/vc4_bo.c +140 -0
164 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_drv.c +5 -4
@@ -64,7 +64,7 @@ static const struct file_operations vc4_drm_fops = { .open = drm_open, .release = drm_release, .unlocked_ioctl = drm_ioctl, - .mmap = drm_gem_cma_mmap, + .mmap = vc4_mmap, .poll = drm_poll, .read = drm_read,#ifdef CONFIG_COMPAT
@@ -76,6 +76,7 @@ static const struct file_operations vc4_drm_fops = {static const struct drm_ioctl_desc vc4_drm_ioctls[] = {DRM_IOCTL_DEF_DRV (VC4_CREATE_BO , vc4_create_bo_ioctl,0 ),DRM_IOCTL_DEF_DRV (VC4_MMAP_BO , vc4_mmap_bo_ioctl,0 ), +DRM_IOCTL_DEF_DRV (VC4_CREATE_SHADER_BO , vc4_create_shader_bo_ioctl,0 ), };static struct drm_driver vc4_drm_driver = {
@@ -102,12 +103,12 @@ static struct drm_driver vc4_drm_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = drm_gem_prime_import, - .gem_prime_export = drm_gem_prime_export, + .gem_prime_export = vc4_prime_export, .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, - .gem_prime_vmap = drm_gem_cma_prime_vmap, + .gem_prime_vmap = vc4_prime_vmap, .gem_prime_vunmap = drm_gem_cma_prime_vunmap, - .gem_prime_mmap = drm_gem_cma_prime_mmap, + .gem_prime_mmap = vc4_prime_mmap, .dumb_create = vc4_dumb_create, .dumb_map_offset = drm_gem_cma_dumb_map_offset,
drivers/gpu/drm/vc4/vc4_drv.h +50 -0
73 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_qpu_defines.h new file +264 -0
264 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_validate_shaders.c new file +513 -0
513 lines not on this page · raw message
include/uapi/drm/vc4_drm.h +25 -0
@@ -28,9 +28,11 @@#define DRM_VC4_CREATE_BO 0x03#define DRM_VC4_MMAP_BO 0x04 +#define DRM_VC4_CREATE_SHADER_BO 0x05#define DRM_IOCTL_VC4_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_BO, struct drm_vc4_create_bo)#define DRM_IOCTL_VC4_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo) +#define DRM_IOCTL_VC4_CREATE_SHADER_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo)/** * struct drm_vc4_create_bo - ioctl argument for creating VC4 BOs.
@@ -65,4 +67,27 @@ struct drm_vc4_mmap_bo { __u64 offset; }; +/** +* struct drm_vc4_create_shader_bo - ioctl argument for creating VC4 +* shader BOs. +* +* Since allowing a shader to be overwritten while it's also being +* executed from would allow privlege escalation, shaders must be +* created using this ioctl, and they can't be mmapped later. +*/ +struct drm_vc4_create_shader_bo { +/* Size of the data argument. */ +__u32 size; +/* Flags, currently must be 0. */ +__u32 flags; + +/* Pointer to the data. */ +__u64 data; + +/** Returned GEM handle for the BO. */ +__u32 handle; +/* Pad, must be 0. */ +__u32 pad; +}; +#endif /* _UAPI_VC4_DRM_H_ */
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 5/9 drm/vc4: Fix a typo in a V3D debug register.
In reply to Eric Anholt--- drivers/gpu/drm/vc4/vc4_regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_regs.h +1 -1
@@ -154,7 +154,7 @@#define V3D_PCTRS14 0x006f4#define V3D_PCTR15 0x006f8#define V3D_PCTRS15 0x006fc -#define V3D_BGE 0x00f00 +#define V3D_DBGE 0x00f00#define V3D_FDBGO 0x00f04#define V3D_FDBGB 0x00f08#define V3D_FDBGR 0x00f0c
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 6/9 drm/vc4: Bind and initialize the V3D engine.
In reply to Eric AnholtThis is the component of the GPU that does 3D rendering.
--- drivers/gpu/drm/vc4/Makefile | 1 + drivers/gpu/drm/vc4/vc4_debugfs.c | 2 + drivers/gpu/drm/vc4/vc4_drv.c | 1 + drivers/gpu/drm/vc4/vc4_drv.h | 13 +++ drivers/gpu/drm/vc4/vc4_v3d.c | 225 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 242 insertions(+) create mode 100644 drivers/gpu/drm/vc4/vc4_v3d.c
drivers/gpu/drm/vc4/Makefile +1 -0
@@ -11,6 +11,7 @@ vc4-y := \ vc4_hdmi.o \ vc4_hvs.o \ vc4_plane.o \ + vc4_v3d.o \ vc4_validate_shaders.o vc4-$(CONFIG_DEBUG_FS) += vc4_debugfs.o
drivers/gpu/drm/vc4/vc4_debugfs.c +2 -0
@@ -22,6 +22,8 @@ static const struct drm_info_list vc4_debugfs_list[] = { {"crtc0_regs", vc4_crtc_debugfs_regs, 0, (void *)(uintptr_t)0}, {"crtc1_regs", vc4_crtc_debugfs_regs, 0, (void *)(uintptr_t)1}, {"crtc2_regs", vc4_crtc_debugfs_regs, 0, (void *)(uintptr_t)2}, + {"v3d_ident", vc4_v3d_debugfs_ident, 0}, + {"v3d_regs", vc4_v3d_debugfs_regs, 0}, };#define VC4_DEBUGFS_ENTRIES ARRAY_SIZE(vc4_debugfs_list)
drivers/gpu/drm/vc4/vc4_drv.c +1 -0
@@ -236,6 +236,7 @@ static struct platform_driver *const component_drivers[] = { &vc4_hdmi_driver, &vc4_crtc_driver, &vc4_hvs_driver, + &vc4_v3d_driver, };static int vc4_platform_drm_probe (struct platform_device *pdev)
drivers/gpu/drm/vc4/vc4_drv.h +13 -0
@@ -15,6 +15,7 @@ struct vc4_dev {struct vc4_hdmi *hdmi;struct vc4_hvs *hvs;struct vc4_crtc *crtc[3 ]; +struct vc4_v3d *v3d;struct drm_fbdev_cma *fbdev;
@@ -82,6 +83,11 @@ to_vc4_bo(struct drm_gem_object *bo)return (struct vc4_bo *)bo; } +struct vc4_v3d { +struct platform_device *pdev; +void __iomem *regs; +}; +struct vc4_hvs {struct platform_device *pdev;void __iomem *regs;
@@ -119,6 +125,8 @@ to_vc4_encoder(struct drm_encoder *encoder) return container_of(encoder, struct vc4_encoder, base); } +#define V3D_READ (offset) readl(vc4->v3d->regs + offset) +#define V3D_WRITE (offset, val) writel(val, vc4->v3d->regs + offset)#define HVS_READ (offset) readl(vc4->hvs->regs + offset)#define HVS_WRITE (offset, val) writel(val, vc4->hvs->regs + offset)
@@ -241,6 +249,11 @@ struct drm_plane *vc4_plane_init(struct drm_device *dev,u32 vc4_plane_write_dlist (struct drm_plane *plane,u32 __iomem *dlist);u32 vc4_plane_dlist_size (struct drm_plane_state *state); +/* vc4_v3d.c */ +extern struct platform_driver vc4_v3d_driver; +int vc4_v3d_debugfs_ident (struct seq_file *m,void *unused); +int vc4_v3d_debugfs_regs (struct seq_file *m,void *unused); +/* vc4_validate_shader.c */ struct vc4_validated_shader_info *vc4_validate_shader (struct drm_gem_cma_object *shader_obj);
drivers/gpu/drm/vc4/vc4_v3d.c new file +225 -0
225 lines not on this page · raw message
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 7/9 drm/vc4: Add support for drawing 3D frames.
In reply to Eric AnholtThe user submission is basically a pointer to a command list and a pointer to uniforms. We copy those in to the kernel, validate and relocate them, and store the result in a GPU BO which we queue for execution.
---
v2: Drop support for NV shader recs (not necessary for GL), simplify
vc4_use_bo(), improve bin flush/semaphore checks, use __u32 style types.
drivers/gpu/drm/vc4/Makefile | 7 + drivers/gpu/drm/vc4/vc4_drv.c | 15 +- drivers/gpu/drm/vc4/vc4_drv.h | 182 +++++++ drivers/gpu/drm/vc4/vc4_gem.c | 642 +++++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_irq.c | 210 ++++++++ drivers/gpu/drm/vc4/vc4_packet.h | 399 +++++++++++++++ drivers/gpu/drm/vc4/vc4_render_cl.c | 634 +++++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_trace.h | 63 +++ drivers/gpu/drm/vc4/vc4_trace_points.c | 14 + drivers/gpu/drm/vc4/vc4_v3d.c | 37 ++ drivers/gpu/drm/vc4/vc4_validate.c | 900 +++++++++++++++++++++++++++++++++ include/uapi/drm/vc4_drm.h | 141 ++++++ 12 files changed, 3243 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/vc4/vc4_gem.c create mode 100644 drivers/gpu/drm/vc4/vc4_irq.c create mode 100644 drivers/gpu/drm/vc4/vc4_packet.h create mode 100644 drivers/gpu/drm/vc4/vc4_render_cl.c create mode 100644 drivers/gpu/drm/vc4/vc4_trace.h create mode 100644 drivers/gpu/drm/vc4/vc4_trace_points.c create mode 100644 drivers/gpu/drm/vc4/vc4_validate.c
drivers/gpu/drm/vc4/Makefile +7 -0
@@ -8,12 +8,19 @@ vc4-y := \ vc4_crtc.o \ vc4_drv.o \ vc4_kms.o \ + vc4_gem.o \ vc4_hdmi.o \ vc4_hvs.o \ + vc4_irq.o \ vc4_plane.o \ + vc4_render_cl.o \ + vc4_trace_points.o \ vc4_v3d.o \ + vc4_validate.o \ vc4_validate_shaders.o vc4-$(CONFIG_DEBUG_FS) += vc4_debugfs.o obj-$(CONFIG_DRM_VC4) += vc4.o + +CFLAGS_vc4_trace_points.o := -I$(src)
drivers/gpu/drm/vc4/vc4_drv.c +14 -1
@@ -74,6 +74,9 @@ static const struct file_operations vc4_drm_fops = { };static const struct drm_ioctl_desc vc4_drm_ioctls[] = { +DRM_IOCTL_DEF_DRV (VC4_SUBMIT_CL , vc4_submit_cl_ioctl,0 ), +DRM_IOCTL_DEF_DRV (VC4_WAIT_SEQNO , vc4_wait_seqno_ioctl,0 ), +DRM_IOCTL_DEF_DRV (VC4_WAIT_BO , vc4_wait_bo_ioctl,0 ),DRM_IOCTL_DEF_DRV (VC4_CREATE_BO , vc4_create_bo_ioctl,0 ),DRM_IOCTL_DEF_DRV (VC4_MMAP_BO , vc4_mmap_bo_ioctl,0 ),DRM_IOCTL_DEF_DRV (VC4_CREATE_SHADER_BO , vc4_create_shader_bo_ioctl,0 ),
@@ -83,10 +86,16 @@ static struct drm_driver vc4_drm_driver = { .driver_features = (DRIVER_MODESET |DRIVER_ATOMIC |DRIVER_GEM | +DRIVER_HAVE_IRQ | DRIVER_PRIME), .lastclose = vc4_lastclose, .preclose = vc4_drm_preclose, + .irq_handler = vc4_irq, + .irq_preinstall = vc4_irq_preinstall, + .irq_postinstall = vc4_irq_postinstall, + .irq_uninstall = vc4_irq_uninstall, + .enable_vblank = vc4_enable_vblank, .disable_vblank = vc4_disable_vblank, .get_vblank_counter = drm_vblank_count,
@@ -181,9 +190,11 @@ static int vc4_drm_bind(struct device *dev)if (ret) goto unref; +vc4_gem_init (drm); + ret =component_bind_all (dev, drm);if (ret) - goto unref; + goto gem_destroy; ret =drm_dev_register (drm,0 );if (ret <0 )
@@ -207,6 +218,8 @@ unregister:drm_dev_unregister (drm); unbind_all:component_unbind_all (dev, drm); +gem_destroy: +vc4_gem_destroy (drm); unref:drm_dev_unref (drm);vc4_bo_cache_destroy (drm);
drivers/gpu/drm/vc4/vc4_drv.h +182 -0
216 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_gem.c new file +642 -0
642 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_irq.c new file +210 -0
210 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_packet.h new file +399 -0
399 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_render_cl.c new file +634 -0
634 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_trace.h new file +63 -0
63 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_trace_points.c new file +14 -0
@@ -0,0 +1,14 @@ +/* +* Copyright (C) 2015 Broadcom +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "vc4_drv.h" + +#ifndef __CHECKER__ +#define CREATE_TRACE_POINTS +#include "vc4_trace.h" +#endif
drivers/gpu/drm/vc4/vc4_v3d.c +37 -0
@@ -144,6 +144,21 @@ int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused) }#endif /* CONFIG_DEBUG_FS */ +/* +* Asks the firmware to turn on power to the V3D engine. +* +* This may be doable with just the clocks interface, though this +* packet does some other register setup from the firmware, too. +*/ +int +vc4_v3d_set_power (struct vc4_dev *vc4,bool on) +{ +if (on) +return pm_generic_poweroff (&vc4->v3d->pdev->dev); +else +return pm_generic_resume (&vc4->v3d->pdev->dev); +} +static void vc4_v3d_init_hw (struct drm_device *dev) {struct vc4_dev *vc4 =to_vc4_dev (dev);
@@ -161,6 +176,7 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)struct drm_device *drm =dev_get_drvdata (master);struct vc4_dev *vc4 =to_vc4_dev (drm);struct vc4_v3d *v3d =NULL ; +int ret; v3d =devm_kzalloc (&pdev->dev,sizeof (*v3d),GFP_KERNEL );if (!v3d)
@@ -180,8 +196,20 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)return -EINVAL ; } +/* Reset the binner overflow address/size at setup, to be sure +* we don't reuse an old one. +*/ +V3D_WRITE (V3D_BPOA ,0 ); +V3D_WRITE (V3D_BPOS ,0 ); +vc4_v3d_init_hw (drm); + ret =drm_irq_install (drm,platform_get_irq (pdev,0 )); +if (ret) { +DRM_ERROR ("Failed to install IRQ handler\n" ); +return ret; + } +return 0 ; }
@@ -191,6 +219,15 @@ static void vc4_v3d_unbind(struct device *dev, struct device *master,struct drm_device *drm =dev_get_drvdata (master);struct vc4_dev *vc4 =to_vc4_dev (drm); +drm_irq_uninstall (drm); + +/* Disable the binner's overflow memory address, so the next +* driver probe (if any) doesn't try to reuse our old +* allocation. +*/ +V3D_WRITE (V3D_BPOA ,0 ); +V3D_WRITE (V3D_BPOS ,0 ); + vc4->v3d =NULL ; }
drivers/gpu/drm/vc4/vc4_validate.c new file +900 -0
695 lines not on this page · raw message
include/uapi/drm/vc4_drm.h +141 -0
141 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Part of the diff is not shown here. View the raw message.
PATCH v2 8/9 drm/vc4: Add support for async pageflips.
In reply to Eric AnholtAn async pageflip stores the modeset to be done and executes it once the BOs are ready to be displayed. This gets us about 3x performance in full screen rendering with pageflipping.
--- drivers/gpu/drm/vc4/vc4_crtc.c | 99 +++++++++++++++++++++++++- drivers/gpu/drm/vc4/vc4_drv.h | 16 +++++ drivers/gpu/drm/vc4/vc4_gem.c | 40 +++++++++++ drivers/gpu/drm/vc4/vc4_kms.c | 149 +++++++++++++++++++++++++++++++++++++++- drivers/gpu/drm/vc4/vc4_plane.c | 40 +++++++++++ 5 files changed, 342 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_crtc.c +98 -1
@@ -35,6 +35,7 @@#include "drm_atomic_helper.h" #include "drm_crtc_helper.h" #include "linux/clk.h" +#include "drm_fb_cma_helper.h" #include "linux/component.h" #include "linux/of_device.h" #include "vc4_drv.h"
@@ -475,10 +476,106 @@ static irqreturn_t vc4_crtc_irq_handler(int irq, void *data)return ret; } +struct vc4_async_flip_state { +struct drm_crtc *crtc; +struct drm_framebuffer *fb; +struct drm_pending_vblank_event *event; + +struct vc4_seqno_cb cb; +}; + +/* Called when the V3D execution for the BO being flipped to is done, so that +* we can actually update the plane's address to point to it. +*/ +static void +vc4_async_page_flip_complete (struct vc4_seqno_cb *cb) +{ +struct vc4_async_flip_state *flip_state = + container_of(cb, struct vc4_async_flip_state, cb); +struct drm_crtc *crtc = flip_state->crtc; +struct drm_device *dev = crtc->dev; +struct vc4_dev *vc4 =to_vc4_dev (dev); +struct drm_plane *plane = crtc->primary; + +vc4_plane_async_set_fb (plane, flip_state->fb); +if (flip_state->event) { +unsigned long flags; + +spin_lock_irqsave (&dev->event_lock, flags); +drm_crtc_send_vblank_event (crtc, flip_state->event); +spin_unlock_irqrestore (&dev->event_lock, flags); + } + +drm_framebuffer_unreference (flip_state->fb); +kfree (flip_state); + +up (&vc4->async_modeset); +} + +/* Implements async (non-vblank-synced) page flips. +* +* The page flip ioctl needs to return immediately, so we grab the +* modeset semaphore on the pipe, and queue the address update for +* when V3D is done with the BO being flipped to. +*/ +static int vc4_async_page_flip (struct drm_crtc *crtc, +struct drm_framebuffer *fb, +struct drm_pending_vblank_event *event, +uint32_t flags) +{ +struct drm_device *dev = crtc->dev; +struct vc4_dev *vc4 =to_vc4_dev (dev); +struct drm_plane *plane = crtc->primary; +int ret =0 ; +struct vc4_async_flip_state *flip_state; +struct drm_gem_cma_object *cma_bo =drm_fb_cma_get_gem_obj (fb,0 ); +struct vc4_bo *bo =to_vc4_bo (&cma_bo->base); + + flip_state =kzalloc (sizeof (*flip_state),GFP_KERNEL ); +if (!flip_state) +return -ENOMEM ; + +drm_framebuffer_reference (fb); + flip_state->fb = fb; + flip_state->crtc = crtc; + flip_state->event = event; + +/* Make sure all other async modesetes have landed. */ + ret =down_interruptible (&vc4->async_modeset); +if (ret) { +kfree (flip_state); +return ret; + } + +/* Immediately update the plane's legacy fb pointer, so that later +* modeset prep sees the state that will be present when the semaphore +* is released. +*/ +drm_atomic_set_fb_for_plane (plane->state, fb); + plane->fb = fb; + +vc4_queue_seqno_cb (dev, &flip_state->cb, bo->seqno, + vc4_async_page_flip_complete); + +/* Driver takes ownership of state on successful async commit. */ +return 0 ; +} + +static int vc4_page_flip (struct drm_crtc *crtc, +struct drm_framebuffer *fb, +struct drm_pending_vblank_event *event, +uint32_t flags) +{ +if (flags &DRM_MODE_PAGE_FLIP_ASYNC ) +return vc4_async_page_flip (crtc, fb, event, flags); +else +return drm_atomic_helper_page_flip (crtc, fb, event, flags); +} +static const struct drm_crtc_funcs vc4_crtc_funcs = { .set_config = drm_atomic_helper_set_config, .destroy = vc4_crtc_destroy, - .page_flip = drm_atomic_helper_page_flip, + .page_flip = vc4_page_flip, .set_property =NULL , .cursor_set =NULL ,/* handled by drm_mode_cursor_universal */ .cursor_move =NULL ,/* handled by drm_mode_cursor_universal */
drivers/gpu/drm/vc4/vc4_drv.h +16 -0
@@ -76,6 +76,11 @@ struct vc4_dev {wait_queue_head_t job_wait_queue;struct work_struct job_done_work; +/* List of struct vc4_seqno_cb for callbacks to be made from a +* workqueue when the given seqno is passed. +*/ +struct list_head seqno_cb_list; +/* The binner overflow memory that's currently set up in * BPOA/BPOS registers. When overflow occurs and a new one is * allocated, the previous one will be moved to
@@ -128,6 +133,12 @@ to_vc4_bo(struct drm_gem_object *bo)return (struct vc4_bo *)bo; } +struct vc4_seqno_cb { +struct work_struct work; +uint64_t seqno; +void (*func)(struct vc4_seqno_cb *cb); +}; +struct vc4_v3d {struct platform_device *pdev;void __iomem *regs;
@@ -384,6 +395,9 @@ void vc4_submit_next_job(struct drm_device *dev);int vc4_wait_for_seqno (struct drm_device *dev,uint64_t seqno,uint64_t timeout_ns,bool interruptible);void vc4_job_handle_completed (struct vc4_dev *vc4); +int vc4_queue_seqno_cb (struct drm_device *dev, +struct vc4_seqno_cb *cb,uint64_t seqno, +void (*func)(struct vc4_seqno_cb *cb));/* vc4_hdmi.c */ extern struct platform_driver vc4_hdmi_driver;
@@ -409,6 +423,8 @@ struct drm_plane *vc4_plane_init(struct drm_device *dev, enum drm_plane_type type);u32 vc4_plane_write_dlist (struct drm_plane *plane,u32 __iomem *dlist);u32 vc4_plane_dlist_size (struct drm_plane_state *state); +void vc4_plane_async_set_fb (struct drm_plane *plane, +struct drm_framebuffer *fb);/* vc4_v3d.c */ extern struct platform_driver vc4_v3d_driver;
drivers/gpu/drm/vc4/vc4_gem.c +40 -0
@@ -461,6 +461,7 @@ void vc4_job_handle_completed(struct vc4_dev *vc4) {unsigned long irqflags; +struct vc4_seqno_cb *cb, *cb_temp;spin_lock_irqsave (&vc4->job_lock, irqflags);while (!list_empty (&vc4->job_done_list)) {
@@ -473,7 +474,45 @@ vc4_job_handle_completed(struct vc4_dev *vc4)vc4_complete_exec (vc4->dev, exec);spin_lock_irqsave (&vc4->job_lock, irqflags); } + +list_for_each_entry_safe (cb, cb_temp, &vc4->seqno_cb_list, work.entry) { +if (cb->seqno <= vc4->finished_seqno) { +list_del_init (&cb->work.entry); +schedule_work (&cb->work); + } + } + +spin_unlock_irqrestore (&vc4->job_lock, irqflags); +} + +static void vc4_seqno_cb_work (struct work_struct *work) +{ + struct vc4_seqno_cb *cb = container_of(work, struct vc4_seqno_cb, work); + + cb->func (cb); +} + +int vc4_queue_seqno_cb (struct drm_device *dev, +struct vc4_seqno_cb *cb,uint64_t seqno, +void (*func)(struct vc4_seqno_cb *cb)) +{ +struct vc4_dev *vc4 =to_vc4_dev (dev); +int ret =0 ; +unsigned long irqflags; + + cb->func = func; +INIT_WORK (&cb->work, vc4_seqno_cb_work); + +spin_lock_irqsave (&vc4->job_lock, irqflags); +if (seqno > vc4->finished_seqno) { + cb->seqno = seqno; +list_add_tail (&cb->work.entry, &vc4->seqno_cb_list); + }else { +schedule_work (&cb->work); + }spin_unlock_irqrestore (&vc4->job_lock, irqflags); + +return ret; }/* Scheduled when any job has been completed, this walks the list of
@@ -610,6 +649,7 @@ vc4_gem_init(struct drm_device *dev)INIT_LIST_HEAD (&vc4->job_list);INIT_LIST_HEAD (&vc4->job_done_list); +INIT_LIST_HEAD (&vc4->seqno_cb_list);spin_lock_init (&vc4->job_lock);INIT_WORK (&vc4->hangcheck.reset_work, vc4_reset_work);
drivers/gpu/drm/vc4/vc4_kms.c +148 -1
176 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_plane.c +40 -0
@@ -29,6 +29,14 @@ struct vc4_plane_state {u32 *dlist;u32 dlist_size;/* Number of dwords in allocated for the display list */ u32 dlist_count;/* Number of used dwords in the display list. */ + +/* Offset in the dlist to pointer word 0. */ +u32 pw0_offset; + +/* Offset where the plane's dlist was last stored in the +hardware at vc4_crtc_atomic_flush() time. +*/ +u32 *hw_dlist; }; static inline struct vc4_plane_state *
@@ -197,6 +205,8 @@ static int vc4_plane_mode_set(struct drm_plane *plane,/* Position Word 3: Context. Written by the HVS. */ vc4_dlist_write (vc4_state,0xc0c0c0c0 ); + vc4_state->pw0_offset = vc4_state->dlist_count; +/* Pointer Word 0: RGB / Y Pointer */ vc4_dlist_write (vc4_state, bo->paddr + offset);
@@ -248,6 +258,8 @@ u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist)struct vc4_plane_state *vc4_state =to_vc4_plane_state (plane->state);int i; + vc4_state->hw_dlist = dlist; +/* Can't memcpy_toio() because it needs to be 32-bit writes. */ for (i =0 ; i < vc4_state->dlist_count; i++)writel (vc4_state->dlist[i], &dlist[i]);
@@ -262,6 +274,34 @@ u32 vc4_plane_dlist_size(struct drm_plane_state *state)return vc4_state->dlist_count; } +/* Updates the plane to immediately (well, once the FIFO needs +* refilling) scan out from at a new framebuffer. +*/ +void vc4_plane_async_set_fb (struct drm_plane *plane,struct drm_framebuffer *fb) +{ +struct vc4_plane_state *vc4_state =to_vc4_plane_state (plane->state); +struct drm_gem_cma_object *bo =drm_fb_cma_get_gem_obj (fb,0 ); +uint32_t addr; + +/* We're skipping the address adjustment for negative origin, +* because this is only called on the primary plane. +*/ +WARN_ON_ONCE (plane->state->crtc_x <0 || plane->state->crtc_y <0 ); + addr = bo->paddr + fb->offsets[0 ]; + +/* Write the new address into the hardware immediately. The +* scanout will start from this address as soon as the FIFO +* needs to refill with pixels. +*/ +writel (addr, &vc4_state->hw_dlist[vc4_state->pw0_offset]); + +/* Also update the CPU-side dlist copy, so that any later +* atomic updates that don't do a new modeset on our plane +* also use our updated address. +*/ + vc4_state->dlist[vc4_state->pw0_offset] = addr; +} +static const struct drm_plane_helper_funcs vc4_plane_helper_funcs = { .prepare_fb =NULL , .cleanup_fb =NULL ,
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 9/9 drm/vc4: Add an interface for capturing the GPU state after a hang.
In reply to Eric AnholtThis can be parsed with vc4-gpu-tools tools for trying to figure out what was going on.
---
v2: Use __u32-style types.
drivers/gpu/drm/vc4/vc4_drv.c | 2 + drivers/gpu/drm/vc4/vc4_drv.h | 4 + drivers/gpu/drm/vc4/vc4_gem.c | 185 ++++++++++++++++++++++++++++++++++++++++++ include/uapi/drm/vc4_drm.h | 45 ++++++++++ 4 files changed, 236 insertions(+)
drivers/gpu/drm/vc4/vc4_drv.c +2 -0
@@ -80,6 +80,8 @@ static const struct drm_ioctl_desc vc4_drm_ioctls[] = {DRM_IOCTL_DEF_DRV (VC4_CREATE_BO , vc4_create_bo_ioctl,0 ),DRM_IOCTL_DEF_DRV (VC4_MMAP_BO , vc4_mmap_bo_ioctl,0 ),DRM_IOCTL_DEF_DRV (VC4_CREATE_SHADER_BO , vc4_create_shader_bo_ioctl,0 ), +DRM_IOCTL_DEF_DRV (VC4_GET_HANG_STATE , vc4_get_hang_state_ioctl, + DRM_ROOT_ONLY), }; static struct drm_driver vc4_drm_driver = {
drivers/gpu/drm/vc4/vc4_drv.h +4 -0
@@ -19,6 +19,8 @@ struct vc4_dev {struct drm_fbdev_cma *fbdev; +struct vc4_hang_state *hang_state; +/* The kernel-space BO cache. Tracks buffers that have been * unreferenced by all other users (refcounts of 0!) but not * yet freed, so we can do cheap allocations.
@@ -361,6 +363,8 @@ int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);int vc4_mmap_bo_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); +int vc4_get_hang_state_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv);int vc4_mmap (struct file *filp,struct vm_area_struct *vma);int vc4_prime_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);void *vc4_prime_vmap (struct drm_gem_object *obj);
drivers/gpu/drm/vc4/vc4_gem.c +185 -0
201 lines not on this page · raw message
include/uapi/drm/vc4_drm.h +45 -0
61 lines not on this page · raw message
Signature · 6 lines
2.6.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel