TegraDRM UAPI
Mikko Perttunen
maintainerv6 cover TegraDRM UAPI
Hi all,
here's the sixth revision of the TegraDRM UAPI proposal. The biggest change is the removal of the /dev/host1x device. Syncpoints are now allocated directly through the TegraDRM API. Direct userspace fence interfaces have been removed as there is currently no upstream use for them. Otherwise, there's a whole lot of smaller fixes and cosmetic improvements.
Some previously discussed items that are not (fully) implemented here:
- Per-job syncpoint allocation - this is easy to add in afterwards in a backwards compatible manner, so I left it out. I have prototyped it locally in case we need it.
- Full support for syncobjs - currently only two syncobjs are taken, one in and one out, as currently there is no userspace that would need more than that, and it is also relatively easy to extend.
- Constructing jobs in a non-CDMA pushbuffer. This should not cause any UAPI changes and will require further design work.
The following pieces of userspace have been updated to support this revision of the UAPI:
* vaapi-tegra-driver - https://github.com/cyndis/vaapi-tegra-driver
Experimental support for MPEG2 and H264 decoding on T210, T186 and T194.
* xf86-video-opentegra - https://github.com/grate-driver/xf86-video-opentegra
X11 userspace acceleration driver for Tegra20, Tegra30, and Tegra114.
* grate - https://github.com/grate-driver/grate
3D rendering testbed for Tegra20, Tegra30, and Tegra114
The series can be also found in
https://github.com/cyndis/linux/commits/work/tegradrm-v6.
Older versions:
v1: https://www.spinics.net/lists/linux-tegra/msg51000.html
v2: https://www.spinics.net/lists/linux-tegra/msg53061.html
v3: https://www.spinics.net/lists/linux-tegra/msg54370.html
v4: https://www.spinics.net/lists/dri-devel/msg279897.html
v5: https://www.spinics.net/lists/linux-tegra/msg56353.html
Thank you,
Mikko
Mikko Perttunen (14):
gpu: host1x: Add DMA fence implementation
gpu: host1x: Add no-recovery mode
gpu: host1x: Add job release callback
gpu: host1x: Add support for syncpoint waits in CDMA pushbuffer drm/tegra: Extract tegra_gem_lookup
drm/tegra: Add new UAPI to header
drm/tegra: Boot VIC during runtime PM resume drm/tegra: Allocate per-engine channel in core code drm/tegra: Implement new UAPI
drm/tegra: Implement syncpoint management UAPI drm/tegra: Implement syncpoint wait UAPI
drm/tegra: Implement job submission part of new UAPI drm/tegra: Add job firewall
drm/tegra: Bump driver version
drivers/gpu/drm/tegra/Makefile | 4 + drivers/gpu/drm/tegra/drm.c | 82 +-- drivers/gpu/drm/tegra/drm.h | 12 + drivers/gpu/drm/tegra/firewall.c | 254 ++++++++++ drivers/gpu/drm/tegra/gather_bo.c | 81 +++ drivers/gpu/drm/tegra/gather_bo.h | 22 + drivers/gpu/drm/tegra/gem.c | 13 + drivers/gpu/drm/tegra/gem.h | 2 + drivers/gpu/drm/tegra/submit.c | 549 +++++++++++++++++++++ drivers/gpu/drm/tegra/submit.h | 21 + drivers/gpu/drm/tegra/uapi.c | 374 ++++++++++++++ drivers/gpu/drm/tegra/uapi.h | 58 +++ drivers/gpu/drm/tegra/vic.c | 112 ++--- drivers/gpu/host1x/Makefile | 1 + drivers/gpu/host1x/cdma.c | 58 ++- drivers/gpu/host1x/fence.c | 211 ++++++++ drivers/gpu/host1x/fence.h | 13 + drivers/gpu/host1x/hw/channel_hw.c | 87 +++- drivers/gpu/host1x/hw/debug_hw.c | 9 +- drivers/gpu/host1x/hw/hw_host1x02_uclass.h | 12 + drivers/gpu/host1x/hw/hw_host1x04_uclass.h | 12 + drivers/gpu/host1x/hw/hw_host1x05_uclass.h | 12 + drivers/gpu/host1x/hw/hw_host1x06_uclass.h | 12 + drivers/gpu/host1x/hw/hw_host1x07_uclass.h | 12 + drivers/gpu/host1x/intr.c | 9 + drivers/gpu/host1x/intr.h | 2 + drivers/gpu/host1x/job.c | 77 ++- drivers/gpu/host1x/job.h | 16 + drivers/gpu/host1x/syncpt.c | 2 + drivers/gpu/host1x/syncpt.h | 12 + include/linux/host1x.h | 22 +- include/uapi/drm/tegra_drm.h | 414 +++++++++++++++- 32 files changed, 2408 insertions(+), 169 deletions(-) create mode 100644 drivers/gpu/drm/tegra/firewall.c create mode 100644 drivers/gpu/drm/tegra/gather_bo.c create mode 100644 drivers/gpu/drm/tegra/gather_bo.h create mode 100644 drivers/gpu/drm/tegra/submit.c create mode 100644 drivers/gpu/drm/tegra/submit.h create mode 100644 drivers/gpu/drm/tegra/uapi.c create mode 100644 drivers/gpu/drm/tegra/uapi.h create mode 100644 drivers/gpu/host1x/fence.c create mode 100644 drivers/gpu/host1x/fence.h
Signature · 1 line
2.30.1
Mikko Perttunen
maintainerPATCH v6 1/14 gpu: host1x: Add DMA fence implementation
Add 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. The timeout can potentially be removed in the future after job tracking code has been refactored.
---
v6:
* Removed userspace interface.
* Add host1x_ prefixes in various places.
v5:
* Update for change in put_ref prototype.
v4:
* Fix _signal prototype and include it to avoid warning
* Remove use of unused local in error path
v3:
* Move declaration of host1x_fence_extract to public header
--- drivers/gpu/host1x/Makefile | 1 + drivers/gpu/host1x/fence.c | 211 ++++++++++++++++++++++++++++++++++++ drivers/gpu/host1x/fence.h | 13 +++ drivers/gpu/host1x/intr.c | 9 ++ drivers/gpu/host1x/intr.h | 2 + include/linux/host1x.h | 3 + 6 files changed, 239 insertions(+) create mode 100644 drivers/gpu/host1x/fence.c create mode 100644 drivers/gpu/host1x/fence.h
drivers/gpu/host1x/Makefile +1 -0
@@ -9,6 +9,7 @@ host1x-y = \ job.o \ debug.o \ mipi.o \ + fence.o \ hw/host1x01.o \ hw/host1x02.o \ hw/host1x04.o \
drivers/gpu/host1x/fence.c new file +211 -0
211 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 ; + +void 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 };
include/linux/host1x.h +3 -0
@@ -166,6 +166,9 @@ u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);void host1x_syncpt_release_vblank_reservation (struct host1x_client *client,u32 syncpt_id); +struct dma_fence *host1x_fence_create (struct host1x_syncpt *sp,u32 threshold); +int host1x_fence_extract (struct dma_fence *fence,u32 *id,u32 *threshold); +/* * host1x channel */
Signature · 1 line
2.30.1
kernel test robot
build botRe: [PATCH v6 01/14] gpu: host1x: Add DMA fence implementation
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 v5.13-rc3 next-20210528]
[cannot apply to tegra/for-next]
[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/TegraDRM-UAPI/20210530-205239 base: git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next config: arm-randconfig-r015-20210530 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project bc6799f2f79f0ae87e9f1ebf9d25ba799fbd25a9)
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 arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/0day-ci/linux/commit/5de49ce9211cbf0fbbfeb200e72ce934f4574d4b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mikko-Perttunen/TegraDRM-UAPI/20210530-205239 git checkout 5de49ce9211cbf0fbbfeb200e72ce934f4574d4b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpu/host1x/fence.c:170:5: warning: no previous prototype for function 'host1x_fence_create_fd' [-Wmissing-prototypes]
int host1x_fence_create_fd(struct host1x_syncpt *sp, u32 threshold)
^ drivers/gpu/host1x/fence.c:170:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int host1x_fence_create_fd(struct host1x_syncpt *sp, u32 threshold)
^
static
1 warning generated.
vim +/host1x_fence_create_fd +170 drivers/gpu/host1x/fence.c
169
> 170 int host1x_fence_create_fd(struct host1x_syncpt *sp, u32 threshold)
171 {
172 struct sync_file *file;
173 struct dma_fence *f;
174 int fd;
175
176 f = host1x_fence_create(sp, threshold);
177 if (IS_ERR(f))
178 return PTR_ERR(f);
179
180 fd = get_unused_fd_flags(O_CLOEXEC);
181 if (fd < 0) {
182 dma_fence_put(f);
183 return fd;
184 }
185
186 file = sync_file_create(f);
187 dma_fence_put(f);
188 if (!file)
189 return -ENOMEM;
190
191 fd_install(fd, file->file);
192
193 return fd;
194 }
195 EXPORT_SYMBOL(host1x_fence_create_fd);
196
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Mikko Perttunen
maintainerPATCH v6 2/14 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.
---
v5:
* Update for change in put_ref prototype.
* Fixed typo in comment.
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
@@ -200,6 +200,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, false); +if (job->syncpt)host1x_syncpt_put (job->syncpt);
drivers/gpu/host1x/syncpt.c +2 -0
@@ -407,6 +407,8 @@ static void syncpt_release(struct kref *ref)atomic_set (&sp->max_val,host1x_syncpt_read (sp)); + 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.30.1
Mikko Perttunen
maintainerPATCH v6 3/14 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, false);
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.30.1
Mikko Perttunen
maintainerPATCH v6 4/14 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.
Also supported are waits relative to the start of the job, which are useful for jobs doing multiple things with an engine that doesn't natively support pipelining.
While at it, use 32-bit waits on chips that support them.
---
v6:
- Change into specified class after wait
- Support waits relative to start of job
- Support 32-bit waits
--- drivers/gpu/host1x/hw/channel_hw.c | 85 +++++++++++++++++----- drivers/gpu/host1x/hw/debug_hw.c | 9 ++- drivers/gpu/host1x/hw/hw_host1x02_uclass.h | 12 +++ drivers/gpu/host1x/hw/hw_host1x04_uclass.h | 12 +++ drivers/gpu/host1x/hw/hw_host1x05_uclass.h | 12 +++ drivers/gpu/host1x/hw/hw_host1x06_uclass.h | 12 +++ drivers/gpu/host1x/hw/hw_host1x07_uclass.h | 12 +++ drivers/gpu/host1x/job.c | 70 +++++++++++++----- drivers/gpu/host1x/job.h | 16 ++++ include/linux/host1x.h | 6 +- 10 files changed, 203 insertions(+), 43 deletions(-)
drivers/gpu/host1x/hw/channel_hw.c +65 -20
@@ -47,39 +47,84 @@ static void trace_write_gather(struct host1x_cdma *cdma, struct host1x_bo *bo, } } -static void submit_gathers (struct host1x_job *job) +static void submit_wait (struct host1x_cdma *cdma,u32 id,u32 threshold, +u32 next_class) +{ +#if HOST1X_HW >=2 +host1x_cdma_push_wide (cdma, +host1x_opcode_setclass ( +HOST1X_CLASS_HOST1X , +HOST1X_UCLASS_LOAD_SYNCPT_PAYLOAD_32 , +/* WAIT_SYNCPT_32 is at SYNCPT_PAYLOAD_32+2 */ +BIT (0 ) |BIT (2 ) + ), + threshold, + id, +host1x_opcode_setclass (next_class,0 ,0 ) + ); +#else +/* TODO add waitchk or use waitbases or other mitigation */ +host1x_cdma_push (cdma, +host1x_opcode_setclass ( +HOST1X_CLASS_HOST1X , +host1x_uclass_wait_syncpt_r (), +BIT (0 ) + ), +host1x_class_host_wait_syncpt (id, threshold) + ); +host1x_cdma_push (cdma, +host1x_opcode_setclass (next_class,0 ,0 ), +HOST1X_OPCODE_NOP + ); +#endif +} + +static void submit_gathers (struct host1x_job *job,u32 job_syncpt_base) {struct host1x_cdma *cdma = &job->channel->cdma;#if HOST1X_HW <6 struct device *dev = job->channel->dev;#endif unsigned int i; +u32 threshold; -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) { +if (cmd->wait.relative) + threshold = job_syncpt_base + cmd->wait.threshold; +else + threshold = cmd->wait.threshold; -trace_write_gather (cdma, g->bo, g->offset, g->words); +submit_wait (cdma, cmd->wait.id, threshold, cmd->wait.next_class); + }else { +struct host1x_job_gather *g = &cmd->gather; + +dma_addr_t addr = g->base + g->offset; +u32 op2, op3; + + op2 =lower_32_bits (addr); + op3 =upper_32_bits (addr); -if (op3 !=0 ) { +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 +171,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 */
@@ -181,7 +226,7 @@ static int channel_submit(struct host1x_job *job)host1x_opcode_setclass (job->class,0 ,0 ), HOST1X_OPCODE_NOP); -submit_gathers (job); +submit_gathers (job, syncval - user_syncpt_incrs);/* end CDMA submit & stash pinned hMems into sync queue */ host1x_cdma_end (&ch->cdma, job);
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/hw/hw_host1x02_uclass.h +12 -0
@@ -165,5 +165,17 @@ static inline u32 host1x_uclass_indoff_rwn_read_v(void) }#define HOST1X_UCLASS_INDOFF_INDROFFSET_F (v) \ host1x_uclass_indoff_indroffset_f(v) +static inline u32 host1x_uclass_load_syncpt_payload_32_r (void ) +{ +return 0x4e ; +} +#define HOST1X_UCLASS_LOAD_SYNCPT_PAYLOAD_32 \ + host1x_uclass_load_syncpt_payload_32_r() +static inline u32 host1x_uclass_wait_syncpt_32_r (void ) +{ +return 0x50 ; +} +#define HOST1X_UCLASS_WAIT_SYNCPT_32 \ + host1x_uclass_wait_syncpt_32_r()#endif
drivers/gpu/host1x/hw/hw_host1x04_uclass.h +12 -0
@@ -165,5 +165,17 @@ static inline u32 host1x_uclass_indoff_rwn_read_v(void) }#define HOST1X_UCLASS_INDOFF_INDROFFSET_F (v) \ host1x_uclass_indoff_indroffset_f(v) +static inline u32 host1x_uclass_load_syncpt_payload_32_r (void ) +{ +return 0x4e ; +} +#define HOST1X_UCLASS_LOAD_SYNCPT_PAYLOAD_32 \ + host1x_uclass_load_syncpt_payload_32_r() +static inline u32 host1x_uclass_wait_syncpt_32_r (void ) +{ +return 0x50 ; +} +#define HOST1X_UCLASS_WAIT_SYNCPT_32 \ + host1x_uclass_wait_syncpt_32_r()#endif
drivers/gpu/host1x/hw/hw_host1x05_uclass.h +12 -0
@@ -165,5 +165,17 @@ static inline u32 host1x_uclass_indoff_rwn_read_v(void) }#define HOST1X_UCLASS_INDOFF_INDROFFSET_F (v) \ host1x_uclass_indoff_indroffset_f(v) +static inline u32 host1x_uclass_load_syncpt_payload_32_r (void ) +{ +return 0x4e ; +} +#define HOST1X_UCLASS_LOAD_SYNCPT_PAYLOAD_32 \ + host1x_uclass_load_syncpt_payload_32_r() +static inline u32 host1x_uclass_wait_syncpt_32_r (void ) +{ +return 0x50 ; +} +#define HOST1X_UCLASS_WAIT_SYNCPT_32 \ + host1x_uclass_wait_syncpt_32_r()#endif
drivers/gpu/host1x/hw/hw_host1x06_uclass.h +12 -0
@@ -165,5 +165,17 @@ static inline u32 host1x_uclass_indoff_rwn_read_v(void) }#define HOST1X_UCLASS_INDOFF_INDROFFSET_F (v) \ host1x_uclass_indoff_indroffset_f(v) +static inline u32 host1x_uclass_load_syncpt_payload_32_r (void ) +{ +return 0x4e ; +} +#define HOST1X_UCLASS_LOAD_SYNCPT_PAYLOAD_32 \ + host1x_uclass_load_syncpt_payload_32_r() +static inline u32 host1x_uclass_wait_syncpt_32_r (void ) +{ +return 0x50 ; +} +#define HOST1X_UCLASS_WAIT_SYNCPT_32 \ + host1x_uclass_wait_syncpt_32_r()#endif
drivers/gpu/host1x/hw/hw_host1x07_uclass.h +12 -0
@@ -165,5 +165,17 @@ static inline u32 host1x_uclass_indoff_rwn_read_v(void) }#define HOST1X_UCLASS_INDOFF_INDROFFSET_F (v) \ host1x_uclass_indoff_indroffset_f(v) +static inline u32 host1x_uclass_load_syncpt_payload_32_r (void ) +{ +return 0x4e ; +} +#define HOST1X_UCLASS_LOAD_SYNCPT_PAYLOAD_32 \ + host1x_uclass_load_syncpt_payload_32_r() +static inline u32 host1x_uclass_wait_syncpt_32_r (void ) +{ +return 0x50 ; +} +#define HOST1X_UCLASS_WAIT_SYNCPT_32 \ + host1x_uclass_wait_syncpt_32_r()#endif
drivers/gpu/host1x/job.c +51 -19
148 lines not on this page · raw message
drivers/gpu/host1x/job.h +16 -0
@@ -18,6 +18,22 @@ struct host1x_job_gather {bool handled; }; +struct host1x_job_wait { +u32 id; +u32 threshold; +u32 next_class; +bool relative; +}; + +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 +4 -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,8 @@ 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, +bool relative,u32 next_class);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.30.1
Mikko Perttunen
maintainerPATCH v6 5/14 drm/tegra: Extract tegra_gem_lookup
In reply to Mikko PerttunenThe static function host1x_bo_lookup in drm.c is also useful elsewhere. Extract it as tegra_gem_lookup in gem.c.
---
v6:
- New patch
--- drivers/gpu/drm/tegra/drm.c | 20 +++----------------- drivers/gpu/drm/tegra/gem.c | 13 +++++++++++++ drivers/gpu/drm/tegra/gem.h | 2 ++ 3 files changed, 18 insertions(+), 17 deletions(-)
drivers/gpu/drm/tegra/drm.c +3 -17
@@ -106,20 +106,6 @@ static void tegra_drm_context_free(struct tegra_drm_context *context)kfree (context); } -static struct host1x_bo * -host1x_bo_lookup (struct drm_file *file,u32 handle) -{ -struct drm_gem_object *gem; -struct tegra_bo *bo; - - gem =drm_gem_object_lookup (file, handle); -if (!gem) -return NULL ; - - bo =to_tegra_bo (gem); -return &bo->base; -} - static int host1x_reloc_copy_from_user(struct host1x_reloc *dest, struct drm_tegra_reloc __user *src, struct drm_device *drm,
@@ -150,11 +136,11 @@ static int host1x_reloc_copy_from_user(struct host1x_reloc *dest, dest->flags =HOST1X_RELOC_READ |HOST1X_RELOC_WRITE ; - dest->cmdbuf.bo =host1x_bo_lookup (file, cmdbuf); + dest->cmdbuf.bo =tegra_gem_lookup (file, cmdbuf);if (!dest->cmdbuf.bo)return -ENOENT ; - dest->target.bo =host1x_bo_lookup (file, target); + dest->target.bo =tegra_gem_lookup (file, target);if (!dest->target.bo)return -ENOENT ;
@@ -237,7 +223,7 @@ int tegra_drm_submit(struct tegra_drm_context *context, goto fail; } - bo =host1x_bo_lookup (file, cmdbuf.handle); + bo =tegra_gem_lookup (file, cmdbuf.handle);if (!bo) { err = -ENOENT ; goto fail;
drivers/gpu/drm/tegra/gem.c +13 -0
@@ -707,3 +707,16 @@ struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm,return &bo->gem; } + +struct host1x_bo *tegra_gem_lookup (struct drm_file *file,u32 handle) +{ +struct drm_gem_object *gem; +struct tegra_bo *bo; + + gem =drm_gem_object_lookup (file, handle); +if (!gem) +return NULL ; + + bo =to_tegra_bo (gem); +return &bo->base; +}
drivers/gpu/drm/tegra/gem.h +2 -0
@@ -74,4 +74,6 @@ struct dma_buf *tegra_gem_prime_export(struct drm_gem_object *gem,struct drm_gem_object *tegra_gem_prime_import (struct drm_device *drm,struct dma_buf *buf); +struct host1x_bo *tegra_gem_lookup (struct drm_file *file,u32 handle); +#endif
Signature · 1 line
2.30.1
Mikko Perttunen
maintainerPATCH v6 6/14 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.
---
v6:
* Fix comment
* Add syncpoint allocation/freeing IOCTLs, use syncpoint ID instead of syncpoint FD
* Add syncobj fields to submit IOCTL
* Add relative syncpoint wait
* Add hardware flags field
* Add syncpoint wait ioctl
* Remove new GEM_CREATE/GEM_MMAP as unneeded
v4:
* Remove features that are not strictly necessary
* Remove padding/reserved fields in IOCTL structs where DRM's zero extension feature allows future expansion
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 | 414 +++++++++++++++++++++++++++++++++-- 1 file changed, 391 insertions(+), 23 deletions(-)
include/uapi/drm/tegra_drm.h +391 -23
@@ -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)
@@ -649,8 +632,8 @@ struct drm_tegra_gem_get_flags {#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
@@ -674,6 +657,391 @@ 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 */ + +/** +* Reported by the driver in the `hardware_flags` field. +* +* If set, the engine is cache coherent with regard to the system +* memory. +*/ +#define DRM_TEGRA_CHANNEL_OPEN_HW_CACHE_COHERENT (1<<0) + +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; + +/** +* @hardware_flags: [out] +* +* Flags describing the hardware capabilities. +*/ +__u32 hardware_flags; +}; + +struct drm_tegra_channel_close { +/** +* @channel_ctx: [in] +* +* Identifier of the channel to close. +*/ +__u32 channel_ctx; +}; + +#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; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +/** +* @mapping_id: [out] +* +* Identifier corresponding to the mapping, to be used for +* relocations or unmapping later. +*/ +__u32 mapping_id; +}; + +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; +}; + +/* 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) + +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. +*/ +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; +}; + +struct drm_tegra_submit_syncpt_incr { +/** +* @id: [in] +* +* ID of the syncpoint that the job will increment. +*/ +__u32 id; + +/** +* @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; +}; + +/** +* 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 a syncpoint to reach a value before continuing with further +* commands. The threshold is calculated in relation to the start of the +* job. +*/ +#define DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT_RELATIVE 2 + +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 { +/** +* @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; +__u32 reserved[4 ]; + }; +}; + +struct drm_tegra_channel_submit { +/** +* @channel_ctx: [in] +* +* Identifier of the channel to submit this job to. +*/ +__u32 channel_ctx; + +/** +* @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; + +/** +* @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; + +/** +* @syncobj_in: [in] +* +* Handle for DRM syncobj that will be waited before submission. +* Ignored if zero. +*/ +__u32 syncobj_in; + +/** +* @syncobj_out: [in] +* +* Handle for DRM syncobj that will have its fence replaced with +* the job's completion fence. Ignored if zero. +*/ +__u32 syncobj_out; + +/** +* @syncpt_incr: [in,out] +* +* Information about the syncpoint the job will increment. +*/ +struct drm_tegra_submit_syncpt_incr syncpt_incr; +}; + +struct drm_tegra_syncpoint_allocate { +/** +* @id: [out] +* +* ID of allocated syncpoint. +*/ +__u32 id; +}; + +struct drm_tegra_syncpoint_free { +/** +* @id: [in] +* +* ID of syncpoint to free. +*/ +__u32 id; +}; + +struct drm_tegra_syncpoint_wait { +/** +* @timeout: [in] +* +* Absolute timestamp at which the wait will time out. +*/ +__s64 timeout_ns; + +/** +* @id: [in] +* +* ID of syncpoint to wait on. +*/ +__u32 id; + +/** +* @threshold: [in] +* +* Threshold to wait for. +*/ +__u32 threshold; + +/** +* @value: [out] +* +* Value of the syncpoint upon wait completion. +*/ +__u32 value; + +__u32 padding[1 ]; +}; + +#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_SYNCPOINT_ALLOCATE DRM_IOWR(DRM_COMMAND_BASE + 0x20, struct drm_tegra_syncpoint_allocate) +#define DRM_IOCTL_TEGRA_SYNCPOINT_FREE DRM_IOWR(DRM_COMMAND_BASE + 0x21, struct drm_tegra_syncpoint_free) +#define DRM_IOCTL_TEGRA_SYNCPOINT_WAIT DRM_IOWR(DRM_COMMAND_BASE + 0x22, struct drm_tegra_syncpoint_wait) +#if defined(__cplusplus) }#endif
Signature · 1 line
2.30.1
Mikko Perttunen
maintainerPATCH v6 7/14 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.
---
v6:
* Use pm_runtime_resume_and_get
v3:
* runtime_get/put is now done directly from submit path, so no callbacks are added
* Reworded.
--- drivers/gpu/drm/tegra/vic.c | 112 ++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 61 deletions(-)
drivers/gpu/drm/tegra/vic.c +51 -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;
@@ -170,8 +124,6 @@ static int vic_boot(struct vic *vic)return err; } - vic->booted = true; -return 0 ; }
@@ -325,35 +277,74 @@ 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_resume_and_get (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_resume_and_get (vic->dev); +if (err <0 ) +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)
@@ -361,7 +352,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.30.1
Mikko Perttunen
maintainerPATCH v6 8/14 drm/tegra: Allocate per-engine channel in core code
In reply to Mikko PerttunenTo avoid code duplication, allocate the per-engine shared channel in the core code instead. This is the usual channel that all jobs are submitted to when MLOCKing is not in use. Once MLOCKs are implemented on Host1x side, we can also update this to avoid allocating a shared channel when MLOCKs are enabled.
---
v6:
- Reorder fields in drm.h to put core-controlled fields first
--- drivers/gpu/drm/tegra/drm.c | 11 +++++++++++ drivers/gpu/drm/tegra/drm.h | 2 ++ 2 files changed, 13 insertions(+)
drivers/gpu/drm/tegra/drm.c +11 -0
@@ -869,6 +869,14 @@ static const 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;
@@ -885,6 +893,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 +2 -0
@@ -86,7 +86,9 @@ struct tegra_drm_client {struct host1x_client base;struct list_head list;struct tegra_drm *drm; +struct host1x_channel *shared_channel; +/* Set by driver */ unsigned int version;const struct tegra_drm_client_ops *ops; };
Signature · 1 line
2.30.1
Mikko Perttunen
maintainerPATCH v6 9/14 drm/tegra: Implement new UAPI
In reply to Mikko PerttunenImplement the non-submission parts of the new UAPI, including channel management and memory mapping. The UAPI is under the CONFIG_DRM_TEGRA_STAGING config flag for now.
---
v6:
* Whitespace fixes
* Tell userspace if engine is cache coherent when opening a channel
* Removed uapi subdirectory
* Reuse tegra_drm_context instead of creating new tegra_drm_channel_ctx
* Remove tegra_drm_channel_ctx_lock
* Simplify id variable names
* Remove unused close_channel_ctx function
* Use tegra_gem_lookup
* Clean up channel_open by outlining client-finding code
* Use DMA API path when there is no IOMMU
* Remove unnecessary comment
* Remove new GEM_CREATE/GEM_MMAP
* Move unlock in channel_map to avoid double unlock on error path.
v5:
* Set iova_end in both mapping paths
v4:
* New patch, split out from combined UAPI + submit patch.
--- drivers/gpu/drm/tegra/Makefile | 1 + drivers/gpu/drm/tegra/drm.c | 37 ++-- drivers/gpu/drm/tegra/drm.h | 10 ++ drivers/gpu/drm/tegra/uapi.c | 300 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/tegra/uapi.h | 51 ++++++ 5 files changed, 383 insertions(+), 16 deletions(-) create mode 100644 drivers/gpu/drm/tegra/uapi.c create mode 100644 drivers/gpu/drm/tegra/uapi.h
drivers/gpu/drm/tegra/Makefile +1 -0
@@ -3,6 +3,7 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG tegra-drm-y := \ drm.o \ + uapi.o \ gem.o \ fb.o \ dp.o \
drivers/gpu/drm/tegra/drm.c +21 -16
@@ -20,6 +20,7 @@#include <drm/drm_prime.h> #include <drm/drm_vblank.h> +#include "uapi.h" #include "drm.h" #include "gem.h"
@@ -33,11 +34,6 @@#define CARVEOUT_SZ SZ_64M#define CDMA_GATHER_FETCHES_MAX_NB 16383 -struct tegra_drm_file { -struct idr contexts; -struct mutex lock; -}; -static int tegra_atomic_check (struct drm_device *drm,struct drm_atomic_state *state) {
@@ -93,7 +89,8 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)if (!fpriv)return -ENOMEM ; -idr_init_base (&fpriv->contexts,1 ); +idr_init_base (&fpriv->legacy_contexts,1 ); +xa_init_flags (&fpriv->contexts,XA_FLAGS_ALLOC1 );mutex_init (&fpriv->lock); filp->driver_priv = fpriv;
@@ -418,7 +415,7 @@ static int tegra_client_open(struct tegra_drm_file *fpriv,if (err <0 )return err; - err =idr_alloc (&fpriv->contexts, context,1 ,0 ,GFP_KERNEL ); + err =idr_alloc (&fpriv->legacy_contexts, context,1 ,0 ,GFP_KERNEL );if (err <0 ) { client->ops->close_channel (context);return err;
@@ -473,13 +470,13 @@ static int tegra_close_channel(struct drm_device *drm, void *data,mutex_lock (&fpriv->lock); - context =idr_find (&fpriv->contexts, args->context); + context =idr_find (&fpriv->legacy_contexts, args->context);if (!context) { err = -EINVAL ; goto unlock; } -idr_remove (&fpriv->contexts, context->id); +idr_remove (&fpriv->legacy_contexts, context->id);tegra_drm_context_free (context); unlock:
@@ -498,7 +495,7 @@ static int tegra_get_syncpt(struct drm_device *drm, void *data,mutex_lock (&fpriv->lock); - context =idr_find (&fpriv->contexts, args->context); + context =idr_find (&fpriv->legacy_contexts, args->context);if (!context) { err = -ENODEV ; goto unlock;
@@ -527,7 +524,7 @@ static int tegra_submit(struct drm_device *drm, void *data,mutex_lock (&fpriv->lock); - context =idr_find (&fpriv->contexts, args->context); + context =idr_find (&fpriv->legacy_contexts, args->context);if (!context) { err = -ENODEV ; goto unlock;
@@ -552,7 +549,7 @@ static int tegra_get_syncpt_base(struct drm_device *drm, void *data,mutex_lock (&fpriv->lock); - context =idr_find (&fpriv->contexts, args->context); + context =idr_find (&fpriv->legacy_contexts, args->context);if (!context) { err = -ENODEV ; goto unlock;
@@ -721,10 +718,17 @@ static int tegra_gem_get_flags(struct drm_device *drm, void *data,static const struct drm_ioctl_desc tegra_drm_ioctls[] = { #ifdef CONFIG_DRM_TEGRA_STAGING -DRM_IOCTL_DEF_DRV (TEGRA_GEM_CREATE , tegra_gem_create, +DRM_IOCTL_DEF_DRV (TEGRA_CHANNEL_OPEN , tegra_drm_ioctl_channel_open, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (TEGRA_CHANNEL_CLOSE , tegra_drm_ioctl_channel_close,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (TEGRA_GEM_MMAP , tegra_gem_mmap, +DRM_IOCTL_DEF_DRV (TEGRA_CHANNEL_MAP , tegra_drm_ioctl_channel_map,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (TEGRA_CHANNEL_UNMAP , tegra_drm_ioctl_channel_unmap, +DRM_RENDER_ALLOW ), + +DRM_IOCTL_DEF_DRV (TEGRA_GEM_CREATE , tegra_gem_create,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (TEGRA_GEM_MMAP , tegra_gem_mmap,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (TEGRA_SYNCPT_READ , tegra_syncpt_read,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_INCR, tegra_syncpt_incr,
@@ -778,10 +782,11 @@ static void tegra_drm_postclose(struct drm_device *drm, struct drm_file *file)struct tegra_drm_file *fpriv = file->driver_priv;mutex_lock (&fpriv->lock); -idr_for_each (&fpriv->contexts, tegra_drm_context_cleanup,NULL ); +idr_for_each (&fpriv->legacy_contexts, tegra_drm_context_cleanup,NULL ); +tegra_drm_uapi_close_file (fpriv);mutex_unlock (&fpriv->lock); -idr_destroy (&fpriv->contexts); +idr_destroy (&fpriv->legacy_contexts);mutex_destroy (&fpriv->lock);kfree (fpriv); }
drivers/gpu/drm/tegra/drm.h +10 -0
@@ -59,12 +59,22 @@ 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 {struct tegra_drm_client *client;struct host1x_channel *channel; + +/* Only used by legacy UAPI. */ unsigned int id; + +/* Only used by new UAPI. */ +struct xarray mappings; };struct tegra_drm_client_ops {
drivers/gpu/drm/tegra/uapi.c new file +300 -0
300 lines not on this page · raw message
drivers/gpu/drm/tegra/uapi.h new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.30.1
kernel test robot
build botRe: [PATCH v6 09/14] drm/tegra: Implement new UAPI
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 v5.13-rc3 next-20210528]
[cannot apply to tegra/for-next]
[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/TegraDRM-UAPI/20210530-205239 base: git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next config: arm-randconfig-r015-20210530 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project bc6799f2f79f0ae87e9f1ebf9d25ba799fbd25a9)
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 arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/0day-ci/linux/commit/0d658490b25da0e7f059362a45f609a92cbcbaef
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mikko-Perttunen/TegraDRM-UAPI/20210530-205239 git checkout 0d658490b25da0e7f059362a45f609a92cbcbaef
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/tegra/uapi.c:265:5: warning: no previous prototype for function 'tegra_drm_ioctl_gem_create' [-Wmissing-prototypes]
int tegra_drm_ioctl_gem_create(struct drm_device *drm, void *data,
^
drivers/gpu/drm/tegra/uapi.c:265:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int tegra_drm_ioctl_gem_create(struct drm_device *drm, void *data,
^
static
>> drivers/gpu/drm/tegra/uapi.c:282:5: warning: no previous prototype for function 'tegra_drm_ioctl_gem_mmap' [-Wmissing-prototypes]
int tegra_drm_ioctl_gem_mmap(struct drm_device *drm, void *data,
^ drivers/gpu/drm/tegra/uapi.c:282:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int tegra_drm_ioctl_gem_mmap(struct drm_device *drm, void *data,
^
static
2 warnings generated.
vim +/tegra_drm_ioctl_gem_create +265 drivers/gpu/drm/tegra/uapi.c
264
> 265 int tegra_drm_ioctl_gem_create(struct drm_device *drm, void *data,
266 struct drm_file *file)
267 {
268 struct drm_tegra_gem_create *args = data;
269 struct tegra_bo *bo;
270
271 if (args->flags)
272 return -EINVAL;
273
274 bo = tegra_bo_create_with_handle(file, drm, args->size, args->flags,
275 &args->handle);
276 if (IS_ERR(bo))
277 return PTR_ERR(bo);
278
279 return 0;
280 }
281
> 282 int tegra_drm_ioctl_gem_mmap(struct drm_device *drm, void *data,---
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 v6 09/14] drm/tegra: Implement new UAPI
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 v5.13-rc3 next-20210528]
[cannot apply to tegra/for-next]
[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/TegraDRM-UAPI/20210530-205239 base: git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next config: arm-defconfig (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/0d658490b25da0e7f059362a45f609a92cbcbaef
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mikko-Perttunen/TegraDRM-UAPI/20210530-205239 git checkout 0d658490b25da0e7f059362a45f609a92cbcbaef
# 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 warnings (new ones prefixed by >>):
>> drivers/gpu/drm/tegra/uapi.c:265:5: warning: no previous prototype for 'tegra_drm_ioctl_gem_create' [-Wmissing-prototypes]
265 | int tegra_drm_ioctl_gem_create(struct drm_device *drm, void *data,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/gpu/drm/tegra/uapi.c:282:5: warning: no previous prototype for 'tegra_drm_ioctl_gem_mmap' [-Wmissing-prototypes] 282 | int tegra_drm_ioctl_gem_mmap(struct drm_device *drm, void *data,
| ^~~~~~~~~~~~~~~~~~~~~~~~
vim +/tegra_drm_ioctl_gem_create +265 drivers/gpu/drm/tegra/uapi.c
264
> 265 int tegra_drm_ioctl_gem_create(struct drm_device *drm, void *data,
266 struct drm_file *file)
267 {
268 struct drm_tegra_gem_create *args = data;
269 struct tegra_bo *bo;
270
271 if (args->flags)
272 return -EINVAL;
273
274 bo = tegra_bo_create_with_handle(file, drm, args->size, args->flags,
275 &args->handle);
276 if (IS_ERR(bo))
277 return PTR_ERR(bo);
278
279 return 0;
280 }
281
> 282 int tegra_drm_ioctl_gem_mmap(struct drm_device *drm, void *data,---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Mikko Perttunen
maintainerPATCH v6 10/14 drm/tegra: Implement syncpoint management UAPI
In reply to Mikko PerttunenImplement TegraDRM IOCTLs for allocating and freeing syncpoints.
---
v6:
- New patch
--- drivers/gpu/drm/tegra/drm.c | 5 ++++ drivers/gpu/drm/tegra/uapi.c | 56 ++++++++++++++++++++++++++++++++++-- drivers/gpu/drm/tegra/uapi.h | 5 ++++ 3 files changed, 64 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/drm.c +5 -0
@@ -91,6 +91,7 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)idr_init_base (&fpriv->legacy_contexts,1 );xa_init_flags (&fpriv->contexts,XA_FLAGS_ALLOC1 ); +xa_init (&fpriv->syncpoints);mutex_init (&fpriv->lock); filp->driver_priv = fpriv;
@@ -726,6 +727,10 @@ static const struct drm_ioctl_desc tegra_drm_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (TEGRA_CHANNEL_UNMAP , tegra_drm_ioctl_channel_unmap,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (TEGRA_SYNCPOINT_ALLOCATE , tegra_drm_ioctl_syncpoint_allocate, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (TEGRA_SYNCPOINT_FREE , tegra_drm_ioctl_syncpoint_free, +DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (TEGRA_GEM_CREATE , tegra_gem_create,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP, tegra_gem_mmap, DRM_RENDER_ALLOW),
drivers/gpu/drm/tegra/uapi.c +54 -2
70 lines not on this page · raw message
drivers/gpu/drm/tegra/uapi.h +5 -0
@@ -21,6 +21,7 @@ struct tegra_drm_file {/* New UAPI state */ struct xarray contexts; +struct xarray syncpoints; };struct tegra_drm_mapping {
@@ -44,6 +45,10 @@ int tegra_drm_ioctl_channel_unmap(struct drm_device *drm, void *data, struct drm_file *file);int tegra_drm_ioctl_channel_submit (struct drm_device *drm,void *data,struct drm_file *file); +int tegra_drm_ioctl_syncpoint_allocate (struct drm_device *drm,void *data, +struct drm_file *file); +int tegra_drm_ioctl_syncpoint_free (struct drm_device *drm,void *data, +struct drm_file *file);void tegra_drm_uapi_close_file (struct tegra_drm_file *file);void tegra_drm_mapping_put (struct tegra_drm_mapping *mapping);
Signature · 1 line
2.30.1
Mikko Perttunen
maintainerPATCH v6 11/14 drm/tegra: Implement syncpoint wait UAPI
In reply to Mikko PerttunenImplement new syncpoint wait UAPI. This is different from the legacy one in taking an absolute timestamp in line with modern DRM conventions.
---
v6:
- New patch
--- drivers/gpu/drm/tegra/drm.c | 2 ++ drivers/gpu/drm/tegra/uapi.c | 22 ++++++++++++++++++++++ drivers/gpu/drm/tegra/uapi.h | 2 ++ 3 files changed, 26 insertions(+)
drivers/gpu/drm/tegra/drm.c +2 -0
@@ -731,6 +731,8 @@ static const struct drm_ioctl_desc tegra_drm_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (TEGRA_SYNCPOINT_FREE , tegra_drm_ioctl_syncpoint_free,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (TEGRA_SYNCPOINT_WAIT , tegra_drm_ioctl_syncpoint_wait, +DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (TEGRA_GEM_CREATE , tegra_gem_create,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP, tegra_gem_mmap, DRM_RENDER_ALLOW),
drivers/gpu/drm/tegra/uapi.c +22 -0
@@ -7,6 +7,7 @@#include <drm/drm_drv.h> #include <drm/drm_file.h> +#include <drm/drm_utils.h> #include "drm.h" #include "uapi.h"
@@ -350,3 +351,24 @@ int tegra_drm_ioctl_syncpoint_free(struct drm_device *drm, void *data,return 0 ; } + +int tegra_drm_ioctl_syncpoint_wait (struct drm_device *drm,void *data, +struct drm_file *file) +{ +struct host1x *host1x =tegra_drm_to_host1x (drm->dev_private); +struct drm_tegra_syncpoint_wait *args = data; +signed long timeout_jiffies; +struct host1x_syncpt *sp; + +if (args->padding[0 ] !=0 ) +return -EINVAL ; + + sp =host1x_syncpt_get_by_id_noref (host1x, args->id); +if (!sp) +return -EINVAL ; + + timeout_jiffies =drm_timeout_abs_to_jiffies (args->timeout_ns); + +return host1x_syncpt_wait (sp, args->threshold, timeout_jiffies, + &args->value); +}
drivers/gpu/drm/tegra/uapi.h +2 -0
@@ -49,6 +49,8 @@ int tegra_drm_ioctl_syncpoint_allocate(struct drm_device *drm, void *data, struct drm_file *file);int tegra_drm_ioctl_syncpoint_free (struct drm_device *drm,void *data,struct drm_file *file); +int tegra_drm_ioctl_syncpoint_wait (struct drm_device *drm,void *data, +struct drm_file *file);void tegra_drm_uapi_close_file (struct tegra_drm_file *file);void tegra_drm_mapping_put (struct tegra_drm_mapping *mapping);
Signature · 1 line
2.30.1
Mikko Perttunen
maintainerPATCH v6 12/14 drm/tegra: Implement job submission part of new UAPI
In reply to Mikko PerttunenImplement the job submission IOCTL with a minimum feature set.
---
v6:
* Remove sgt bypass path in gather_bo - this would cause cache maintenance to be skipped and is unnecessary in general.
* Changes related to moving to using syncpoint IDs
* Add syncobj related code
* Print warning on submit failure describing the issue
* Use ARCH_DMA_ADDR_T_64BIT to check if that is indeed the case
* Add support for relative syncpoint wait
* Use pm_runtime_resume_and_get
* Only try to resume engines that support runtime PM
* Removed uapi subdirectory
* Don't use "copy_err" variables for copy_from_user return value
* Fix setting of blocklinear flag
v5:
* Add 16K size limit to copies from userspace.
* Guard RELOC_BLOCKLINEAR flag handling to only exist in ARM64 to prevent oversized shift on 32-bit platforms.
v4:
* Remove all features that are not strictly necessary.
* Split into two patches.
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 | 2 + drivers/gpu/drm/tegra/drm.c | 4 +- drivers/gpu/drm/tegra/gather_bo.c | 81 +++++ drivers/gpu/drm/tegra/gather_bo.h | 22 ++ drivers/gpu/drm/tegra/submit.c | 541 ++++++++++++++++++++++++++++++ drivers/gpu/drm/tegra/submit.h | 17 + 6 files changed, 666 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/tegra/gather_bo.c create mode 100644 drivers/gpu/drm/tegra/gather_bo.h create mode 100644 drivers/gpu/drm/tegra/submit.c create mode 100644 drivers/gpu/drm/tegra/submit.h
drivers/gpu/drm/tegra/Makefile +2 -0
@@ -4,6 +4,8 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG tegra-drm-y := \ drm.o \ uapi.o \ + submit.o \ + gather_bo.o \ gem.o \ fb.o \ dp.o \
drivers/gpu/drm/tegra/drm.c +3 -1
@@ -727,6 +727,8 @@ static const struct drm_ioctl_desc tegra_drm_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (TEGRA_CHANNEL_UNMAP , tegra_drm_ioctl_channel_unmap,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (TEGRA_CHANNEL_SUBMIT , tegra_drm_ioctl_channel_submit, +DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (TEGRA_SYNCPOINT_ALLOCATE , tegra_drm_ioctl_syncpoint_allocate,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(TEGRA_SYNCPOINT_FREE, tegra_drm_ioctl_syncpoint_free,
@@ -851,7 +853,7 @@ static void tegra_debugfs_init(struct drm_minor *minor)static const struct drm_driver tegra_drm_driver = { .driver_features =DRIVER_MODESET |DRIVER_GEM | -DRIVER_ATOMIC |DRIVER_RENDER , +DRIVER_ATOMIC |DRIVER_RENDER |DRIVER_SYNCOBJ , .open = tegra_drm_open, .postclose = tegra_drm_postclose, .lastclose = drm_fb_helper_lastclose,
drivers/gpu/drm/tegra/gather_bo.c new file +81 -0
81 lines not on this page · raw message
drivers/gpu/drm/tegra/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/submit.c new file +541 -0
541 lines not on this page · raw message
drivers/gpu/drm/tegra/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
Signature · 1 line
2.30.1
Mikko Perttunen
maintainerPATCH v6 13/14 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.
---
v6:
* If .is_valid_class is not set, match against client's class
* Fix indentation
* Return to previous class after a WAIT command
* Print warning detailing error when rejecting a command buffer
* Removed uapi subdirectory
v5:
* Support SETCLASS opcode
v3:
* New patch
--- drivers/gpu/drm/tegra/Makefile | 1 + drivers/gpu/drm/tegra/firewall.c | 254 +++++++++++++++++++++++++++++++ drivers/gpu/drm/tegra/submit.c | 12 +- drivers/gpu/drm/tegra/submit.h | 4 + 4 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/tegra/firewall.c
drivers/gpu/drm/tegra/Makefile +1 -0
@@ -6,6 +6,7 @@ tegra-drm-y := \ uapi.o \ submit.o \ gather_bo.o \ + firewall.o \ gem.o \ fb.o \ dp.o \
drivers/gpu/drm/tegra/firewall.c new file +254 -0
254 lines not on this page · raw message
drivers/gpu/drm/tegra/submit.c +10 -2
@@ -246,7 +246,8 @@ static int submit_job_add_gather(struct host1x_job *job,struct tegra_drm_context *ctx, struct drm_tegra_submit_cmd_gather_uptr *cmd, struct gather_bo *bo, u32 *offset, - struct tegra_drm_submit_data *job_data) + struct tegra_drm_submit_data *job_data, + u32 *class) { u32 next_offset;
@@ -271,6 +272,12 @@ static int submit_job_add_gather(struct host1x_job *job,return -EINVAL ; } +if (tegra_drm_fw_validate (ctx->client, bo->gather_data, *offset, + cmd->words, job_data, class)) { +SUBMIT_ERR (ctx,"job was rejected by firewall" ); +return -EINVAL ; + } +host1x_job_add_gather (job, &bo->base, cmd->words, *offset *4 ); *offset = next_offset;
@@ -327,7 +334,8 @@ static int submit_create_job(struct host1x_job **pjob,if (cmd->type ==DRM_TEGRA_SUBMIT_CMD_GATHER_UPTR ) { err =submit_job_add_gather (job, ctx, &cmd->gather_uptr, bo, - &gather_offset, job_data); + &gather_offset, job_data, + &class);if (err) goto free_job; }else if (cmd->type ==DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT ) {
drivers/gpu/drm/tegra/submit.h +4 -0
@@ -14,4 +14,8 @@ 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, +u32 *job_class); +#endif
Signature · 1 line
2.30.1
Mikko Perttunen
maintainerPATCH v6 14/14 drm/tegra: Bump driver version
In reply to Mikko PerttunenBump driver version to 1.0.0 to allow userspace to detect availability of new interfaces.
--- drivers/gpu/drm/tegra/drm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tegra/drm.c +1 -1
@@ -27,7 +27,7 @@#define DRIVER_NAME "tegra"#define DRIVER_DESC "NVIDIA Tegra graphics"#define DRIVER_DATE "20120330" -#define DRIVER_MAJOR 0 +#define DRIVER_MAJOR 1#define DRIVER_MINOR 0#define DRIVER_PATCHLEVEL 0
Signature · 1 line
2.30.1