Host1x/TegraDRM UAPI
Mikko Perttunen
maintainerv3 cover Host1x/TegraDRM UAPI
Hi all,
here's the third revision of the Host1x/TegraDRM UAPI proposal. The open issues from RFCv2 should be resolved now, so I'm dropping the RFC tag. The series is still only tested with Tegra186 so I'm hoping for people with devices with other chips to test this out.
The test suite[1] has been updated for the changes in this revision, and also includes tests for the newly added DMA reservation support. If there are no further issues with the UAPI definition, I'll look at porting other userspace next - hoping for some help with that as well since most of it is for chips I don't have easy access to.
The series can be also found in
https://github.com/cyndis/linux/commits/work/host1x-uapi-v3.
Older versions:
v1: https://www.spinics.net/lists/linux-tegra/msg51000.html
v2: https://www.spinics.net/lists/linux-tegra/msg53061.html
Thank you,
Mikko
[1] https://github.com/cyndis/uapi-test
Mikko Perttunen (20):
gpu: host1x: Use different lock classes for each client
gpu: host1x: Allow syncpoints without associated client
gpu: host1x: Show number of pending waiters in debugfs
gpu: host1x: Remove cancelled waiters immediately
gpu: host1x: Use HW-equivalent syncpoint expiration check
gpu: host1x: Cleanup and refcounting for syncpoints
gpu: host1x: Introduce UAPI header
gpu: host1x: Implement /dev/host1x device node
gpu: host1x: DMA fences and userspace fence creation
gpu: host1x: Add no-recovery mode
gpu: host1x: Add job release callback
gpu: host1x: Add support for syncpoint waits in CDMA pushbuffer
gpu: host1x: Reset max value when freeing a syncpoint
gpu: host1x: Reserve VBLANK syncpoints at initialization drm/tegra: Add new UAPI to header
drm/tegra: Boot VIC during runtime PM resume drm/tegra: Set resv fields when importing/exporting GEMs drm/tegra: Allocate per-engine channel in core code drm/tegra: Implement new UAPI
drm/tegra: Add job firewall
drivers/gpu/drm/tegra/Makefile | 4 + drivers/gpu/drm/tegra/dc.c | 10 +- drivers/gpu/drm/tegra/drm.c | 75 ++- drivers/gpu/drm/tegra/drm.h | 9 + drivers/gpu/drm/tegra/gem.c | 2 + drivers/gpu/drm/tegra/gr2d.c | 4 +- drivers/gpu/drm/tegra/gr3d.c | 4 +- drivers/gpu/drm/tegra/uapi.h | 63 +++ drivers/gpu/drm/tegra/uapi/firewall.c | 197 +++++++ drivers/gpu/drm/tegra/uapi/gather_bo.c | 86 ++++ drivers/gpu/drm/tegra/uapi/gather_bo.h | 22 + drivers/gpu/drm/tegra/uapi/submit.c | 679 +++++++++++++++++++++++++ drivers/gpu/drm/tegra/uapi/submit.h | 20 + drivers/gpu/drm/tegra/uapi/uapi.c | 326 ++++++++++++ drivers/gpu/drm/tegra/vic.c | 118 ++--- drivers/gpu/host1x/Makefile | 2 + drivers/gpu/host1x/bus.c | 7 +- drivers/gpu/host1x/cdma.c | 69 ++- drivers/gpu/host1x/debug.c | 14 +- drivers/gpu/host1x/dev.c | 15 + drivers/gpu/host1x/dev.h | 16 +- drivers/gpu/host1x/fence.c | 207 ++++++++ drivers/gpu/host1x/fence.h | 13 + drivers/gpu/host1x/hw/cdma_hw.c | 2 +- drivers/gpu/host1x/hw/channel_hw.c | 63 ++- drivers/gpu/host1x/hw/debug_hw.c | 11 +- drivers/gpu/host1x/intr.c | 23 +- drivers/gpu/host1x/intr.h | 2 + drivers/gpu/host1x/job.c | 79 ++- drivers/gpu/host1x/job.h | 14 + drivers/gpu/host1x/syncpt.c | 185 ++++--- drivers/gpu/host1x/syncpt.h | 16 +- drivers/gpu/host1x/uapi.c | 382 ++++++++++++++ drivers/gpu/host1x/uapi.h | 22 + include/linux/host1x.h | 47 +- include/uapi/drm/tegra_drm.h | 420 ++++++++++++++- include/uapi/linux/host1x.h | 134 +++++ 37 files changed, 3076 insertions(+), 286 deletions(-) create mode 100644 drivers/gpu/drm/tegra/uapi.h create mode 100644 drivers/gpu/drm/tegra/uapi/firewall.c create mode 100644 drivers/gpu/drm/tegra/uapi/gather_bo.c create mode 100644 drivers/gpu/drm/tegra/uapi/gather_bo.h create mode 100644 drivers/gpu/drm/tegra/uapi/submit.c create mode 100644 drivers/gpu/drm/tegra/uapi/submit.h create mode 100644 drivers/gpu/drm/tegra/uapi/uapi.c create mode 100644 drivers/gpu/host1x/fence.c create mode 100644 drivers/gpu/host1x/fence.h create mode 100644 drivers/gpu/host1x/uapi.c create mode 100644 drivers/gpu/host1x/uapi.h create mode 100644 include/uapi/linux/host1x.h
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 1/20 gpu: host1x: Use different lock classes for each client
To avoid false lockdep warnings, give each client lock a different lock class, passed from the initialization site by macro.
--- drivers/gpu/host1x/bus.c | 7 ++++--- include/linux/host1x.h | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-)
drivers/gpu/host1x/bus.c +4 -3
@@ -714,13 +714,14 @@ EXPORT_SYMBOL(host1x_driver_unregister);* device and call host1x_device_init(), which will in turn call each client's * &host1x_client_ops.init implementation. */ -int host1x_client_register (struct host1x_client *client) +int __host1x_client_register (struct host1x_client *client, +struct lock_class_key *key) {struct host1x *host1x;int err;INIT_LIST_HEAD (&client->list); -mutex_init (&client->lock); +__mutex_init (&client->lock,"host1x client lock" , key); client->usecount =0 ;mutex_lock (&devices_lock);
@@ -741,7 +742,7 @@ int host1x_client_register(struct host1x_client *client)return 0 ; } -EXPORT_SYMBOL (host1x_client_register); +EXPORT_SYMBOL (__host1x_client_register);/** * host1x_client_unregister() - unregister a host1x client
include/linux/host1x.h +8 -1
@@ -320,7 +320,14 @@ static inline struct host1x_device *to_host1x_device(struct device *dev)int host1x_device_init (struct host1x_device *device);int host1x_device_exit (struct host1x_device *device); -int host1x_client_register (struct host1x_client *client); +int __host1x_client_register (struct host1x_client *client, +struct lock_class_key *key); +#define host1x_client_register (class) \ + ({ \ + static struct lock_class_key __key; \ + __host1x_client_register(class, &__key); \ + }) +int host1x_client_unregister (struct host1x_client *client);int host1x_client_suspend (struct host1x_client *client);
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 2/20 gpu: host1x: Allow syncpoints without associated client
In reply to Mikko PerttunenSyncpoints don't need to be associated with any client, so remove the property, and expose host1x_syncpt_alloc. This will allow allocating syncpoints without prior knowledge of the engine that it will be used with.
---
v3:
* Clean up host1x_syncpt_alloc signature to allow specifying a name for the syncpoint.
* Export the function.
--- drivers/gpu/host1x/syncpt.c | 22 ++++++++++------------ drivers/gpu/host1x/syncpt.h | 1 - include/linux/host1x.h | 3 +++ 3 files changed, 13 insertions(+), 13 deletions(-)
drivers/gpu/host1x/syncpt.c +10 -12
@@ -42,13 +42,13 @@ static void host1x_syncpt_base_free(struct host1x_syncpt_base *base) base->requested = false; } -static struct host1x_syncpt *host1x_syncpt_alloc (struct host1x *host, -struct host1x_client *client, -unsigned long flags) +struct host1x_syncpt *host1x_syncpt_alloc (struct host1x *host, +unsigned long flags, +const char *name) {struct host1x_syncpt *sp = host->syncpt; +char *full_name;unsigned int i; -char *name;mutex_lock (&host->syncpt_mutex);
@@ -64,13 +64,11 @@ static struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host, goto unlock; } - name =kasprintf (GFP_KERNEL ,"%02u-%s" , sp->id, - client ?dev_name (client->dev) :NULL ); -if (!name) + full_name =kasprintf (GFP_KERNEL ,"%u-%s" , sp->id, name); +if (!full_name) goto free_base; - sp->client = client; - sp->name = name; + sp->name = full_name;if (flags &HOST1X_SYNCPT_CLIENT_MANAGED ) sp->client_managed = true;
@@ -87,6 +85,7 @@ static struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,mutex_unlock (&host->syncpt_mutex);return NULL ; } +EXPORT_SYMBOL (host1x_syncpt_alloc);/** * host1x_syncpt_id() - retrieve syncpoint ID
@@ -401,7 +400,7 @@ int host1x_syncpt_init(struct host1x *host)host1x_hw_syncpt_enable_protection (host);/* Allocate sync point to use for clearing waits for expired fences */ - host->nop_sp =host1x_syncpt_alloc (host,NULL ,0 ); + host->nop_sp =host1x_syncpt_alloc (host,0 ,"reserved-nop" );if (!host->nop_sp)return -ENOMEM ;
@@ -423,7 +422,7 @@ struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client, {struct host1x *host =dev_get_drvdata (client->host->parent); -return host1x_syncpt_alloc (host, client, flags); +return host1x_syncpt_alloc (host, flags,dev_name (client->dev)); }EXPORT_SYMBOL (host1x_syncpt_request);
@@ -447,7 +446,6 @@ void host1x_syncpt_free(struct host1x_syncpt *sp)host1x_syncpt_base_free (sp->base);kfree (sp->name); sp->base =NULL ; - sp->client =NULL ; sp->name =NULL ; sp->client_managed = false;
drivers/gpu/host1x/syncpt.h +0 -1
@@ -33,7 +33,6 @@ struct host1x_syncpt {const char *name;bool client_managed;struct host1x *host; -struct host1x_client *client;struct host1x_syncpt_base *base;/* interrupt data */
include/linux/host1x.h +3 -0
@@ -154,6 +154,9 @@ int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,struct host1x_syncpt *host1x_syncpt_request (struct host1x_client *client,unsigned long flags);void host1x_syncpt_free (struct host1x_syncpt *sp); +struct host1x_syncpt *host1x_syncpt_alloc (struct host1x *host, +unsigned long flags, +const char *name);struct host1x_syncpt_base *host1x_syncpt_get_base (struct host1x_syncpt *sp);u32 host1x_syncpt_base_id (struct host1x_syncpt_base *base);
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 3/20 gpu: host1x: Show number of pending waiters in debugfs
In reply to Mikko PerttunenShow the number of pending waiters in the debugfs status file. This is useful for testing to verify that waiters do not leak or accumulate incorrectly.
--- drivers/gpu/host1x/debug.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/gpu/host1x/debug.c +11 -3
@@ -69,6 +69,7 @@ static int show_channel(struct host1x_channel *ch, void *data, bool show_fifo)static void show_syncpts (struct host1x *m,struct output *o) { +struct list_head *pos;unsigned int i;host1x_debug_output (o,"---- syncpts ----\n" );
@@ -76,12 +77,19 @@ static void show_syncpts(struct host1x *m, struct output *o)for (i =0 ; i <host1x_syncpt_nb_pts (m); i++) {u32 max =host1x_syncpt_read_max (m->syncpt + i);u32 min =host1x_syncpt_load (m->syncpt + i); +unsigned int waiters =0 ; -if (!min && !max) +spin_lock (&m->syncpt[i].intr.lock); +list_for_each (pos, &m->syncpt[i].intr.wait_head) + waiters++; +spin_unlock (&m->syncpt[i].intr.lock); + +if (!min && !max && !waiters)continue ; -host1x_debug_output (o,"id %u (%s) min %d max %d\n" , - i, m->syncpt[i].name, min, max); +host1x_debug_output (o, +"id %u (%s) min %d max %d (%d waiters)\n" , + i, m->syncpt[i].name, min, max, waiters); }for (i =0 ; i <host1x_syncpt_nb_bases (m); i++) {
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 4/20 gpu: host1x: Remove cancelled waiters immediately
In reply to Mikko PerttunenBefore this patch, cancelled waiters would only be cleaned up once their threshold value was reached. Make host1x_intr_put_ref process the cancellation immediately to fix this.
--- drivers/gpu/host1x/intr.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/host1x/intr.c +9 -5
@@ -247,13 +247,17 @@ void host1x_intr_put_ref(struct host1x *host, unsigned int id, void *ref)struct host1x_waitlist *waiter = ref;struct host1x_syncpt *syncpt; -while (atomic_cmpxchg (&waiter->state,WLS_PENDING ,WLS_CANCELLED ) == -WLS_REMOVED ) -schedule (); +atomic_cmpxchg (&waiter->state,WLS_PENDING ,WLS_CANCELLED ); syncpt = host->syncpt + id; - (void )process_wait_list (host, syncpt, -host1x_syncpt_load (host->syncpt + id)); + +spin_lock (&syncpt->intr.lock); +if (atomic_cmpxchg (&waiter->state,WLS_CANCELLED ,WLS_HANDLED ) == +WLS_CANCELLED ) { +list_del (&waiter->list); +kref_put (&waiter->refcount, waiter_release); + } +spin_unlock (&syncpt->intr.lock);kref_put (&waiter->refcount, waiter_release); }
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 5/20 gpu: host1x: Use HW-equivalent syncpoint expiration check
In reply to Mikko PerttunenMake syncpoint expiration checks always use the same logic used by the hardware. This ensures that there are no race conditions that could occur because of the hardware triggering a syncpoint interrupt and then the driver disagreeing.
One situation where this could occur is if a job incremented a syncpoint too many times -- then the hardware would trigger an interrupt, but the driver would assume that a syncpoint value greater than the syncpoint's max value is in the future, and not clean up the job.
--- drivers/gpu/host1x/syncpt.c | 51 ++----------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-)
drivers/gpu/host1x/syncpt.c +2 -49
@@ -306,59 +306,12 @@ EXPORT_SYMBOL(host1x_syncpt_wait);bool host1x_syncpt_is_expired (struct host1x_syncpt *sp,u32 thresh) {u32 current_val; -u32 future_val;smp_rmb (); current_val = (u32 )atomic_read (&sp->min_val); - future_val = (u32 )atomic_read (&sp->max_val); - -/* Note the use of unsigned arithmetic here (mod 1<<32). -* -* c = current_val = min_val = the current value of the syncpoint. -* t = thresh = the value we are checking -* f = future_val = max_val = the value c will reach when all -* outstanding increments have completed. -* -* Note that c always chases f until it reaches f. -* -* Dtf = (f - t) -* Dtc = (c - t) -* -* Consider all cases: -* -* A) .....c..t..f..... Dtf < Dtc need to wait -* B) .....c.....f..t.. Dtf > Dtc expired -* C) ..t..c.....f..... Dtf > Dtc expired (Dct very large) -* -* Any case where f==c: always expired (for any t). Dtf == Dcf -* Any case where t==c: always expired (for any f). Dtf >= Dtc (because Dtc==0) -* Any case where t==f!=c: always wait. Dtf < Dtc (because Dtf==0, -* Dtc!=0) -* -* Other cases: -* -* A) .....t..f..c..... Dtf < Dtc need to wait -* A) .....f..c..t..... Dtf < Dtc need to wait -* A) .....f..t..c..... Dtf > Dtc expired -* -* So: -* Dtf >= Dtc implies EXPIRED (return true) -* Dtf < Dtc implies WAIT (return false) -* -* Note: If t is expired then we *cannot* wait on it. We would wait -* forever (hang the system). -* -* Note: do NOT get clever and remove the -thresh from both sides. It -* is NOT the same. -* -* If future valueis zero, we have a client managed sync point. In that -* case we do a direct comparison. -*/ -if (!host1x_syncpt_client_managed (sp)) -return future_val - thresh >= current_val - thresh; -else -return (s32)(current_val - thresh) >=0 ; + +return ((current_val - thresh) &0x80000000U ) ==0U ; }int host1x_syncpt_init (struct host1x *host)
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 6/20 gpu: host1x: Cleanup and refcounting for syncpoints
In reply to Mikko PerttunenAdd reference counting for allocated syncpoints to allow keeping them allocated while jobs are referencing them. Additionally, clean up various places using syncpoint IDs to use host1x_syncpt pointers instead.
--- drivers/gpu/drm/tegra/dc.c | 4 +- drivers/gpu/drm/tegra/drm.c | 17 ++++--- drivers/gpu/drm/tegra/gr2d.c | 4 +- drivers/gpu/drm/tegra/gr3d.c | 4 +- drivers/gpu/drm/tegra/vic.c | 4 +- drivers/gpu/host1x/cdma.c | 11 ++--- drivers/gpu/host1x/dev.h | 7 ++- drivers/gpu/host1x/hw/cdma_hw.c | 2 +- drivers/gpu/host1x/hw/channel_hw.c | 10 ++-- drivers/gpu/host1x/hw/debug_hw.c | 2 +- drivers/gpu/host1x/job.c | 5 +- drivers/gpu/host1x/syncpt.c | 75 +++++++++++++++++++++++------- drivers/gpu/host1x/syncpt.h | 3 ++ include/linux/host1x.h | 8 ++-- 14 files changed, 99 insertions(+), 57 deletions(-)
drivers/gpu/drm/tegra/dc.c +2 -2
@@ -2127,7 +2127,7 @@ static int tegra_dc_init(struct host1x_client *client)drm_plane_cleanup (primary);host1x_client_iommu_detach (client); -host1x_syncpt_free (dc->syncpt); +host1x_syncpt_put (dc->syncpt);return err; }
@@ -2152,7 +2152,7 @@ static int tegra_dc_exit(struct host1x_client *client) }host1x_client_iommu_detach (client); -host1x_syncpt_free (dc->syncpt); +host1x_syncpt_put (dc->syncpt);return 0 ; }
drivers/gpu/drm/tegra/drm.c +10 -7
@@ -171,7 +171,7 @@ int tegra_drm_submit(struct tegra_drm_context *context,struct drm_tegra_syncpt syncpt;struct host1x *host1x =dev_get_drvdata (drm->dev->parent);struct drm_gem_object **refs; -struct host1x_syncpt *sp; +struct host1x_syncpt *sp =NULL ;struct host1x_job *job;unsigned int num_refs;int err;
@@ -298,8 +298,8 @@ int tegra_drm_submit(struct tegra_drm_context *context, goto fail; } -/* check whether syncpoint ID is valid */ - sp =host1x_syncpt_get (host1x, syncpt.id); +/* Syncpoint ref will be dropped on job release. */ + sp =host1x_syncpt_get_by_id (host1x, syncpt.id);if (!sp) { err = -ENOENT ; goto fail;
@@ -308,7 +308,7 @@ int tegra_drm_submit(struct tegra_drm_context *context, job->is_addr_reg = context->client->ops->is_addr_reg; job->is_valid_class = context->client->ops->is_valid_class; job->syncpt_incrs = syncpt.incrs; - job->syncpt_id = syncpt.id; + job->syncpt = sp; job->timeout =10000 ;if (args->timeout && args->timeout <10000 )
@@ -327,6 +327,9 @@ int tegra_drm_submit(struct tegra_drm_context *context, args->fence = job->syncpt_end; fail: +if (sp) +host1x_syncpt_put (sp); +while (num_refs--)drm_gem_object_put (refs[num_refs]);
@@ -380,7 +383,7 @@ static int tegra_syncpt_read(struct drm_device *drm, void *data,struct drm_tegra_syncpt_read *args = data;struct host1x_syncpt *sp; - sp =host1x_syncpt_get (host, args->id); + sp =host1x_syncpt_get_by_id_noref (host, args->id);if (!sp)return -EINVAL ;
@@ -395,7 +398,7 @@ static int tegra_syncpt_incr(struct drm_device *drm, void *data,struct drm_tegra_syncpt_incr *args = data;struct host1x_syncpt *sp; - sp =host1x_syncpt_get (host1x, args->id); + sp =host1x_syncpt_get_by_id_noref (host1x, args->id);if (!sp)return -EINVAL ;
@@ -409,7 +412,7 @@ static int tegra_syncpt_wait(struct drm_device *drm, void *data,struct drm_tegra_syncpt_wait *args = data;struct host1x_syncpt *sp; - sp =host1x_syncpt_get (host1x, args->id); + sp =host1x_syncpt_get_by_id_noref (host1x, args->id);if (!sp)return -EINVAL ;
drivers/gpu/drm/tegra/gr2d.c +2 -2
@@ -67,7 +67,7 @@ static int gr2d_init(struct host1x_client *client) detach:host1x_client_iommu_detach (client); free: -host1x_syncpt_free (client->syncpts[0 ]); +host1x_syncpt_put (client->syncpts[0 ]); put:host1x_channel_put (gr2d->channel);return err;
@@ -86,7 +86,7 @@ static int gr2d_exit(struct host1x_client *client)return err;host1x_client_iommu_detach (client); -host1x_syncpt_free (client->syncpts[0 ]); +host1x_syncpt_put (client->syncpts[0 ]);host1x_channel_put (gr2d->channel);return 0 ;
drivers/gpu/drm/tegra/gr3d.c +2 -2
@@ -76,7 +76,7 @@ static int gr3d_init(struct host1x_client *client) detach:host1x_client_iommu_detach (client); free: -host1x_syncpt_free (client->syncpts[0 ]); +host1x_syncpt_put (client->syncpts[0 ]); put:host1x_channel_put (gr3d->channel);return err;
@@ -94,7 +94,7 @@ static int gr3d_exit(struct host1x_client *client)return err;host1x_client_iommu_detach (client); -host1x_syncpt_free (client->syncpts[0 ]); +host1x_syncpt_put (client->syncpts[0 ]);host1x_channel_put (gr3d->channel);return 0 ;
drivers/gpu/drm/tegra/vic.c +2 -2
@@ -197,7 +197,7 @@ static int vic_init(struct host1x_client *client)return 0 ; free_syncpt: -host1x_syncpt_free (client->syncpts[0 ]); +host1x_syncpt_put (client->syncpts[0 ]); free_channel:host1x_channel_put (vic->channel); detach:
@@ -221,7 +221,7 @@ static int vic_exit(struct host1x_client *client)if (err <0 )return err; -host1x_syncpt_free (client->syncpts[0 ]); +host1x_syncpt_put (client->syncpts[0 ]);host1x_channel_put (vic->channel);host1x_client_iommu_detach (client);
drivers/gpu/host1x/cdma.c +3 -8
@@ -273,15 +273,13 @@ static int host1x_cdma_wait_pushbuffer_space(struct host1x *host1x,static void cdma_start_timer_locked (struct host1x_cdma *cdma,struct host1x_job *job) { -struct host1x *host =cdma_to_host1x (cdma); -if (cdma->timeout.client) {/* timer already started */ return ; } cdma->timeout.client = job->client; - cdma->timeout.syncpt =host1x_syncpt_get (host, job->syncpt_id); + cdma->timeout.syncpt = job->syncpt; cdma->timeout.syncpt_val = job->syncpt_end; cdma->timeout.start_ktime =ktime_get ();
@@ -312,7 +310,6 @@ static void stop_cdma_timer_locked(struct host1x_cdma *cdma)static void update_cdma_locked (struct host1x_cdma *cdma) {bool signal = false; -struct host1x *host1x =cdma_to_host1x (cdma);struct host1x_job *job, *n;/* If CDMA is stopped, queue is cleared and we can return */
@@ -324,8 +321,7 @@ static void update_cdma_locked(struct host1x_cdma *cdma)* to consume as many sync queue entries as possible without blocking */ list_for_each_entry_safe (job, n, &cdma->sync_queue, list) { -struct host1x_syncpt *sp = -host1x_syncpt_get (host1x, job->syncpt_id); +struct host1x_syncpt *sp = job->syncpt;/* Check whether this syncpt has completed, and bail if not */ if (!host1x_syncpt_is_expired (sp, job->syncpt_end)) {
@@ -499,8 +495,7 @@ int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job)if (!cdma->timeout.initialized) {int err; - err =host1x_hw_cdma_timeout_init (host1x, cdma, - job->syncpt_id); + err =host1x_hw_cdma_timeout_init (host1x, cdma);if (err) {mutex_unlock (&cdma->lock);return err;
drivers/gpu/host1x/dev.h +3 -4
@@ -37,7 +37,7 @@ struct host1x_cdma_ops {void (*start)(struct host1x_cdma *cdma);void (*stop)(struct host1x_cdma *cdma);void (*flush)(struct host1x_cdma *cdma); -int (*timeout_init)(struct host1x_cdma *cdma,unsigned int syncpt); +int (*timeout_init)(struct host1x_cdma *cdma);void (*timeout_destroy)(struct host1x_cdma *cdma);void (*freeze)(struct host1x_cdma *cdma);void (*resume)(struct host1x_cdma *cdma,u32 getptr);
@@ -261,10 +261,9 @@ static inline void host1x_hw_cdma_flush(struct host1x *host, }static inline int host1x_hw_cdma_timeout_init (struct host1x *host, -struct host1x_cdma *cdma, -unsigned int syncpt) +struct host1x_cdma *cdma) { -return host->cdma_op->timeout_init (cdma, syncpt); +return host->cdma_op->timeout_init (cdma); } static inline void host1x_hw_cdma_timeout_destroy(struct host1x *host,
drivers/gpu/host1x/hw/cdma_hw.c +1 -1
@@ -295,7 +295,7 @@ static void cdma_timeout_handler(struct work_struct *work)/* * Init timeout resources */ -static int cdma_timeout_init (struct host1x_cdma *cdma,unsigned int syncpt) +static int cdma_timeout_init (struct host1x_cdma *cdma) {INIT_DELAYED_WORK (&cdma->timeout.wq, cdma_timeout_handler); cdma->timeout.initialized = true;
drivers/gpu/host1x/hw/channel_hw.c +4 -6
@@ -86,8 +86,7 @@ static void submit_gathers(struct host1x_job *job)static inline void synchronize_syncpt_base (struct host1x_job *job) { -struct host1x *host =dev_get_drvdata (job->channel->dev->parent); -struct host1x_syncpt *sp = host->syncpt + job->syncpt_id; +struct host1x_syncpt *sp = job->syncpt;unsigned int id;u32 value;
@@ -118,7 +117,7 @@ static void host1x_channel_set_streamid(struct host1x_channel *channel)static int channel_submit (struct host1x_job *job) {struct host1x_channel *ch = job->channel; -struct host1x_syncpt *sp; +struct host1x_syncpt *sp = job->syncpt;u32 user_syncpt_incrs = job->syncpt_incrs;u32 prev_max =0 ;u32 syncval;
@@ -126,10 +125,9 @@ static int channel_submit(struct host1x_job *job)struct host1x_waitlist *completed_waiter =NULL ;struct host1x *host =dev_get_drvdata (ch->dev->parent); - sp = host->syncpt + job->syncpt_id;trace_host1x_channel_submit (dev_name (ch->dev), job->num_gathers, job->num_relocs, - job->syncpt_id, job->syncpt_incrs); + job->syncpt->id, job->syncpt_incrs);/* before error checks, return current max */ prev_max = job->syncpt_end =host1x_syncpt_read_max (sp);
@@ -163,7 +161,7 @@ static int channel_submit(struct host1x_job *job)host1x_cdma_push (&ch->cdma,host1x_opcode_setclass (HOST1X_CLASS_HOST1X ,host1x_uclass_wait_syncpt_r (),1 ), -host1x_class_host_wait_syncpt (job->syncpt_id, +host1x_class_host_wait_syncpt (job->syncpt->id,host1x_syncpt_read_max (sp))); }
drivers/gpu/host1x/hw/debug_hw.c +1 -1
@@ -204,7 +204,7 @@ static void show_channel_gathers(struct output *o, struct host1x_cdma *cdma)unsigned int i;host1x_debug_output (o,"\n%p: JOB, syncpt_id=%d, syncpt_val=%d, first_get=%08x, timeout=%d num_slots=%d, num_handles=%d\n" , - job, job->syncpt_id, job->syncpt_end, + job, job->syncpt->id, job->syncpt_end, job->first_get, job->timeout, job->num_slots, job->num_unpins);
drivers/gpu/host1x/job.c +4 -1
@@ -79,6 +79,9 @@ static void job_free(struct kref *ref) { struct host1x_job *job = container_of(ref, struct host1x_job, ref); +if (job->syncpt) +host1x_syncpt_put (job->syncpt); +kfree (job); }
@@ -680,7 +683,7 @@ EXPORT_SYMBOL(host1x_job_unpin);*/ void host1x_job_dump (struct device *dev,struct host1x_job *job) { -dev_dbg (dev," SYNCPT_ID %d\n" , job->syncpt_id); +dev_dbg (dev," SYNCPT_ID %d\n" , job->syncpt->id);dev_dbg (dev," SYNCPT_VAL %d\n" , job->syncpt_end);dev_dbg (dev," FIRST_GET 0x%x\n" , job->first_get);dev_dbg (dev," TIMEOUT %d\n" , job->timeout);
drivers/gpu/host1x/syncpt.c +57 -18
113 lines not on this page · raw message
drivers/gpu/host1x/syncpt.h +3 -0
@@ -11,6 +11,7 @@#include <linux/atomic.h> #include <linux/host1x.h> #include <linux/kernel.h> +#include <linux/kref.h> #include <linux/sched.h> #include "intr.h"
@@ -26,6 +27,8 @@ struct host1x_syncpt_base { };struct host1x_syncpt { +struct kref ref; +unsigned int id;atomic_t min_val;atomic_t max_val;
include/linux/host1x.h +5 -3
@@ -142,7 +142,9 @@ struct host1x_syncpt_base;struct host1x_syncpt ;struct host1x ; -struct host1x_syncpt *host1x_syncpt_get (struct host1x *host,u32 id); +struct host1x_syncpt *host1x_syncpt_get_by_id (struct host1x *host,u32 id); +struct host1x_syncpt *host1x_syncpt_get_by_id_noref (struct host1x *host,u32 id); +struct host1x_syncpt *host1x_syncpt_get (struct host1x_syncpt *sp);u32 host1x_syncpt_id (struct host1x_syncpt *sp);u32 host1x_syncpt_read_min (struct host1x_syncpt *sp);u32 host1x_syncpt_read_max (struct host1x_syncpt *sp);
@@ -153,7 +155,7 @@ int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout, u32 *value);struct host1x_syncpt *host1x_syncpt_request (struct host1x_client *client,unsigned long flags); -void host1x_syncpt_free (struct host1x_syncpt *sp); +void host1x_syncpt_put (struct host1x_syncpt *sp);struct host1x_syncpt *host1x_syncpt_alloc (struct host1x *host,unsigned long flags,const char *name);
@@ -221,7 +223,7 @@ struct host1x_job {dma_addr_t *reloc_addr_phys;/* Sync point id, number of increments and end related to the submit */ -u32 syncpt_id; +struct host1x_syncpt *syncpt;u32 syncpt_incrs;u32 syncpt_end;
Signature · 1 line
2.28.0
kernel test robot
build botRe: [PATCH v3 06/20] gpu: host1x: Cleanup and refcounting for syncpoints
Thank you for the patch! Yet something to improve:
Hi Mikko,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on tegra-drm/drm/tegra/for-next]
[also build test ERROR on tegra/for-next linus/master v5.9-rc8 next-20201007] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Mikko-Perttunen/Host1x-TegraDRM-UAPI/20201008-034403 base: git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next config: arm-allyesconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/3721bf9ddd2b05fe12b3512999f77351ae839d08
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mikko-Perttunen/Host1x-TegraDRM-UAPI/20201008-034403 git checkout 3721bf9ddd2b05fe12b3512999f77351ae839d08
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/staging/media/tegra-video/vi.c: In function 'tegra_channel_cleanup':
>> drivers/staging/media/tegra-video/vi.c:621:2: error: implicit declaration of function 'host1x_syncpt_free'; did you mean 'host1x_syncpt_read'? [-Werror=implicit-function-declaration]
621 | host1x_syncpt_free(chan->mw_ack_sp);
| ^~~~~~~~~~~~~~~~~~
| host1x_syncpt_readcc1: some warnings being treated as errors
vim +621 drivers/staging/media/tegra-video/vi.c
3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 616
3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 617 static void tegra_channel_cleanup(struct tegra_vi_channel *chan)
3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 618 {
3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 619 v4l2_ctrl_handler_free(&chan->ctrl_handler);
3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 620 media_entity_cleanup(&chan->video.entity);
3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 @621 host1x_syncpt_free(chan->mw_ack_sp);
3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 622 host1x_syncpt_free(chan->frame_start_sp);
3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 623 mutex_destroy(&chan->video_lock);
3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 624 }3d8a97eabef0883 Sowjanya Komatineni 2020-05-04 625
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Mikko Perttunen
maintainerPATCH v3 7/20 gpu: host1x: Introduce UAPI header
In reply to Mikko PerttunenAdd the userspace interface header, specifying interfaces for allocating and accessing syncpoints from userspace, and for creating sync_file based fences based on syncpoint thresholds.
--- include/uapi/linux/host1x.h | 134 ++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 include/uapi/linux/host1x.h
include/uapi/linux/host1x.h new file +134 -0
@@ -0,0 +1,134 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (c) 2020 NVIDIA Corporation */ + +#ifndef _UAPI__LINUX_HOST1X_H +#define _UAPI__LINUX_HOST1X_H + +#include <linux/ioctl.h> +#include <linux/types.h> + +#if defined(__cplusplus) +extern "C" { +#endif + +struct host1x_allocate_syncpoint { +/** +* @fd: [out] +* +* New file descriptor representing the allocated syncpoint. +*/ +__s32 fd; + +__u32 reserved[3 ]; +}; + +struct host1x_syncpoint_info { +/** +* @id: [out] +* +* System-global ID of the syncpoint. +*/ +__u32 id; + +__u32 reserved[3 ]; +}; + +struct host1x_syncpoint_increment { +/** +* @count: [in] +* +* Number of times to increment the syncpoint. The syncpoint can +* be observed at in-between values, but each increment is atomic. +*/ +__u32 count; +}; + +struct host1x_read_syncpoint { +/** +* @id: [in] +* +* ID of the syncpoint to read. +*/ +__u32 id; + +/** +* @value: [out] +* +* Current value of the syncpoint. +*/ +__u32 value; +}; + +struct host1x_create_fence { +/** +* @id: [in] +* +* ID of the syncpoint to create a fence for. +*/ +__u32 id; + +/** +* @threshold: [in] +* +* When the syncpoint reaches this value, the fence will be signaled. +* The syncpoint is considered to have reached the threshold when the +* following condition is true: +* +* ((value - threshold) & 0x80000000U) == 0U +* +*/ +__u32 threshold; + +/** +* @fence_fd: [out] +* +* New sync_file file descriptor containing the created fence. +*/ +__s32 fence_fd; + +__u32 reserved[1 ]; +}; + +struct host1x_fence_extract_fence { +__u32 id; +__u32 threshold; +}; + +struct host1x_fence_extract { +/** +* @fence_fd: [in] +* +* sync_file file descriptor +*/ +__s32 fence_fd; + +/** +* @num_fences: [in,out] +* +* In: size of the `fences_ptr` array counted in elements. +* Out: required size of the `fences_ptr` array counted in elements. +*/ +__u32 num_fences; + +/** +* @fences_ptr: [in] +* +* Pointer to array of `struct host1x_fence_extract_fence`. +*/ +__u64 fences_ptr; + +__u32 reserved[2 ]; +}; + +#define HOST1X_IOCTL_ALLOCATE_SYNCPOINT _IOWR('X', 0x00, struct host1x_allocate_syncpoint) +#define HOST1X_IOCTL_READ_SYNCPOINT _IOR ('X', 0x01, struct host1x_read_syncpoint) +#define HOST1X_IOCTL_CREATE_FENCE _IOWR('X', 0x02, struct host1x_create_fence) +#define HOST1X_IOCTL_SYNCPOINT_INFO _IOWR('X', 0x03, struct host1x_syncpoint_info) +#define HOST1X_IOCTL_SYNCPOINT_INCREMENT _IOWR('X', 0x04, struct host1x_syncpoint_increment) +#define HOST1X_IOCTL_FENCE_EXTRACT _IOWR('X', 0x05, struct host1x_fence_extract) + +#if defined(__cplusplus) +} +#endif + +#endif
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 8/20 gpu: host1x: Implement /dev/host1x device node
In reply to Mikko PerttunenAdd the /dev/host1x device node, implementing the following functionality:
- Reading syncpoint values
- Allocating syncpoints (providing syncpoint FDs)
- Incrementing syncpoints (based on syncpoint FD)
---
v3:
* Pass process name as syncpoint name when allocating syncpoint.
--- drivers/gpu/host1x/Makefile | 1 + drivers/gpu/host1x/dev.c | 9 ++ drivers/gpu/host1x/dev.h | 3 + drivers/gpu/host1x/uapi.c | 276 ++++++++++++++++++++++++++++++++++++ drivers/gpu/host1x/uapi.h | 22 +++ include/linux/host1x.h | 2 + 6 files changed, 313 insertions(+) create mode 100644 drivers/gpu/host1x/uapi.c create mode 100644 drivers/gpu/host1x/uapi.h
drivers/gpu/host1x/Makefile +1 -0
@@ -9,6 +9,7 @@ host1x-y = \ job.o \ debug.o \ mipi.o \ + uapi.o \ hw/host1x01.o \ hw/host1x02.o \ hw/host1x04.o \
drivers/gpu/host1x/dev.c +9 -0
@@ -461,6 +461,12 @@ static int host1x_probe(struct platform_device *pdev) goto deinit_syncpt; } + err =host1x_uapi_init (&host->uapi, host); +if (err) { +dev_err (&pdev->dev,"failed to initialize uapi\n" ); + goto deinit_intr; + } +host1x_debug_init (host);if (host->info->has_hypervisor)
@@ -480,6 +486,8 @@ static int host1x_probe(struct platform_device *pdev)host1x_unregister (host); deinit_debugfs:host1x_debug_deinit (host); +host1x_uapi_deinit (&host->uapi); +deinit_intr:host1x_intr_deinit (host); deinit_syncpt:host1x_syncpt_deinit (host);
@@ -501,6 +509,7 @@ static int host1x_remove(struct platform_device *pdev)host1x_unregister (host);host1x_debug_deinit (host); +host1x_uapi_deinit (&host->uapi);host1x_intr_deinit (host);host1x_syncpt_deinit (host);reset_control_assert (host->rst);
drivers/gpu/host1x/dev.h +3 -0
@@ -17,6 +17,7 @@#include "intr.h" #include "job.h" #include "syncpt.h" +#include "uapi.h" struct host1x_syncpt ;struct host1x_syncpt_base ;
@@ -143,6 +144,8 @@ struct host1x {struct list_head list;struct device_dma_parameters dma_parms; + +struct host1x_uapi uapi; };void host1x_hypervisor_writel (struct host1x *host1x,u32 r,u32 v);
drivers/gpu/host1x/uapi.c new file +276 -0
276 lines not on this page · raw message
drivers/gpu/host1x/uapi.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2020, NVIDIA Corporation. +*/ + +#ifndef HOST1X_UAPI_H +#define HOST1X_UAPI_H + +#include <linux/cdev.h> + +struct host1x_uapi { +struct class *class; + +struct cdev cdev; +struct device *dev; +dev_t dev_num; +}; + +int host1x_uapi_init (struct host1x_uapi *uapi,struct host1x *host1x); +void host1x_uapi_deinit (struct host1x_uapi *uapi); + +#endif
include/linux/host1x.h +2 -0
@@ -163,6 +163,8 @@ struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,struct host1x_syncpt_base *host1x_syncpt_get_base (struct host1x_syncpt *sp);u32 host1x_syncpt_base_id (struct host1x_syncpt_base *base); +struct host1x_syncpt *host1x_syncpt_fd_get (int fd); +/* * host1x channel */
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 9/20 gpu: host1x: DMA fences and userspace fence creation
In reply to Mikko PerttunenAdd an implementation of dma_fences based on syncpoints. Syncpoint interrupts are used to signal fences. Additionally, after software signaling has been enabled, a 30 second timeout is started. If the syncpoint threshold is not reached within this period, the fence is signalled with an -ETIMEDOUT error code. This is to allow fences that would never reach their syncpoint threshold to be cleaned up.
Additionally, add a new /dev/host1x IOCTL for creating sync_file file descriptors backed by syncpoint fences.
---
v3:
* Move declaration of host1x_fence_extract to public header
--- drivers/gpu/host1x/Makefile | 1 + drivers/gpu/host1x/fence.c | 207 ++++++++++++++++++++++++++++++++++++ drivers/gpu/host1x/fence.h | 13 +++ drivers/gpu/host1x/intr.c | 9 ++ drivers/gpu/host1x/intr.h | 2 + drivers/gpu/host1x/uapi.c | 106 ++++++++++++++++++ include/linux/host1x.h | 4 + 7 files changed, 342 insertions(+) create mode 100644 drivers/gpu/host1x/fence.c create mode 100644 drivers/gpu/host1x/fence.h
drivers/gpu/host1x/Makefile +1 -0
@@ -10,6 +10,7 @@ host1x-y = \ debug.o \ mipi.o \ uapi.o \ + fence.o \ hw/host1x01.o \ hw/host1x02.o \ hw/host1x04.o \
drivers/gpu/host1x/fence.c new file +207 -0
207 lines not on this page · raw message
drivers/gpu/host1x/fence.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2020, NVIDIA Corporation. +*/ + +#ifndef HOST1X_FENCE_H +#define HOST1X_FENCE_H + +struct host1x_syncpt_fence ; + +bool host1x_fence_signal (struct host1x_syncpt_fence *fence); + +#endif
drivers/gpu/host1x/intr.c +9 -0
@@ -13,6 +13,7 @@#include <trace/events/host1x.h> #include "channel.h" #include "dev.h" +#include "fence.h" #include "intr.h" /* Wait list management */
@@ -121,12 +122,20 @@ static void action_wakeup_interruptible(struct host1x_waitlist *waiter)wake_up_interruptible (wq); } +static void action_signal_fence (struct host1x_waitlist *waiter) +{ +struct host1x_syncpt_fence *f = waiter->data; + +host1x_fence_signal (f); +} +typedef void (*action_handler )(struct host1x_waitlist *waiter);static const action_handler action_handlers[HOST1X_INTR_ACTION_COUNT ] = { action_submit_complete, action_wakeup, action_wakeup_interruptible, + action_signal_fence, };static void run_handlers (struct list_head completed[HOST1X_INTR_ACTION_COUNT ])
drivers/gpu/host1x/intr.h +2 -0
@@ -33,6 +33,8 @@ enum host1x_intr_action {*/ HOST1X_INTR_ACTION_WAKEUP_INTERRUPTIBLE , +HOST1X_INTR_ACTION_SIGNAL_FENCE , + HOST1X_INTR_ACTION_COUNT };
drivers/gpu/host1x/uapi.c +106 -0
126 lines not on this page · raw message
include/linux/host1x.h +4 -0
@@ -165,6 +165,10 @@ u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);struct host1x_syncpt *host1x_syncpt_fd_get (int fd); +struct dma_fence *host1x_fence_create (struct host1x_syncpt *sp,u32 threshold); +int host1x_fence_create_fd (struct host1x_syncpt *sp,u32 threshold); +int host1x_fence_extract (struct dma_fence *fence,u32 *id,u32 *threshold); +/* * host1x channel */
Signature · 1 line
2.28.0
kernel test robot
build botRe: [PATCH v3 09/20] gpu: host1x: DMA fences and userspace fence creation
Thank you for the patch! Perhaps something to improve:
Hi Mikko,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on tegra-drm/drm/tegra/for-next]
[also build test WARNING on tegra/for-next linus/master v5.9-rc8 next-20201007] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Mikko-Perttunen/Host1x-TegraDRM-UAPI/20201008-034403 base: git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next config: arm64-randconfig-r004-20201008 (attached as .config) compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/c4f5ec983027f2b19e6854a362e23a79e1630100
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mikko-Perttunen/Host1x-TegraDRM-UAPI/20201008-034403 git checkout c4f5ec983027f2b19e6854a362e23a79e1630100
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpu/host1x/fence.c:105:6: warning: no previous prototype for 'host1x_fence_signal' [-Wmissing-prototypes]
105 | void host1x_fence_signal(struct host1x_syncpt_fence *f)
| ^~~~~~~~~~~~~~~~~~~
vim +/host1x_fence_signal +105 drivers/gpu/host1x/fence.c
104
> 105 void host1x_fence_signal(struct host1x_syncpt_fence *f)
106 {
107 if (atomic_xchg(&f->signaling, 1))
108 return;
109
110 /*
111 * Cancel pending timeout work - if it races, it will
112 * not get 'f->signaling' and return.
113 */
114 cancel_delayed_work_sync(&f->timeout_work);
115
116 host1x_intr_put_ref(f->sp->host, f->sp->id, f->waiter_ref);
117
118 dma_fence_signal(&f->base);
119 dma_fence_put(&f->base);
120 }
121
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v3 09/20] gpu: host1x: DMA fences and userspace fence creation
In reply to Mikko PerttunenThank you for the patch! Perhaps something to improve:
Hi Mikko,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on tegra-drm/drm/tegra/for-next]
[also build test WARNING on tegra/for-next linus/master v5.9-rc8 next-20201007] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Mikko-Perttunen/Host1x-TegraDRM-UAPI/20201008-034403 base: git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next config: arm64-randconfig-r021-20201008 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 4d1d8ae7100ec3c7e1709addb7b3ec6f9ad0b44f)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/c4f5ec983027f2b19e6854a362e23a79e1630100
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mikko-Perttunen/Host1x-TegraDRM-UAPI/20201008-034403 git checkout c4f5ec983027f2b19e6854a362e23a79e1630100
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpu/host1x/uapi.c:227:8: warning: variable 'file' is uninitialized when used here [-Wuninitialized]
fput(file->file);
^~~~
drivers/gpu/host1x/uapi.c:204:24: note: initialize the variable 'file' to silence this warning
struct sync_file *file;
^
= NULL
1 warning generated.
--
>> drivers/gpu/host1x/fence.c:105:6: warning: no previous prototype for function 'host1x_fence_signal' [-Wmissing-prototypes]
void host1x_fence_signal(struct host1x_syncpt_fence *f)
^ drivers/gpu/host1x/fence.c:105:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void host1x_fence_signal(struct host1x_syncpt_fence *f)
^
static
1 warning generated.
vim +/file +227 drivers/gpu/host1x/uapi.c
199
200 static int dev_file_ioctl_create_fence(struct host1x *host1x, void __user *data)
201 {
202 struct host1x_create_fence args;
203 unsigned long copy_err;
204 struct sync_file *file;
205 int fd;
206
207 copy_err = copy_from_user(&args, data, sizeof(args));
208 if (copy_err)
209 return -EFAULT;
210
211 if (args.reserved[0])
212 return -EINVAL;
213
214 if (args.id >= host1x_syncpt_nb_pts(host1x))
215 return -EINVAL;
216
217 args.id = array_index_nospec(args.id, host1x_syncpt_nb_pts(host1x));
218
219 fd = host1x_fence_create_fd(&host1x->syncpt[args.id], args.threshold);
220 if (fd < 0)
221 return fd;
222
223 args.fence_fd = fd;
224
225 copy_err = copy_to_user(data, &args, sizeof(args));
226 if (copy_err) {
> 227 fput(file->file);
228 return -EFAULT;
229 }
230
231 return 0;
232 }
233
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Mikko Perttunen
maintainerPATCH v3 10/20 gpu: host1x: Add no-recovery mode
In reply to Mikko PerttunenAdd a new property for jobs to enable or disable recovery i.e. CPU increments of syncpoints to max value on job timeout. This allows for a more solid model for hanged jobs, where userspace doesn't need to guess if a syncpoint increment happened because the job completed, or because job timeout was triggered.
On job timeout, we stop the channel, NOP all future jobs on the channel using the same syncpoint, mark the syncpoint as locked and resume the channel from the next job, if any.
The future jobs are NOPed, since because we don't do the CPU increments, the value of the syncpoint is no longer synchronized, and any waiters would become confused if a future job incremented the syncpoint. The syncpoint is marked locked to ensure that any future jobs cannot increment the syncpoint either, until the application has recognized the situation and reallocated the syncpoint.
---
v3:
* Move 'locked' check inside CDMA lock to prevent race
* Add clarifying comment to NOP-patching code
--- drivers/gpu/drm/tegra/drm.c | 1 + drivers/gpu/host1x/cdma.c | 58 ++++++++++++++++++++++++++---- drivers/gpu/host1x/hw/channel_hw.c | 2 +- drivers/gpu/host1x/job.c | 4 +++ drivers/gpu/host1x/syncpt.c | 2 ++ drivers/gpu/host1x/syncpt.h | 12 +++++++ include/linux/host1x.h | 9 +++++ 7 files changed, 81 insertions(+), 7 deletions(-)
drivers/gpu/drm/tegra/drm.c +1 -0
@@ -197,6 +197,7 @@ int tegra_drm_submit(struct tegra_drm_context *context, job->client = client; job->class = client->class; job->serialize = true; + job->syncpt_recovery = true;/* * Track referenced BOs so that they can be unreferenced after the
drivers/gpu/host1x/cdma.c +52 -6
91 lines not on this page · raw message
drivers/gpu/host1x/hw/channel_hw.c +1 -1
@@ -191,7 +191,7 @@ static int channel_submit(struct host1x_job *job)/* schedule a submit complete interrupt */ err =host1x_intr_add_action (host, sp, syncval,HOST1X_INTR_ACTION_SUBMIT_COMPLETE , ch, - completed_waiter,NULL ); + completed_waiter, &job->waiter); completed_waiter =NULL ;WARN (err,"Failed to set submit complete interrupt" );
drivers/gpu/host1x/job.c +4 -0
@@ -79,6 +79,10 @@ static void job_free(struct kref *ref) { struct host1x_job *job = container_of(ref, struct host1x_job, ref); +if (job->waiter) +host1x_intr_put_ref (job->syncpt->host, job->syncpt->id, + job->waiter); +if (job->syncpt)host1x_syncpt_put (job->syncpt);
drivers/gpu/host1x/syncpt.c +2 -0
@@ -385,6 +385,8 @@ static void syncpt_release(struct kref *ref) { struct host1x_syncpt *sp = container_of(ref, struct host1x_syncpt, ref); + sp->locked = false; +mutex_lock (&sp->host->syncpt_mutex);host1x_syncpt_base_free (sp->base);
drivers/gpu/host1x/syncpt.h +12 -0
@@ -40,6 +40,13 @@ struct host1x_syncpt {/* interrupt data */ struct host1x_syncpt_intr intr; + +/* +* If a submission incrementing this syncpoint fails, lock it so that +* further submission cannot be made until application has handled the +* failure. +*/ +bool locked; };/* Initialize sync point array */
@@ -115,4 +122,9 @@ static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp) return sp->id < host1x_syncpt_nb_pts(sp->host); } +static inline void host1x_syncpt_set_locked (struct host1x_syncpt *sp) +{ + sp->locked = true; +} +#endif
include/linux/host1x.h +9 -0
@@ -233,9 +233,15 @@ struct host1x_job {u32 syncpt_incrs;u32 syncpt_end; +/* Completion waiter ref */ +void *waiter; +/* Maximum time to wait for this job */ unsigned int timeout; +/* Job has timed out and should be released */ +bool cancelled; +/* Index and number of slots used in the push buffer */ unsigned int first_get;unsigned int num_slots;
@@ -256,6 +262,9 @@ struct host1x_job {/* Add a channel wait for previous ops to complete */ bool serialize; + +/* Fast-forward syncpoint increments on job timeout */ +bool syncpt_recovery; }; struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 11/20 gpu: host1x: Add job release callback
In reply to Mikko PerttunenAdd a callback field to the job structure, to be called just before the job is to be freed. This allows the job's submitter to clean up any of its own state, like decrement runtime PM refcounts.
--- drivers/gpu/host1x/job.c | 3 +++ include/linux/host1x.h | 4 ++++ 2 files changed, 7 insertions(+)
drivers/gpu/host1x/job.c +3 -0
@@ -79,6 +79,9 @@ static void job_free(struct kref *ref) { struct host1x_job *job = container_of(ref, struct host1x_job, ref); +if (job->release) + job->release (job); +if (job->waiter)host1x_intr_put_ref (job->syncpt->host, job->syncpt->id, job->waiter);
include/linux/host1x.h +4 -0
@@ -265,6 +265,10 @@ struct host1x_job {/* Fast-forward syncpoint increments on job timeout */ bool syncpt_recovery; + +/* Callback called when job is freed */ +void (*release)(struct host1x_job *job); +void *user_data; }; struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 12/20 gpu: host1x: Add support for syncpoint waits in CDMA pushbuffer
In reply to Mikko PerttunenAdd support for inserting syncpoint waits in the CDMA pushbuffer. These waits need to be done in HOST1X class, while gather submitted by the application execute in engine class.
Support is added by converting the gather list of job into a command list that can include both gathers and waits. When the job is submitted, these commands are pushed as the appropriate opcodes on the CDMA pushbuffer.
--- drivers/gpu/host1x/hw/channel_hw.c | 51 +++++++++++++++-------- drivers/gpu/host1x/hw/debug_hw.c | 9 +++- drivers/gpu/host1x/job.c | 67 +++++++++++++++++++++--------- drivers/gpu/host1x/job.h | 14 +++++++ include/linux/host1x.h | 5 ++- 5 files changed, 105 insertions(+), 41 deletions(-)
drivers/gpu/host1x/hw/channel_hw.c +33 -18
@@ -55,31 +55,46 @@ static void submit_gathers(struct host1x_job *job)#endif unsigned int i; -for (i =0 ; i < job->num_gathers; i++) { -struct host1x_job_gather *g = &job->gathers[i]; -dma_addr_t addr = g->base + g->offset; -u32 op2, op3; +for (i =0 ; i < job->num_cmds; i++) { +struct host1x_job_cmd *cmd = &job->cmds[i]; - op2 =lower_32_bits (addr); - op3 =upper_32_bits (addr); +if (cmd->is_wait) { +/* TODO use modern wait */ +host1x_cdma_push (cdma, +host1x_opcode_setclass (HOST1X_CLASS_HOST1X , +host1x_uclass_wait_syncpt_r (),1 ), +host1x_class_host_wait_syncpt (cmd->wait.id, + cmd->wait.threshold)); +host1x_cdma_push ( + cdma,host1x_opcode_setclass (job->class,0 ,0 ), +HOST1X_OPCODE_NOP ); + }else { +struct host1x_job_gather *g = &cmd->gather; -trace_write_gather (cdma, g->bo, g->offset, g->words); +dma_addr_t addr = g->base + g->offset; +u32 op2, op3; -if (op3 !=0 ) { + op2 =lower_32_bits (addr); + op3 =upper_32_bits (addr); + +trace_write_gather (cdma, g->bo, g->offset, g->words); + +if (op3 !=0 ) {#if HOST1X_HW >=6 -u32 op1 =host1x_opcode_gather_wide (g->words); -u32 op4 =HOST1X_OPCODE_NOP ; +u32 op1 =host1x_opcode_gather_wide (g->words); +u32 op4 =HOST1X_OPCODE_NOP ; -host1x_cdma_push_wide (cdma, op1, op2, op3, op4); +host1x_cdma_push_wide (cdma, op1, op2, op3, op4);#else -dev_err (dev,"invalid gather for push buffer %pad\n" , - &addr); -continue ; +dev_err (dev,"invalid gather for push buffer %pad\n" , + &addr); +continue ;#endif - }else { -u32 op1 =host1x_opcode_gather (g->words); + }else { +u32 op1 =host1x_opcode_gather (g->words); -host1x_cdma_push (cdma, op1, op2); +host1x_cdma_push (cdma, op1, op2); + } } } }
@@ -126,7 +141,7 @@ static int channel_submit(struct host1x_job *job)struct host1x *host =dev_get_drvdata (ch->dev->parent);trace_host1x_channel_submit (dev_name (ch->dev), - job->num_gathers, job->num_relocs, + job->num_cmds, job->num_relocs, job->syncpt->id, job->syncpt_incrs);/* before error checks, return current max */
drivers/gpu/host1x/hw/debug_hw.c +7 -2
@@ -208,10 +208,15 @@ static void show_channel_gathers(struct output *o, struct host1x_cdma *cdma) job->first_get, job->timeout, job->num_slots, job->num_unpins); -for (i =0 ; i < job->num_gathers; i++) { -struct host1x_job_gather *g = &job->gathers[i]; +for (i =0 ; i < job->num_cmds; i++) { +struct host1x_job_gather *g;u32 *mapped; +if (job->cmds[i].is_wait) +continue ; + + g = &job->cmds[i].gather; +if (job->gather_copy_mapped) mapped = (u32 *)job->gather_copy_mapped;else
drivers/gpu/host1x/job.c +48 -19
145 lines not on this page · raw message
drivers/gpu/host1x/job.h +14 -0
@@ -18,6 +18,20 @@ struct host1x_job_gather {bool handled; }; +struct host1x_job_wait { +u32 id; +u32 threshold; +}; + +struct host1x_job_cmd { +bool is_wait; + +union { +struct host1x_job_gather gather; +struct host1x_job_wait wait; + }; +}; +struct host1x_job_unpin_data {struct host1x_bo *bo;struct sg_table *sgt;
include/linux/host1x.h +3 -2
@@ -215,8 +215,8 @@ struct host1x_job {struct host1x_client *client;/* Gathers and their memory */ -struct host1x_job_gather *gathers; -unsigned int num_gathers; +struct host1x_job_cmd *cmds; +unsigned int num_cmds;/* Array of handles to be pinned & unpinned */ struct host1x_reloc *relocs;
@@ -275,6 +275,7 @@ struct host1x_job *host1x_job_alloc(struct host1x_channel *ch, u32 num_cmdbufs, u32 num_relocs);void host1x_job_add_gather (struct host1x_job *job,struct host1x_bo *bo,unsigned int words,unsigned int offset); +void host1x_job_add_wait (struct host1x_job *job,u32 id,u32 thresh);struct host1x_job *host1x_job_get (struct host1x_job *job);void host1x_job_put (struct host1x_job *job);int host1x_job_pin (struct host1x_job *job,struct device *dev);
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 13/20 gpu: host1x: Reset max value when freeing a syncpoint
In reply to Mikko PerttunenWith job recovery becoming optional, syncpoints may have a mismatch between their value and max value when freed. As such, when freeing, set the max value to the current value of the syncpoint so that it is in a sane state for the next user.
---
v3:
* Use host1x_syncpt_read instead of read_min to ensure syncpoint value is current.
--- drivers/gpu/host1x/syncpt.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/host1x/syncpt.c +1 -0
@@ -385,6 +385,7 @@ static void syncpt_release(struct kref *ref) { struct host1x_syncpt *sp = container_of(ref, struct host1x_syncpt, ref); +atomic_set (&sp->max_val,host1x_syncpt_read (sp)); sp->locked = false;mutex_lock (&sp->host->syncpt_mutex);
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 14/20 gpu: host1x: Reserve VBLANK syncpoints at initialization
In reply to Mikko PerttunenOn T20-T148 chips, the bootloader can set up a boot splash screen with DC configured to increment syncpoint 26/27 at VBLANK. Because of this we shouldn't allow these syncpoints to be allocated until DC has been reset and will no longer increment them in the background.
As such, on these chips, reserve those two syncpoints at initialization, and only mark them free once the DC driver has indicated it's safe to do so.
---
v3:
* New patch
--- drivers/gpu/drm/tegra/dc.c | 6 ++++++ drivers/gpu/host1x/dev.c | 6 ++++++ drivers/gpu/host1x/dev.h | 6 ++++++ drivers/gpu/host1x/syncpt.c | 34 +++++++++++++++++++++++++++++++++- include/linux/host1x.h | 3 +++ 5 files changed, 54 insertions(+), 1 deletion(-)
drivers/gpu/drm/tegra/dc.c +6 -0
@@ -2031,6 +2031,12 @@ static int tegra_dc_init(struct host1x_client *client)struct drm_plane *cursor =NULL ;int err; +/* +* DC has been reset by now, so VBLANK syncpoint can be released +* for general use. +*/ +host1x_syncpt_release_vblank_reservation (client,26 + dc->pipe); +/* * XXX do not register DCs with no window groups because we cannot * assign a primary plane to them, which in turn will cause KMS to
drivers/gpu/host1x/dev.c +6 -0
@@ -77,6 +77,7 @@ static const struct host1x_info host1x01_info = { .has_hypervisor = false, .num_sid_entries = 0, .sid_table = NULL, + .reserve_vblank_syncpts = true, };static const struct host1x_info host1x02_info = {
@@ -91,6 +92,7 @@ static const struct host1x_info host1x02_info = { .has_hypervisor = false, .num_sid_entries = 0, .sid_table = NULL, + .reserve_vblank_syncpts = true, };static const struct host1x_info host1x04_info = {
@@ -105,6 +107,7 @@ static const struct host1x_info host1x04_info = { .has_hypervisor = false, .num_sid_entries = 0, .sid_table = NULL, + .reserve_vblank_syncpts = false, };static const struct host1x_info host1x05_info = {
@@ -119,6 +122,7 @@ static const struct host1x_info host1x05_info = { .has_hypervisor = false, .num_sid_entries = 0, .sid_table = NULL, + .reserve_vblank_syncpts = false, };static const struct host1x_sid_entry tegra186_sid_table[] = {
@@ -142,6 +146,7 @@ static const struct host1x_info host1x06_info = { .has_hypervisor = true, .num_sid_entries = ARRAY_SIZE(tegra186_sid_table), .sid_table = tegra186_sid_table, + .reserve_vblank_syncpts = false, };static const struct host1x_sid_entry tegra194_sid_table[] = {
@@ -165,6 +170,7 @@ static const struct host1x_info host1x07_info = { .has_hypervisor = true, .num_sid_entries = ARRAY_SIZE(tegra194_sid_table), .sid_table = tegra194_sid_table, + .reserve_vblank_syncpts = false, };static const struct of_device_id host1x_of_match[] = {
drivers/gpu/host1x/dev.h +6 -0
@@ -102,6 +102,12 @@ struct host1x_info {bool has_hypervisor;/* has hypervisor registers */ unsigned int num_sid_entries;const struct host1x_sid_entry *sid_table; +/* +* On T20-T148, the boot chain may setup DC to increment syncpoints +* 26/27 on VBLANK. As such we cannot use these syncpoints until +* the display driver disables VBLANK increments. +*/ +bool reserve_vblank_syncpts; };struct host1x {
drivers/gpu/host1x/syncpt.c +33 -1
@@ -52,7 +52,7 @@ struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,mutex_lock (&host->syncpt_mutex); -for (i =0 ; i < host->info->nb_pts && sp->name; i++, sp++) +for (i =0 ; i < host->info->nb_pts &&kref_read (&sp->ref); i++, sp++) ;if (i >= host->info->nb_pts)
@@ -359,6 +359,11 @@ int host1x_syncpt_init(struct host1x *host)if (!host->nop_sp)return -ENOMEM ; +if (host->info->reserve_vblank_syncpts) { +kref_init (&host->syncpt[26 ].ref); +kref_init (&host->syncpt[27 ].ref); + } +return 0 ; }
@@ -545,3 +550,30 @@ u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base)return base->id; }EXPORT_SYMBOL (host1x_syncpt_base_id); + +static void do_nothing (struct kref *ref) +{ +} + +/** +* host1x_syncpt_release_vblank_reservation() - Make VBLANK syncpoint +* available for allocation +* +* @client: host1x bus client +* +* Makes VBLANK<i> syncpoint available for allocatation if it was +* reserved at initialization time. This should be called by the display +* driver after it has ensured that any VBLANK increment programming configured +* by the boot chain has been disabled. +*/ +void host1x_syncpt_release_vblank_reservation (struct host1x_client *client, +u32 syncpt_id) +{ +struct host1x *host =dev_get_drvdata (client->host->parent); + +if (!host->info->reserve_vblank_syncpts) +return ; + +kref_put (&host->syncpt[syncpt_id].ref, do_nothing); +} +EXPORT_SYMBOL (host1x_syncpt_release_vblank_reservation);
include/linux/host1x.h +3 -0
@@ -163,6 +163,9 @@ struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,struct host1x_syncpt_base *host1x_syncpt_get_base (struct host1x_syncpt *sp);u32 host1x_syncpt_base_id (struct host1x_syncpt_base *base); +void host1x_syncpt_release_vblank_reservation (struct host1x_client *client, +u32 syncpt_id); +struct host1x_syncpt *host1x_syncpt_fd_get (int fd);struct dma_fence *host1x_fence_create (struct host1x_syncpt *sp,u32 threshold);
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 15/20 drm/tegra: Add new UAPI to header
In reply to Mikko PerttunenUpdate the tegra_drm.h UAPI header, adding the new proposed UAPI. The old staging UAPI is left in for now, with minor modification to avoid name collisions.
---
v3:
* Remove timeout field
* Inline the syncpt_incrs array to the submit structure
* Remove WRITE_RELOC (it is now implicit)
--- include/uapi/drm/tegra_drm.h | 420 ++++++++++++++++++++++++++++++++--- 1 file changed, 393 insertions(+), 27 deletions(-)
include/uapi/drm/tegra_drm.h +393 -27
@@ -1,24 +1,5 @@ -/* -* Copyright (c) 2012-2013, NVIDIA CORPORATION. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR -* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -* OTHER DEALINGS IN THE SOFTWARE. -*/ +/* SPDX-License-Identifier: MIT */ +/* Copyright (c) 2012-2020 NVIDIA Corporation */ #ifndef _UAPI_TEGRA_DRM_H_#define _UAPI_TEGRA_DRM_H_
@@ -29,6 +10,8 @@extern "C" {#endif +/* TegraDRM legacy UAPI. Only enabled with STAGING */ +#define DRM_TEGRA_GEM_CREATE_TILED (1 << 0)#define DRM_TEGRA_GEM_CREATE_BOTTOM_UP (1 << 1)
@@ -644,13 +627,13 @@ struct drm_tegra_gem_get_flags {__u32 flags; }; -#define DRM_TEGRA_GEM_CREATE 0x00 -#define DRM_TEGRA_GEM_MMAP 0x01 +#define DRM_TEGRA_GEM_CREATE_LEGACY 0x00 +#define DRM_TEGRA_GEM_MMAP_LEGACY 0x01#define DRM_TEGRA_SYNCPT_READ 0x02#define DRM_TEGRA_SYNCPT_INCR 0x03#define DRM_TEGRA_SYNCPT_WAIT 0x04 -#define DRM_TEGRA_OPEN_CHANNEL 0x05 -#define DRM_TEGRA_CLOSE_CHANNEL 0x06 +#define DRM_TEGRA_OPEN_CHANNEL 0x05 +#define DRM_TEGRA_CLOSE_CHANNEL 0x06#define DRM_TEGRA_GET_SYNCPT 0x07#define DRM_TEGRA_SUBMIT 0x08#define DRM_TEGRA_GET_SYNCPT_BASE 0x09
@@ -659,8 +642,8 @@ struct drm_tegra_gem_get_flags {#define DRM_TEGRA_GEM_SET_FLAGS 0x0c#define DRM_TEGRA_GEM_GET_FLAGS 0x0d -#define DRM_IOCTL_TEGRA_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_CREATE, struct drm_tegra_gem_create) -#define DRM_IOCTL_TEGRA_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_MMAP, struct drm_tegra_gem_mmap) +#define DRM_IOCTL_TEGRA_GEM_CREATE_LEGACY DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_CREATE_LEGACY, struct drm_tegra_gem_create) +#define DRM_IOCTL_TEGRA_GEM_MMAP_LEGACY DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_MMAP_LEGACY, struct drm_tegra_gem_mmap)#define DRM_IOCTL_TEGRA_SYNCPT_READ DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_READ, struct drm_tegra_syncpt_read)#define DRM_IOCTL_TEGRA_SYNCPT_INCR DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_INCR, struct drm_tegra_syncpt_incr)#define DRM_IOCTL_TEGRA_SYNCPT_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_WAIT, struct drm_tegra_syncpt_wait)
@@ -674,6 +657,389 @@ struct drm_tegra_gem_get_flags {#define DRM_IOCTL_TEGRA_GEM_SET_FLAGS DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_SET_FLAGS, struct drm_tegra_gem_set_flags)#define DRM_IOCTL_TEGRA_GEM_GET_FLAGS DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_GET_FLAGS, struct drm_tegra_gem_get_flags) +/* New TegraDRM UAPI */ + +struct drm_tegra_channel_open { +/** +* @host1x_class: [in] +* +* Host1x class of the engine that will be programmed using this +* channel. +*/ +__u32 host1x_class; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +/** +* @channel_ctx: [out] +* +* Opaque identifier corresponding to the opened channel. +*/ +__u32 channel_ctx; + +/** +* @hardware_version: [out] +* +* Version of the engine hardware. This can be used by userspace +* to determine how the engine needs to be programmed. +*/ +__u32 hardware_version; + +__u32 reserved[2 ]; +}; + +struct drm_tegra_channel_close { +/** +* @channel_ctx: [in] +* +* Identifier of the channel to close. +*/ +__u32 channel_ctx; + +__u32 reserved[1 ]; +}; + +#define DRM_TEGRA_CHANNEL_MAP_READWRITE (1<<0) + +struct drm_tegra_channel_map { +/** +* @channel_ctx: [in] +* +* Identifier of the channel to which make memory available for. +*/ +__u32 channel_ctx; + +/** +* @handle: [in] +* +* GEM handle of the memory to map. +*/ +__u32 handle; + +/** +* @offset: [in] +* +* Offset in the GEM handle's underlying memory to start the +* mapping from. +*/ +__u64 offset; + +/** +* @length: [in] +* +* Length of memory to map. +*/ +__u64 length; + +/** +* @iova: [out] +* +* IOVA of mapped memory. Only available if hardware memory +* isolation is supported. If provided, userspace can program this +* address directly to the engine to skip using relocations. +* +* Will be set to U64_MAX if unavailable. +*/ +__u64 iova; + +/** +* @mapping_id: [out] +* +* Identifier corresponding to the mapping, to be used for +* relocations or unmapping later. +*/ +__u32 mapping_id; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +__u32 reserved[2 ]; +}; + +struct drm_tegra_channel_unmap { +/** +* @channel_ctx: [in] +* +* Channel identifier of the channel to unmap memory from. +*/ +__u32 channel_ctx; + +/** +* @mapping_id: [in] +* +* Mapping identifier of the memory mapping to unmap. +*/ +__u32 mapping_id; + +__u32 reserved[2 ]; +}; + +/* Submission */ + +/** +* Specify that bit 39 of the patched-in address should be set to +* trigger layout swizzling between Tegra and non-Tegra Blocklinear +* layout on systems that store surfaces in system memory in non-Tegra +* Blocklinear layout. +*/ +#define DRM_TEGRA_SUBMIT_BUF_RELOC_BLOCKLINEAR (1<<0) +/** +* Specify that any implicit fences required to read this buffer +* should be waited before executing the job. +*/ +#define DRM_TEGRA_SUBMIT_BUF_RESV_READ (1<<1) +/** +* Specify that any implicit fences required to write this buffer +* should be waited before executing the job. +*/ +#define DRM_TEGRA_SUBMIT_BUF_RESV_WRITE (1<<2) + +struct drm_tegra_submit_buf { +/** +* @mapping_id: [in] +* +* Identifier of the mapping to use in the submission. +*/ +__u32 mapping_id; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +/** +* Information for relocation patching. Relocation patching will +* be done if the MAP IOCTL that created `mapping_id` did not +* return an IOVA. If an IOVA was returned, the application is +* responsible for patching the address into the gather. +*/ +struct { +/** +* @target_offset: [in] +* +* Offset from the start of the mapping of the data whose +* address is to be patched into the gather. +*/ +__u64 target_offset; + +/** +* @gather_offset_words: [in] +* +* Offset in words from the start of the gather data to +* where the address should be patched into. +*/ +__u32 gather_offset_words; + +/** +* @shift: [in] +* +* Number of bits the address should be shifted right before +* patching in. +*/ +__u32 shift; + } reloc; + +__u32 reserved[2 ]; +}; + +#define DRM_TEGRA_SUBMIT_SYNCPT_INCR_CREATE_SYNC_FILE (1<<0) + +struct drm_tegra_submit_syncpt_incr { +/** +* @syncpt_fd: [in] +* +* Syncpoint file descriptor of the syncpoint that the job will +* increment. +*/ +__s32 syncpt_fd; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +/** +* @num_incrs: [in] +* +* Number of times the job will increment this syncpoint. +*/ +__u32 num_incrs; + +/** +* @fence_value: [out] +* +* Value the syncpoint will have once the job has completed all +* its specified syncpoint increments. +* +* Note that the kernel may increment the syncpoint before or after +* the job. These increments are not reflected in this field. +* +* If the job hangs or times out, not all of the increments may +* get executed. +*/ +__u32 fence_value; + +/** +* @sync_file_fd: [out] +* +* Created sync_file file descriptor corresponding to the threshold +* specified by `fence_value`. Only set if the CREATE_SYNC_FILE +* flag is specified. +*/ +__s32 sync_file_fd; + +__u32 reserved[3 ]; +}; + +/** +* Execute `words` words of Host1x opcodes specified in the `gather_data_ptr` +* buffer. Each GATHER_UPTR command uses successive words from the buffer. +*/ +#define DRM_TEGRA_SUBMIT_CMD_GATHER_UPTR 0 +/** +* Wait for a syncpoint to reach a value before continuing with further +* commands. +*/ +#define DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT 1 +/** +* Wait for the fence represented by the sync_file file descriptor to be +* signaled before continuing with further commands. This command may be +* executed before submission of the job to hardware. +*/ +#define DRM_TEGRA_SUBMIT_CMD_WAIT_SYNC_FILE 2 + +/** +* If set, the driver is allowed to skip execution of this command if +* the previous job executed by the engine was from the same channel +* context as this job. +*/ +#define DRM_TEGRA_SUBMIT_CONTEXT_SETUP (1<<0) + +struct drm_tegra_submit_cmd_gather_uptr { +__u32 words; +__u32 reserved[3 ]; +}; + +struct drm_tegra_submit_cmd_wait_syncpt { +__u32 id; +__u32 threshold; +__u32 reserved[2 ]; +}; + +struct drm_tegra_submit_cmd_wait_sync_file { +__s32 fd; +__u32 reserved[3 ]; +}; + +struct drm_tegra_submit_cmd { +/** +* @type: [in] +* +* Command type to execute. One of the DRM_TEGRA_SUBMIT_CMD* +* defines. +*/ +__u32 type; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +union { +struct drm_tegra_submit_cmd_gather_uptr gather_uptr; +struct drm_tegra_submit_cmd_wait_syncpt wait_syncpt; +struct drm_tegra_submit_cmd_wait_sync_file wait_sync_file; +__u32 reserved[4 ]; + }; +}; + +struct drm_tegra_channel_submit { +/** +* @channel_ctx: [in] +* +* Identifier of the channel to submit this job to. +*/ +__u32 channel_ctx; + +__u32 reserved0; + +/** +* @bufs_ptr: [in] +* +* Pointer to an array of drm_tegra_submit_buf structures. +*/ +__u64 bufs_ptr; + +/** +* @cmds_ptr: [in] +* +* Pointer to an array of drm_tegra_submit_cmd structures. +*/ +__u64 cmds_ptr; + +/** +* @gather_data_ptr: [in] +* +* Pointer to an array of Host1x opcodes to be used by GATHER_UPTR +* commands. +*/ +__u64 gather_data_ptr; + +/** +* @num_bufs: [in] +* +* Number of elements in the `bufs_ptr` array. +*/ +__u32 num_bufs; + +/** +* @num_cmds: [in] +* +* Number of elements in the `cmds_ptr` array. +*/ +__u32 num_cmds; + +/** +* @gather_data_words: [in] +* +* Number of 32-bit words in the `gather_data_ptr` array. +*/ +__u32 gather_data_words; + +__u32 reserved1; + +/** +* @syncpt_incrs: [in,out] +* +* Information about each distinct syncpoint the job will increment. +*/ +struct drm_tegra_submit_syncpt_incr syncpt_incrs[2 ]; +}; + +#define DRM_IOCTL_TEGRA_CHANNEL_OPEN DRM_IOWR(DRM_COMMAND_BASE + 0x10, struct drm_tegra_channel_open) +#define DRM_IOCTL_TEGRA_CHANNEL_CLOSE DRM_IOWR(DRM_COMMAND_BASE + 0x11, struct drm_tegra_channel_close) +#define DRM_IOCTL_TEGRA_CHANNEL_MAP DRM_IOWR(DRM_COMMAND_BASE + 0x12, struct drm_tegra_channel_map) +#define DRM_IOCTL_TEGRA_CHANNEL_UNMAP DRM_IOWR(DRM_COMMAND_BASE + 0x13, struct drm_tegra_channel_unmap) +#define DRM_IOCTL_TEGRA_CHANNEL_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + 0x14, struct drm_tegra_channel_submit) + +#define DRM_IOCTL_TEGRA_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + 0x15, struct drm_tegra_gem_create) +#define DRM_IOCTL_TEGRA_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + 0x16, struct drm_tegra_gem_mmap) +#if defined(__cplusplus) }#endif
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 16/20 drm/tegra: Boot VIC during runtime PM resume
In reply to Mikko PerttunenWith the new UAPI implementation, engines are powered on and off when there are active jobs, and the core code handles channel allocation. To accommodate that, boot the engine as part of runtime PM instead of using the open_channel callback, which is not used by the new submit path.
---
v3:
* runtime_get/put is now done directly from submit path, so no callbacks are added
* Reworded.
--- drivers/gpu/drm/tegra/vic.c | 114 +++++++++++++++++------------------- 1 file changed, 53 insertions(+), 61 deletions(-)
drivers/gpu/drm/tegra/vic.c +53 -61
@@ -29,7 +29,6 @@ struct vic_config {struct vic {struct falcon falcon; -bool booted;void __iomem *regs;struct tegra_drm_client client;
@@ -52,48 +51,6 @@ static void vic_writel(struct vic *vic, u32 value, unsigned int offset)writel (value, vic->regs + offset); } -static int vic_runtime_resume (struct device *dev) -{ -struct vic *vic =dev_get_drvdata (dev); -int err; - - err =clk_prepare_enable (vic->clk); -if (err <0 ) -return err; - -usleep_range (10 ,20 ); - - err =reset_control_deassert (vic->rst); -if (err <0 ) - goto disable; - -usleep_range (10 ,20 ); - -return 0 ; - -disable: -clk_disable_unprepare (vic->clk); -return err; -} - -static int vic_runtime_suspend (struct device *dev) -{ -struct vic *vic =dev_get_drvdata (dev); -int err; - - err =reset_control_assert (vic->rst); -if (err <0 ) -return err; - -usleep_range (2000 ,4000 ); - -clk_disable_unprepare (vic->clk); - - vic->booted = false; - -return 0 ; -} -static int vic_boot (struct vic *vic) {#ifdef CONFIG_IOMMU_API
@@ -103,9 +60,6 @@ static int vic_boot(struct vic *vic)void *hdr;int err =0 ; -if (vic->booted) -return 0 ; -#ifdef CONFIG_IOMMU_API if (vic->config->supports_sid && spec) {u32 value;
@@ -153,8 +107,6 @@ static int vic_boot(struct vic *vic)return err; } - vic->booted = true; -return 0 ; }
@@ -308,35 +260,76 @@ static int vic_load_firmware(struct vic *vic)return err; } -static int vic_open_channel (struct tegra_drm_client *client, -struct tegra_drm_context *context) + +static int vic_runtime_resume (struct device *dev) { -struct vic *vic =to_vic (client); +struct vic *vic =dev_get_drvdata (dev);int err; - err =pm_runtime_get_sync (vic->dev); + err =clk_prepare_enable (vic->clk);if (err <0 )return err; +usleep_range (10 ,20 ); + + err =reset_control_deassert (vic->rst); +if (err <0 ) + goto disable; + +usleep_range (10 ,20 ); + err =vic_load_firmware (vic);if (err <0 ) - goto rpm_put; + goto assert; err =vic_boot (vic);if (err <0 ) - goto rpm_put; + goto assert; + +return 0 ; + +assert: +reset_control_assert (vic->rst); +disable: +clk_disable_unprepare (vic->clk); +return err; +} + +static int vic_runtime_suspend (struct device *dev) +{ +struct vic *vic =dev_get_drvdata (dev); +int err; + + err =reset_control_assert (vic->rst); +if (err <0 ) +return err; + +usleep_range (2000 ,4000 ); + +clk_disable_unprepare (vic->clk); + +return 0 ; +} + +static int vic_open_channel (struct tegra_drm_client *client, +struct tegra_drm_context *context) +{ +struct vic *vic =to_vic (client); +int err; + + err =pm_runtime_get_sync (vic->dev); +if (err <0 ) { +pm_runtime_put (vic->dev); +return err; + } context->channel =host1x_channel_get (vic->channel);if (!context->channel) { - err = -ENOMEM ; - goto rpm_put; +pm_runtime_put (vic->dev); +return -ENOMEM ; }return 0 ; - -rpm_put: -pm_runtime_put (vic->dev); -return err; }static void vic_close_channel (struct tegra_drm_context *context)
@@ -344,7 +337,6 @@ static void vic_close_channel(struct tegra_drm_context *context)struct vic *vic =to_vic (context->client);host1x_channel_put (context->channel); -pm_runtime_put (vic->dev); }
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 17/20 drm/tegra: Set resv fields when importing/exporting GEMs
In reply to Mikko PerttunenTo allow sharing of implicit fences when exporting/importing dma_buf objects, set the 'resv' fields when importing or exporting GEM objects.
--- drivers/gpu/drm/tegra/gem.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/tegra/gem.c +2 -0
@@ -423,6 +423,7 @@ static struct tegra_bo *tegra_bo_import(struct drm_device *drm, } bo->gem.import_attach = attach; + bo->gem.resv = buf->resv;return bo;
@@ -675,6 +676,7 @@ struct dma_buf *tegra_gem_prime_export(struct drm_gem_object *gem, exp_info.size = gem->size; exp_info.flags = flags; exp_info.priv = gem; + exp_info.resv = gem->resv;return drm_gem_dmabuf_export (gem->dev, &exp_info); }
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 18/20 drm/tegra: Allocate per-engine channel in core code
In reply to Mikko PerttunenTo avoid duplication, allocate the per-engine shared channel in the core code instead. Once MLOCKs are implemented on Host1x side, we can also update this to avoid allocating a shared channel when MLOCKs are enabled.
--- drivers/gpu/drm/tegra/drm.c | 11 +++++++++++ drivers/gpu/drm/tegra/drm.h | 4 ++++ 2 files changed, 15 insertions(+)
drivers/gpu/drm/tegra/drm.c +11 -0
@@ -887,6 +887,14 @@ static struct drm_driver tegra_drm_driver = {int tegra_drm_register_client (struct tegra_drm *tegra,struct tegra_drm_client *client) { +/* +* When MLOCKs are implemented, change to allocate a shared channel +* only when MLOCKs are disabled. +*/ + client->shared_channel =host1x_channel_request (&client->base); +if (!client->shared_channel) +return -EBUSY ; +mutex_lock (&tegra->clients_lock);list_add_tail (&client->list, &tegra->clients); client->drm = tegra;
@@ -903,6 +911,9 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra, client->drm =NULL ;mutex_unlock (&tegra->clients_lock); +if (client->shared_channel) +host1x_channel_put (client->shared_channel); +return 0 ; }
drivers/gpu/drm/tegra/drm.h +4 -0
@@ -86,8 +86,12 @@ struct tegra_drm_client {struct list_head list;struct tegra_drm *drm; +/* Set by driver */ unsigned int version;const struct tegra_drm_client_ops *ops; + +/* Set by TegraDRM core */ +struct host1x_channel *shared_channel; }; static inline struct tegra_drm_client *
Signature · 1 line
2.28.0
Mikko Perttunen
maintainerPATCH v3 19/20 drm/tegra: Implement new UAPI
In reply to Mikko PerttunenImplement the new UAPI, and bump the TegraDRM major version.
---
v3:
* Remove WRITE_RELOC. Relocations are now patched implicitly when patching is needed.
* Directly call PM runtime APIs on devices instead of using power_on/power_off callbacks.
* Remove incorrect mutex unlock in tegra_drm_ioctl_channel_open
* Use XA_FLAGS_ALLOC1 instead of XA_FLAGS_ALLOC
* Accommodate for removal of timeout field and inlining of syncpt_incrs array.
* Copy entire user arrays at a time instead of going through elements one-by-one.
* Implement waiting of DMA reservations.
* Split out gather_bo implementation into a separate file.
* Fix length parameter passed to sg_init_one in gather_bo
* Cosmetic cleanup.
--- drivers/gpu/drm/tegra/Makefile | 3 + drivers/gpu/drm/tegra/drm.c | 46 +- drivers/gpu/drm/tegra/drm.h | 5 + drivers/gpu/drm/tegra/uapi.h | 63 +++ drivers/gpu/drm/tegra/uapi/gather_bo.c | 86 ++++ drivers/gpu/drm/tegra/uapi/gather_bo.h | 22 + drivers/gpu/drm/tegra/uapi/submit.c | 675 +++++++++++++++++++++++++ drivers/gpu/drm/tegra/uapi/submit.h | 17 + drivers/gpu/drm/tegra/uapi/uapi.c | 326 ++++++++++++ 9 files changed, 1225 insertions(+), 18 deletions(-) create mode 100644 drivers/gpu/drm/tegra/uapi.h create mode 100644 drivers/gpu/drm/tegra/uapi/gather_bo.c create mode 100644 drivers/gpu/drm/tegra/uapi/gather_bo.h create mode 100644 drivers/gpu/drm/tegra/uapi/submit.c create mode 100644 drivers/gpu/drm/tegra/uapi/submit.h create mode 100644 drivers/gpu/drm/tegra/uapi/uapi.c
drivers/gpu/drm/tegra/Makefile +3 -0
@@ -3,6 +3,9 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG tegra-drm-y := \ drm.o \ + uapi/uapi.o \ + uapi/submit.o \ + uapi/gather_bo.o \ gem.o \ fb.o \ dp.o \
drivers/gpu/drm/tegra/drm.c +28 -18
121 lines not on this page · raw message
drivers/gpu/drm/tegra/drm.h +5 -0
@@ -58,6 +58,11 @@ struct tegra_drm {struct tegra_display_hub *hub; }; +static inline struct host1x *tegra_drm_to_host1x (struct tegra_drm *tegra) +{ +return dev_get_drvdata (tegra->drm->dev->parent); +} +struct tegra_drm_client ;struct tegra_drm_context {
drivers/gpu/drm/tegra/uapi.h new file +63 -0
63 lines not on this page · raw message
drivers/gpu/drm/tegra/uapi/gather_bo.c new file +86 -0
86 lines not on this page · raw message
drivers/gpu/drm/tegra/uapi/gather_bo.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2020 NVIDIA Corporation */ + +#ifndef _TEGRA_DRM_SUBMIT_GATHER_BO_H +#define _TEGRA_DRM_SUBMIT_GATHER_BO_H + +#include <linux/host1x.h> +#include <linux/kref.h> + +struct gather_bo { +struct host1x_bo base; + +struct kref ref; + +u32 *gather_data; +size_t gather_data_words; +}; + +extern const struct host1x_bo_ops gather_bo_ops; +void gather_bo_put (struct host1x_bo *host_bo); + +#endif
drivers/gpu/drm/tegra/uapi/submit.c new file +675 -0
675 lines not on this page · raw message
drivers/gpu/drm/tegra/uapi/submit.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2020 NVIDIA Corporation */ + +#ifndef _TEGRA_DRM_UAPI_SUBMIT_H +#define _TEGRA_DRM_UAPI_SUBMIT_H + +struct tegra_drm_used_mapping { +struct tegra_drm_mapping *mapping; +u32 flags; +}; + +struct tegra_drm_submit_data { +struct tegra_drm_used_mapping *used_mappings; +u32 num_used_mappings; +}; + +#endif
drivers/gpu/drm/tegra/uapi/uapi.c new file +326 -0
326 lines not on this page · raw message
Signature · 1 line
2.28.0
kernel test robot
build botRe: [PATCH v3 19/20] drm/tegra: Implement new UAPI
Thank you for the patch! Yet something to improve:
Hi Mikko,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on tegra-drm/drm/tegra/for-next]
[also build test ERROR on tegra/for-next linus/master v5.9-rc8 next-20201007] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Mikko-Perttunen/Host1x-TegraDRM-UAPI/20201008-034403 base: git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next config: arm64-randconfig-r004-20201008 (attached as .config) compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/6a3b3d79ce4488695cc0745edd19015fc2220d97
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mikko-Perttunen/Host1x-TegraDRM-UAPI/20201008-034403 git checkout 6a3b3d79ce4488695cc0745edd19015fc2220d97
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
In file included from drivers/gpu/drm/tegra/uapi/uapi.c:12:
>> drivers/gpu/drm/tegra/uapi/../drm.h:84:1: error: attempted to randomize userland API struct tegra_drm_client_ops
84 | };
| ^
>> drivers/gpu/drm/tegra/uapi/uapi.c:62:5: warning: no previous prototype for 'close_channel_ctx' [-Wmissing-prototypes] 62 | int close_channel_ctx(int id, void *p, void *data)
| ^~~~~~~~~~~~~~~~~
--
In file included from drivers/gpu/drm/tegra/uapi/submit.c:18:
>> drivers/gpu/drm/tegra/uapi/../drm.h:84:1: error: attempted to randomize userland API struct tegra_drm_client_ops
84 | };
| ^vim +84 drivers/gpu/drm/tegra/uapi/../drm.h
d43f81cbaf4353 drivers/gpu/host1x/drm/drm.h Terje Bergstrom 2013-03-22 74
53fa7f7204c97d drivers/gpu/host1x/drm/drm.h Thierry Reding 2013-09-24 75 struct tegra_drm_client_ops {
53fa7f7204c97d drivers/gpu/host1x/drm/drm.h Thierry Reding 2013-09-24 76 int (*open_channel)(struct tegra_drm_client *client,
c88c363072c6dc drivers/gpu/host1x/drm/drm.h Thierry Reding 2013-09-26 77 struct tegra_drm_context *context);
c88c363072c6dc drivers/gpu/host1x/drm/drm.h Thierry Reding 2013-09-26 78 void (*close_channel)(struct tegra_drm_context *context);
c40f0f1afcb1dc drivers/gpu/drm/tegra/drm.h Thierry Reding 2013-10-10 79 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
0f563a4bf66e51 drivers/gpu/drm/tegra/drm.h Dmitry Osipenko 2017-06-15 80 int (*is_valid_class)(u32 class);
c88c363072c6dc drivers/gpu/host1x/drm/drm.h Thierry Reding 2013-09-26 81 int (*submit)(struct tegra_drm_context *context,
d43f81cbaf4353 drivers/gpu/host1x/drm/drm.h Terje Bergstrom 2013-03-22 82 struct drm_tegra_submit *args, struct drm_device *drm,
d43f81cbaf4353 drivers/gpu/host1x/drm/drm.h Terje Bergstrom 2013-03-22 83 struct drm_file *file);d43f81cbaf4353 drivers/gpu/host1x/drm/drm.h Terje Bergstrom 2013-03-22 @84 }; d43f81cbaf4353 drivers/gpu/host1x/drm/drm.h Terje Bergstrom 2013-03-22 85
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
In reply to Mikko Perttunen07.10.2020 20:12, Mikko Perttunen пишет:
drivers/gpu/drm/tegra/uapi/uapi.c line 164
Quoted 3 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +3
-0+int tegra_drm_ioctl_channel_map (struct drm_device *drm,void *data, +struct drm_file *file) +{
Hello, Mikko!
Could you please tell what are the host1x clients that are going to be upstreamed and will need this IOCTL?
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
Quoted 10 lines · Dmitry Osipenko
07.10.2020 20:12, Mikko Perttunen пишет:
drivers/gpu/drm/tegra/uapi/uapi.c line 164
Quoted 3 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +3
-0+int tegra_drm_ioctl_channel_map (struct drm_device *drm,void *data, +struct drm_file *file) +{Hello, Mikko!
Could you please tell what are the host1x clients that are going to be upstreamed and will need this IOCTL?
Hi Dmitry!
It is needed for any engine/job that wants to access memory, as this IOCTL must be used to map memory for the engine. So all of them.
Downstream doesn't have an equivalent IOCTL because it (currently) does mapping at submit time, but that is suboptimal because
- it requires doing relocations in the kernel which isn't required for T186+
- it's a big performance penalty, due to which the downstream kernel has the "deferred dma-buf unmapping" feature, where unmapping a dma_buf may not immediately unmap it in case it's used later, so that the "mapping" later is faster. A feature which we'd preferably get rid of.
- because of the above feature not being controlled by the user, it can cause variance in submit times.
On the other hand, we cannot (at least always) do the mapping at allocation/import time, because
- A single FD may have multiple channel_ctx's, and an allocation/import may need to be used in any subset of them
- The import IOCTL is fixed and doesn't have the parameters we'd need to do this at import time
- Overall it's more orthogonal to have GEM object acquirement in one step and mapping in another.
Maybe that's not quite what you asked, but it's some background anyway :)
Cheers,
Mikko
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
19.10.2020 11:13, Mikko Perttunen пишет:
Quoted 32 lines · Dmitry Osipenko
Quoted 10 lines
07.10.2020 20:12, Mikko Perttunen пишет:
drivers/gpu/drm/tegra/uapi/uapi.c line 164
Quoted 3 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +3
-0+int tegra_drm_ioctl_channel_map (struct drm_device *drm,void *data, + struct drm_file *file) +{Hello, Mikko!
Could you please tell what are the host1x clients that are going to be upstreamed and will need this IOCTL?
Hi Dmitry!
It is needed for any engine/job that wants to access memory, as this IOCTL must be used to map memory for the engine. So all of them.
Downstream doesn't have an equivalent IOCTL because it (currently) does mapping at submit time, but that is suboptimal because
- it requires doing relocations in the kernel which isn't required for T186+
- it's a big performance penalty, due to which the downstream kernel has the "deferred dma-buf unmapping" feature, where unmapping adma_bufmay not immediately unmap it in case it's used later, so that the "mapping" later is faster. A feature which we'd preferably get rid of.
- because of the above feature not being controlled by the user, it can cause variance in submit times.On the other hand, we cannot (at least always) do the mapping at allocation/import time, because
Quoted 8 lines
- A single FD may have multiple channel_ctx's, and an allocation/import may need to be used in any subset of them
- The import IOCTL is fixed and doesn't have the parameters we'd need to do this at import time
- Overall it's more orthogonal to have GEM object acquirement in one step and mapping in another.Maybe that's not quite what you asked, but it's some background anyway :)
I'm asking this question because right now there is only one potential client for this IOCTL, the VIC. If other clients aren't supposed to be a part of the DRM driver, like for example NVDEC which probably should be a V4L driver, then DRM driver will have only a single VIC and in this case we shouldn't need this IOCTL because DRM and V4L should use generic dmabuf API for importing and exporting buffers.
I'm also not quite sure about whether the current model of the unified Tegra DRM driver is suitable for having the separated engines. Perhaps each separated engine should just have its own rendering node?
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
Quoted 40 lines · Dmitry Osipenko
19.10.2020 11:13, Mikko Perttunen пишет:
Quoted 39 lines · Dmitry Osipenko
Quoted 10 lines
07.10.2020 20:12, Mikko Perttunen пишет:
drivers/gpu/drm/tegra/uapi/uapi.c line 164
Quoted 3 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +3
-0+int tegra_drm_ioctl_channel_map (struct drm_device *drm,void *data, + struct drm_file *file) +{Hello, Mikko!
Could you please tell what are the host1x clients that are going to be upstreamed and will need this IOCTL?
Hi Dmitry!
It is needed for any engine/job that wants to access memory, as this IOCTL must be used to map memory for the engine. So all of them.
Downstream doesn't have an equivalent IOCTL because it (currently) does mapping at submit time, but that is suboptimal because
- it requires doing relocations in the kernel which isn't required for T186+
- it's a big performance penalty, due to which the downstream kernel has the "deferred dma-buf unmapping" feature, where unmapping adma_bufmay not immediately unmap it in case it's used later, so that the "mapping" later is faster. A feature which we'd preferably get rid of.
- because of the above feature not being controlled by the user, it can cause variance in submit times.On the other hand, we cannot (at least always) do the mapping at allocation/import time, because
- A single FD may have multiple channel_ctx's, and an allocation/import may need to be used in any subset of them
- The import IOCTL is fixed and doesn't have the parameters we'd need to do this at import time
- Overall it's more orthogonal to have GEM object acquirement in one step and mapping in another.
Quoted 8 lines
Quoted 1 line
Maybe that's not quite what you asked, but it's some background anyway :)
I'm asking this question because right now there is only one potential client for this IOCTL, the VIC. If other clients aren't supposed to be a part of the DRM driver, like for example NVDEC which probably should be a V4L driver, then DRM driver will have only a single VIC and in this case we shouldn't need this IOCTL because DRM and V4L should use generic dmabuf API for importing and exporting buffers.
This IOCTL is required for GR2D/GR3D too, as they need to access memory as well. This is a different step from import/export -- first you import or allocate your memory so you have a GEM handle, then you map it to the channel, which does the IOMMU mapping (if there is an IOMMU).
Quoted 5 lines
I'm also not quite sure about whether the current model of the unified Tegra DRM driver is suitable for having the separated engines. Perhaps each separated engine should just have its own rendering node?
Yeah, having separate nodes per engine might be better, e.g. so it's easier to do access control. I don't have a strong opinion on that though.
Mikko
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
20.10.2020 12:18, Mikko Perttunen пишет:
Quoted 7 lines
Quoted 6 lines
I'm asking this question because right now there is only one potential client for this IOCTL, the VIC. If other clients aren't supposed to be a part of the DRM driver, like for example NVDEC which probably should be a V4L driver, then DRM driver will have only a single VIC and in this case we shouldn't need this IOCTL because DRM and V4L should use generic dmabuf API for importing and exporting buffers.
Quoted 5 lines
This IOCTL is required for GR2D/GR3D too, as they need to access memory as well. This is a different step from import/export -- first you import or allocate your memory so you have a GEM handle, then you map it to the channel, which does the IOMMU mapping (if there is an IOMMU).
This doesn't answer my question. I don't have a full picture and for now will remain dubious about this IOCTL, but it should be fine to have it in a form of WIP patches (maybe staging feature) until userspace code and hardware specs will become available.
Some more comments:
1. Older Tegra SoCs do not have restrictions which do not allow to group IOMMU as wished by kernel driver. It's fine to have one static mapping per-GEM that can be accessed by all DRM devices, that's why CHANNEL_MAP is questionable.
2. IIUC, the mappings need to be done per-device group/stream and not per-channel_ctx. It looks like nothing stops channel contexts to guess mapping addresses of the other context, isn't it?
I'm suggesting that each GEM should have a per-device mapping and the new IOCTL should create these GEM-mappings, instead of the channel_ctx mappings.
3. We shouldn't need channel contexts at all, a single "DRM file" context should be enough to have.
4. The new UAPI need to be separated into several parts in the next revision, one patch for each new feature.
The first patches should be the ones that are relevant to the existing userspace code, like support for the waits.
Partial mappings should be a separate feature because it's a questionable feature that needs to be proved by a real userspace first. Maybe it would be even better to drop it for the starter, to ease reviewing.
Waiting for fences on host1x should be a separate feature.
The syncfile support needs to be a separate feature as well because I don't see a use-case for it right now.
I'd like to see the DRM_SCHED and syncobj support. I can help you with it if it's out of yours scope for now.
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
Quoted 19 lines · Dmitry Osipenko
20.10.2020 12:18, Mikko Perttunen пишет:
Quoted 7 lines
Quoted 6 lines
I'm asking this question because right now there is only one potential client for this IOCTL, the VIC. If other clients aren't supposed to be a part of the DRM driver, like for example NVDEC which probably should be a V4L driver, then DRM driver will have only a single VIC and in this case we shouldn't need this IOCTL because DRM and V4L should use generic dmabuf API for importing and exporting buffers.
Quoted 5 lines
This IOCTL is required for GR2D/GR3D too, as they need to access memory as well. This is a different step from import/export -- first you import or allocate your memory so you have a GEM handle, then you map it to the channel, which does the IOMMU mapping (if there is an IOMMU).
This doesn't answer my question. I don't have a full picture and for now will remain dubious about this IOCTL, but it should be fine to have it in a form of WIP patches (maybe staging feature) until userspace code and hardware specs will become available.
Quoted 6 lines
Some more comments:
1. Older Tegra SoCs do not have restrictions which do not allow to group IOMMU as wished by kernel driver. It's fine to have one static mapping per-GEM that can be accessed by all DRM devices, that's why
CHANNEL_MAPis questionable.
Sure, on older Tegras this is not strictly necessary because the firewall can check pointers. It's not related to IOMMU grouping.
Quoted 8 lines
2. IIUC, the mappings need to be done per-device group/stream and not per-channel_ctx. It looks like nothing stops channel contexts to guess mapping addresses of the other context, isn't it?
I'm suggesting that each GEM should have a per-device mapping and the new IOCTL should create these GEM-mappings, instead of the
channel_ctxmappings.
In the absence of context isolation, this is correct. But with context isolation (which is next on my upstream todo-list), on supported chips (T186+), we can map to individual contexts, which are associated with channel_ctx's.
Without context isolation, this IOCTL just maps to the underlying engine. The list of mappings can also be used by the firewall later - as mentioned, just the relocs would be enough for that, but I think there's a good orthogonality in CHANNEL_MAP describing memory regions accessible by the engine, and relocations just doing relocations.
Quoted 3 lines
3. We shouldn't need channel contexts at all, a single "DRM file" context should be enough to have.
Yeah, maybe we could just have one "inline" channel context in the DRM file, that's just initialized by the CHANNEL_OPEN IOCTL.
Quoted 3 lines
4. The new UAPI need to be separated into several parts in the next revision, one patch for each new feature.
I'll try to split up where possible.
Quoted 3 lines
The first patches should be the ones that are relevant to the existing userspace code, like support for the waits.
Can you elaborate what you mean by this?
Quoted 4 lines
Partial mappings should be a separate feature because it's a questionable feature that needs to be proved by a real userspace first. Maybe it would be even better to drop it for the starter, to ease reviewing.
Considering that the "no-op" support for it (map the whole buffer but just keep track of the starting offset) is only a couple of lines, I'd like to keep it in.
Quoted 2 lines
Waiting for fences on host1x should be a separate feature.
OK.
Quoted 3 lines
The syncfile support needs to be a separate feature as well because I don't see a use-case for it right now.
I'll separate it - the reason it's there is to avoid the overhead of the extra ID/threshold -> sync_file conversion IOCTL if you need it.
Quoted 4 lines
I'd like to see the
DRM_SCHEDand syncobj support. I can help you with it if it's out of yours scope for now.
I already wrote some code for syncobj I can probably pull in. Regarding DRM_SCHED, help is accepted. However, we should keep using the hardware scheduler, and considering it's a bigger piece of work, let's not block this series on it.
Mikko
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
26.10.2020 12:11, Mikko Perttunen пишет:
Quoted 5 lines
Quoted 3 lines
The first patches should be the ones that are relevant to the existing userspace code, like support for the waits.
Can you elaborate what you mean by this?
All features that don't have an immediate real use-case should be placed later in the series because we may defer merging of those patches until we will see userspace that uses those features since we can't really decide whether these are decisions that we won't regret later on, only practical application can confirm the correctness.
Quoted 8 lines
Quoted 4 lines
Partial mappings should be a separate feature because it's a questionable feature that needs to be proved by a real userspace first. Maybe it would be even better to drop it for the starter, to ease reviewing.
Considering that the "no-op" support for it (map the whole buffer but just keep track of the starting offset) is only a couple of lines, I'd like to keep it in.
There is no tracking in the current code which prevents the duplicated mappings, will we need to care about it? This a bit too questionable feature for now, IMO. I'd like to see it as a separate patch.
...
Quoted 8 lines
Quoted 3 lines
I'd like to see the
DRM_SCHEDand syncobj support. I can help you with it if it's out of yours scope for now.I already wrote some code for syncobj I can probably pull in. Regarding
DRM_SCHED, help is accepted. However, we should keep using the hardware scheduler, and considering it's a bigger piece of work, let's not block this series on it.
I'd like to see all the custom IOCTLs to be deprecated and replaced with the generic DRM API wherever possible. Hence, I think it should be a mandatory features that we need to focus on. The current WIP userspace already uses and relies on DRM_SCHED.
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
Quoted 5 lines · Dmitry Osipenko
26.10.2020 12:11, Mikko Perttunen пишет:
Quoted 4 lines
Quoted 3 lines
The first patches should be the ones that are relevant to the existing userspace code, like support for the waits.
Quoted 7 lines
Quoted 1 line
Can you elaborate what you mean by this?
All features that don't have an immediate real use-case should be placed later in the series because we may defer merging of those patches until we will see userspace that uses those features since we can't really decide whether these are decisions that we won't regret later on, only practical application can confirm the correctness.
I was more referring to the "support for waits" part, should have clarified that.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Partial mappings should be a separate feature because it's a questionable feature that needs to be proved by a real userspace first. Maybe it would be even better to drop it for the starter, to ease reviewing.
Quoted 7 lines
Quoted 3 lines
Considering that the "no-op" support for it (map the whole buffer but just keep track of the starting offset) is only a couple of lines, I'd like to keep it in.
There is no tracking in the current code which prevents the duplicated mappings, will we need to care about it? This a bit too questionable feature for now, IMO. I'd like to see it as a separate patch.
I don't think there is any need to special case duplicated mappings. I think this is a pretty obvious feature to have, but I can rename them to reserved0 and reserved1 and require that reserved0 is zero and reserved1 is the size of the passed GEM object.
Quoted 11 lines
...
Quoted 8 lines
Quoted 3 lines
I'd like to see the
DRM_SCHEDand syncobj support. I can help you with it if it's out of yours scope for now.I already wrote some code for syncobj I can probably pull in. Regarding
DRM_SCHED, help is accepted. However, we should keep using the hardware scheduler, and considering it's a bigger piece of work, let's not block this series on it.
Quoted 5 lines
I'd like to see all the custom IOCTLs to be deprecated and replaced with the generic DRM API wherever possible. Hence, I think it should be a mandatory features that we need to focus on. The current WIP userspace already uses and relies on
DRM_SCHED.
From my point of view, the ABI needs to be designed such that it can replace what we have downstream, i.e. it needs to support the usecases the downstream nvhost ABI supports currently. Otherwise there is no migration path to upstream and it's not worth it for me to work on this.
Although, I don't see what this ABI is missing that your userspace would rely on. Does it submit jobs in reverse order that would deadlock if drm_sched didn't reorder them based on prefences, or something?
Software-based scheduling might make sense in situations where the channel is shared by all processes, but at least for modern chips that are designed to use hardware scheduling, I want to use that capability.
Mikko
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
28.10.2020 12:54, Mikko Perttunen пишет:
Quoted 8 lines · Dmitry Osipenko
Quoted 7 lines
26.10.2020 12:11, Mikko Perttunen пишет:
Quoted 5 lines
Quoted 3 lines
The first patches should be the ones that are relevant to the existing userspace code, like support for the waits.
Can you elaborate what you mean by this?
Quoted 8 lines
Quoted 5 lines
All features that don't have an immediate real use-case should be placed later in the series because we may defer merging of those patches until we will see userspace that uses those features since we can't really decide whether these are decisions that we won't regret later on, only practical application can confirm the correctness.
I was more referring to the "support for waits" part, should have clarified that.
The "support for waits" is support for the WAIT_SYNCPT command exposed to userspace, which we could utilize right now.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Partial mappings should be a separate feature because it's a questionable feature that needs to be proved by a real userspace first. Maybe it would be even better to drop it for the starter, to ease reviewing.
Considering that the "no-op" support for it (map the whole buffer but just keep track of the starting offset) is only a couple of lines, I'd like to keep it in.
Quoted 8 lines
Quoted 3 lines
There is no tracking in the current code which prevents the duplicated mappings, will we need to care about it? This a bit too questionable feature for now, IMO. I'd like to see it as a separate patch.
I don't think there is any need to special case duplicated mappings. I think this is a pretty obvious feature to have, but I can rename them to reserved0 and reserved1 and require that reserved0 is zero and reserved1 is the size of the passed GEM object.
I'm now concerned about the reserved fields after seeing this reply from Daniel Vetter:
https://www.mail-archive.com/[email protected]/msg36324.html
If DRM IOCTL structs are zero-extended, then perhaps we won't need to reserve anything?
Quoted 16 lines
Quoted 10 lines
...
Quoted 8 lines
Quoted 3 lines
I'd like to see the
DRM_SCHEDand syncobj support. I can help you with it if it's out of yours scope for now.I already wrote some code for syncobj I can probably pull in. Regarding
DRM_SCHED, help is accepted. However, we should keep using the hardware scheduler, and considering it's a bigger piece of work, let's not block this series on it.Quoted 5 lines
I'd like to see all the custom IOCTLs to be deprecated and replaced with the generic DRM API wherever possible. Hence, I think it should be a mandatory features that we need to focus on. The current WIP userspace already uses and relies on
DRM_SCHED.
Quoted 4 lines
From my point of view, the ABI needs to be designed such that it can replace what we have downstream, i.e. it needs to support the usecases the downstream nvhost ABI supports currently. Otherwise there is no migration path to upstream and it's not worth it for me to work on this.
The downstream needs should be irrelevant for the upstream, please read this:
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
It may happen that some of the downstream features could become useful for upstream, but we don't know until we will see the full userspace code.
We don't have a comprehensive userspace which could utilize all the new features and that's why upstream driver has been stagnated for many years now. The grate-drivers would greatly benefit from the updated ABI, but I think that we need at least a usable mesa driver first, that's why I haven't bothered to upstream anything from the WIP UAPI v2.
In order to upstream new UAPI features we will need:
1. Hardware specs (from vendor or reverse-engineered).
2. Regression tests.
3. A non-toy opensource userspace.
Quoted 3 lines
Although, I don't see what this ABI is missing that your userspace would rely on. Does it submit jobs in reverse order that would deadlock if
drm_scheddidn't reorder them based on prefences, or something?
It's the opposite, we don't have userspace which needs majority of the proposed ABI. This needs to be fixed before we could seriously consider merging the new features.
I'm pretty sure that you was already aware about all the upstreaming requirements and we will see the usable opensource userspace at some point, correct?
For now it will be good to have this series in a form of a work-in-progress patches, continuing to discuss and update it. Meanwhile we will need to work on the userspace part as well, which is a much bigger blocker.
Quoted 3 lines
Software-based scheduling might make sense in situations where the channel is shared by all processes, but at least for modern chips that are designed to use hardware scheduling, I want to use that capability.
The software-based scheduling is indeed needed for the older SoCs in order not to block hardware channels and job-submission code paths. Maybe it could become useful for a newer SoCs as well once we will get closer to a usable userspace :)
It will be great to have the hardware-based scheduling supported, but I assume that it needs to be done on top of DRM_SCHED. This should allow us to remove all the buggy host1x's pushbuffer locking code (which is known to deadlock) and support a non-host1x fences for free.
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
Quoted 39 lines · Dmitry Osipenko
28.10.2020 12:54, Mikko Perttunen пишет:
Quoted 8 lines · Dmitry Osipenko
Quoted 7 lines
26.10.2020 12:11, Mikko Perttunen пишет:
Quoted 5 lines
Quoted 3 lines
The first patches should be the ones that are relevant to the existing userspace code, like support for the waits.
Can you elaborate what you mean by this?
Quoted 8 lines
Quoted 5 lines
All features that don't have an immediate real use-case should be placed later in the series because we may defer merging of those patches until we will see userspace that uses those features since we can't really decide whether these are decisions that we won't regret later on, only practical application can confirm the correctness.
I was more referring to the "support for waits" part, should have clarified that.
The "support for waits" is support for the
WAIT_SYNCPTcommand exposed to userspace, which we could utilize right now.Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Partial mappings should be a separate feature because it's a questionable feature that needs to be proved by a real userspace first. Maybe it would be even better to drop it for the starter, to ease reviewing.
Considering that the "no-op" support for it (map the whole buffer but just keep track of the starting offset) is only a couple of lines, I'd like to keep it in.
Quoted 8 lines
Quoted 3 lines
There is no tracking in the current code which prevents the duplicated mappings, will we need to care about it? This a bit too questionable feature for now, IMO. I'd like to see it as a separate patch.
I don't think there is any need to special case duplicated mappings. I think this is a pretty obvious feature to have, but I can rename them to reserved0 and reserved1 and require that reserved0 is zero and reserved1 is the size of the passed GEM object.
Quoted 7 lines
I'm now concerned about the reserved fields after seeing this reply from Daniel Vetter:
https://www.mail-archive.com/[email protected]/msg36324.html
If DRM IOCTL structs are zero-extended, then perhaps we won't need to reserve anything?
I guess for the channel_map we can drop the offset/length, I just think it's fairly obvious that an IOMMU mapping API lets you specify from where and how much you want to map. Sure, it's not a functionality blocker as it can simply be implemented in userspace by shifting the reloc offset / IOVA equivalently, but it will reduce IO address space usage and prevent access to memory that was not intended to be mapped to the engine. The latter becomes a major PITA if you need to create safety documentation at this level -- don't know if this is relevant on Linux or not..
Quoted 45 lines
Quoted 17 lines
Quoted 11 lines
...
Quoted 8 lines
Quoted 3 lines
I'd like to see the
DRM_SCHEDand syncobj support. I can help you with it if it's out of yours scope for now.I already wrote some code for syncobj I can probably pull in. Regarding
DRM_SCHED, help is accepted. However, we should keep using the hardware scheduler, and considering it's a bigger piece of work, let's not block this series on it.Quoted 5 lines
I'd like to see all the custom IOCTLs to be deprecated and replaced with the generic DRM API wherever possible. Hence, I think it should be a mandatory features that we need to focus on. The current WIP userspace already uses and relies on
DRM_SCHED.Quoted 4 lines
From my point of view, the ABI needs to be designed such that it can
replace what we have downstream, i.e. it needs to support the usecases the downstream nvhost ABI supports currently. Otherwise there is no migration path to upstream and it's not worth it for me to work on this.The downstream needs should be irrelevant for the upstream, please read this:
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
It may happen that some of the downstream features could become useful for upstream, but we don't know until we will see the full userspace code.
We don't have a comprehensive userspace which could utilize all the new features and that's why upstream driver has been stagnated for many years now. The grate-drivers would greatly benefit from the updated ABI, but I think that we need at least a usable mesa driver first, that's why I haven't bothered to upstream anything from the WIP UAPI v2.
In order to upstream new UAPI features we will need:
1. Hardware specs (from vendor or reverse-engineered).
2. Regression tests.
3. A non-toy opensource userspace. >Quoted 3 lines
Although, I don't see what this ABI is missing that your userspace would rely on. Does it submit jobs in reverse order that would deadlock if
drm_scheddidn't reorder them based on prefences, or something?
Quoted 7 lines
It's the opposite, we don't have userspace which needs majority of the proposed ABI. This needs to be fixed before we could seriously consider merging the new features.
I'm pretty sure that you was already aware about all the upstreaming requirements and we will see the usable opensource userspace at some point, correct?
I am well aware of that. I'm not saying that we should copy the downstream stack. I am saying that when designing an ABI, we should consider all information available on what kind of features would be required from it.
Going through the proposed TegraDRM UAPI, there are some features that would probably not be immediately used by userspace, or supported in a non-NOOP fashion by the kernel:
* Map offset/length
* IOVA of mapping
* Creation of sync_file postfence
* Waiting for sync_file prefences
* SUBMIT_CONTEXT_SETUP flag
* Having two syncpt_incrs
* Reservations?
I suppose we can remove all of that for now, as long as we ensure that there is a path to add them back. I'm just a bit concerned that we'll end up with 10 different ABI revisions and userspace will have to do a version detection dance and enable things depending on driver version.
Anything else to remove?
Regarding things like explicit channel_map, sure, we could map things implicitly at submit time, but it is a huge performance improvement on newer chips, at least. So technically userspace doesn't need it, but going by that argument, we can get rid of a lot of kernel functionality -- after all, it's only needed if you want your hardware to perform well.
Quoted 5 lines
For now it will be good to have this series in a form of a work-in-progress patches, continuing to discuss and update it. Meanwhile we will need to work on the userspace part as well, which is a much bigger blocker.
I'm hoping that porting the userspace won't take that long. It shouldn't be that big of a hurdle.
Quoted 9 lines
Quoted 4 lines
Software-based scheduling might make sense in situations where the channel is shared by all processes, but at least for modern chips that are designed to use hardware scheduling, I want to use that capability.
The software-based scheduling is indeed needed for the older SoCs in order not to block hardware channels and job-submission code paths. Maybe it could become useful for a newer SoCs as well once we will get closer to a usable userspace :)
Considering that many products were successfully shipped without software-based scheduling, I wouldn't consider it "needed".
Quoted 6 lines
It will be great to have the hardware-based scheduling supported, but I assume that it needs to be done on top of
DRM_SCHED. This should allow us to remove all the buggy host1x's pushbuffer locking code (which is known to deadlock) and support a non-host1x fences for free.
If it is known to deadlock, we should fix it. In any case, which kind of scheduler is used shouldn't affect the ABI, and we already have a functional implemention in the Host1x driver, so we should merge the ABI first rather than wait for another year while the rest of the driver is redesigned and rewritten.
Mikko
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
09.11.2020 17:53, Mikko Perttunen пишет:
...
Quoted 7 lines
I guess for the
channel_mapwe can drop the offset/length, I just think it's fairly obvious that an IOMMU mapping API lets you specify from where and how much you want to map. Sure, it's not a functionality blocker as it can simply be implemented in userspace by shifting the reloc offset / IOVA equivalently, but it will reduce IO address space usage and prevent access to memory that was not intended to be mapped to the engine.
It could be a good feature, but I'd want to see how userspace will benefit from using it in practice before putting effort into it.
Could you please give examples of how this feature will be useful for userspace? What is the use-case for allocating a single buffer and then mapping it partially? Is this needed for a userspace memory pool or something else?
...
Quoted 16 lines
I am well aware of that. I'm not saying that we should copy the downstream stack. I am saying that when designing an ABI, we should consider all information available on what kind of features would be required from it.
Going through the proposed TegraDRM UAPI, there are some features that would probably not be immediately used by userspace, or supported in a non-NOOP fashion by the kernel:
* Map offset/length
* IOVA of mapping
* Creation ofsync_filepostfence
* Waiting forsync_fileprefences
*SUBMIT_CONTEXT_SETUPflag
* Having twosyncpt_incrs
* Reservations?
Quoted 6 lines
I suppose we can remove all of that for now, as long as we ensure that there is a path to add them back. I'm just a bit concerned that we'll end up with 10 different ABI revisions and userspace will have to do a version detection dance and enable things depending on driver version.
Anything else to remove?
I guess it should be enough for now.
Reservations are needed for the grate drivers, but they need to be done in conjunction with the DRM scheduler. I guess it should be fine if you'll remove reservations, I'll then take a look at how to integrate them and drm-sched on top of yours changes.
Quoted 5 lines
Regarding things like explicit
channel_map, sure, we could map things implicitly at submit time, but it is a huge performance improvement on newer chips, at least. So technically userspace doesn't need it, but going by that argument, we can get rid of a lot of kernel functionality -- after all, it's only needed if you want your hardware to perform well.
I have no doubt that it's better to have static mappings, but it's not obvious how it should be implemented without seeing a full picture. I mean that maybe it could be possible to avoid having these special IOCTLs by changing the way of how hardware is exposed to userspace such that generic UAPI could be used in order to achieve the same goals.
...
Quoted 5 lines
If it is known to deadlock, we should fix it. In any case, which kind of scheduler is used shouldn't affect the ABI, and we already have a functional implemention in the Host1x driver, so we should merge the ABI first rather than wait for another year while the rest of the driver is redesigned and rewritten.
Perhaps should be fine to start extending the ABI, but then it should stay under DRM_TEGRA_STAGING until we will be confident that it's all good.
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
In reply to Dmitry OsipenkoQuoted 41 lines · Dmitry Osipenko
19.10.2020 11:13, Mikko Perttunen пишет:
Quoted 39 lines · Dmitry Osipenko
Quoted 10 lines
07.10.2020 20:12, Mikko Perttunen пишет:
drivers/gpu/drm/tegra/uapi/uapi.c line 164
Quoted 3 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +3
-0+int tegra_drm_ioctl_channel_map (struct drm_device *drm,void *data, +struct drm_file *file) +{Hello, Mikko!
Could you please tell what are the host1x clients that are going to be upstreamed and will need this IOCTL?
Hi Dmitry!
It is needed for any engine/job that wants to access memory, as this IOCTL must be used to map memory for the engine. So all of them.
Downstream doesn't have an equivalent IOCTL because it (currently) does mapping at submit time, but that is suboptimal because
- it requires doing relocations in the kernel which isn't required for T186+
- it's a big performance penalty, due to which the downstream kernel has the "deferred dma-buf unmapping" feature, where unmapping adma_bufmay not immediately unmap it in case it's used later, so that the "mapping" later is faster. A feature which we'd preferably get rid of.
- because of the above feature not being controlled by the user, it can cause variance in submit times.On the other hand, we cannot (at least always) do the mapping at allocation/import time, because
- A single FD may have multiple channel_ctx's, and an allocation/import may need to be used in any subset of them
- The import IOCTL is fixed and doesn't have the parameters we'd need to do this at import time
- Overall it's more orthogonal to have GEM object acquirement in one step and mapping in another.
Quoted 8 lines
Quoted 1 line
Maybe that's not quite what you asked, but it's some background anyway :)
I'm asking this question because right now there is only one potential client for this IOCTL, the VIC. If other clients aren't supposed to be a part of the DRM driver, like for example NVDEC which probably should be a V4L driver, then DRM driver will have only a single VIC and in this case we shouldn't need this IOCTL because DRM and V4L should use generic dmabuf API for importing and exporting buffers.
Randomly jumping in here ...
So if you have a drm driver with userspace in mesa3d already, the usual approach is to have a libva implementation (ideally in mesa3d too, using the gallium framework so that a lot of the boring integration glue is taken care of already) directly on top of drm. No v4l driver needed at all here.
And it sounds like this nvdec thing would fit that bill pretty neatly.
Quoted 3 lines
I'm also not quite sure about whether the current model of the unified Tegra DRM driver is suitable for having the separated engines. Perhaps each separated engine should just have its own rendering node?
Above model using libva driver in userspace for nvdec would avoid this issue too.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 19/20] drm/tegra: Implement new UAPI
Quoted 53 lines · Daniel Vetter
Quoted 41 lines · Dmitry Osipenko
19.10.2020 11:13, Mikko Perttunen пишет:
Quoted 39 lines · Dmitry Osipenko
Quoted 10 lines
07.10.2020 20:12, Mikko Perttunen пишет:
drivers/gpu/drm/tegra/uapi/uapi.c line 164
Quoted 3 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +3
-0+int tegra_drm_ioctl_channel_map (struct drm_device *drm,void *data, +struct drm_file *file) +{Hello, Mikko!
Could you please tell what are the host1x clients that are going to be upstreamed and will need this IOCTL?
Hi Dmitry!
It is needed for any engine/job that wants to access memory, as this IOCTL must be used to map memory for the engine. So all of them.
Downstream doesn't have an equivalent IOCTL because it (currently) does mapping at submit time, but that is suboptimal because
- it requires doing relocations in the kernel which isn't required for T186+
- it's a big performance penalty, due to which the downstream kernel has the "deferred dma-buf unmapping" feature, where unmapping adma_bufmay not immediately unmap it in case it's used later, so that the "mapping" later is faster. A feature which we'd preferably get rid of.
- because of the above feature not being controlled by the user, it can cause variance in submit times.On the other hand, we cannot (at least always) do the mapping at allocation/import time, because
- A single FD may have multiple channel_ctx's, and an allocation/import may need to be used in any subset of them
- The import IOCTL is fixed and doesn't have the parameters we'd need to do this at import time
- Overall it's more orthogonal to have GEM object acquirement in one step and mapping in another.Quoted 8 lines
Quoted 1 line
Maybe that's not quite what you asked, but it's some background anyway :)
I'm asking this question because right now there is only one potential client for this IOCTL, the VIC. If other clients aren't supposed to be a part of the DRM driver, like for example NVDEC which probably should be a V4L driver, then DRM driver will have only a single VIC and in this case we shouldn't need this IOCTL because DRM and V4L should use generic dmabuf API for importing and exporting buffers.
Randomly jumping in here ...
Quoted 7 lines
So if you have a drm driver with userspace in mesa3d already, the usual approach is to have a libva implementation (ideally in mesa3d too, using the gallium framework so that a lot of the boring integration glue is taken care of already) directly on top of drm. No v4l driver needed at all here.
And it sounds like this nvdec thing would fit that bill pretty neatly.
Something like this would be my preference as well.
Mikko
Quoted 9 lines
Quoted 4 lines
I'm also not quite sure about whether the current model of the unified Tegra DRM driver is suitable for having the separated engines. Perhaps each separated engine should just have its own rendering node?
Above model using libva driver in userspace for nvdec would avoid this issue too.
-Daniel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Mikko Perttunen
maintainerPATCH v3 20/20 drm/tegra: Add job firewall
In reply to Mikko PerttunenAdd a firewall that validates jobs before submission to ensure they don't do anything they aren't allowed to do, like accessing memory they should not access.
The firewall is functionality-wise a copy of the firewall already implemented in gpu/host1x. It is copied here as it makes more sense for it to live on the DRM side, as it is only needed for userspace job submissions, and generally the data it needs to do its job is easier to access here.
In the future, the other implementation will be removed.
---
v3:
* New patch
--- drivers/gpu/drm/tegra/Makefile | 1 + drivers/gpu/drm/tegra/uapi/firewall.c | 197 ++++++++++++++++++++++++++ drivers/gpu/drm/tegra/uapi/submit.c | 4 + drivers/gpu/drm/tegra/uapi/submit.h | 3 + 4 files changed, 205 insertions(+) create mode 100644 drivers/gpu/drm/tegra/uapi/firewall.c
drivers/gpu/drm/tegra/Makefile +1 -0
@@ -5,6 +5,7 @@ tegra-drm-y := \ drm.o \ uapi/uapi.o \ uapi/submit.o \ + uapi/firewall.o \ uapi/gather_bo.o \ gem.o \ fb.o \
drivers/gpu/drm/tegra/uapi/firewall.c new file +197 -0
197 lines not on this page · raw message
drivers/gpu/drm/tegra/uapi/submit.c +4 -0
@@ -360,6 +360,10 @@ static int submit_job_add_gather(struct host1x_job *job,if (next_offset > bo->gather_data_words)return -EINVAL ; +if (tegra_drm_fw_validate (ctx->client, bo->gather_data, *offset, + cmd->words, job_data)) +return -EINVAL ; +host1x_job_add_gather (job, &bo->base, cmd->words, *offset *4 ); *offset = next_offset;
drivers/gpu/drm/tegra/uapi/submit.h +3 -0
@@ -14,4 +14,7 @@ struct tegra_drm_submit_data { u32 num_used_mappings; }; +int tegra_drm_fw_validate (struct tegra_drm_client *client,u32 *data,u32 start, +u32 words,struct tegra_drm_submit_data *submit); +#endif
Signature · 1 line
2.28.0