1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
|
/*
* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
* Copyright (C) 2017 Linaro Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/clk.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <media/videobuf2-dma-sg.h>
#include <media/v4l2-mem2mem.h>
#include <asm/div64.h>
#include "core.h"
#include "helpers.h"
#include "hfi_helper.h"
struct intbuf {
struct list_head list;
u32 type;
size_t size;
void *va;
dma_addr_t da;
unsigned long attrs;
};
bool venus_helper_check_codec(struct venus_inst *inst, u32 v4l2_pixfmt)
{
struct venus_core *core = inst->core;
u32 session_type = inst->session_type;
u32 codec;
switch (v4l2_pixfmt) {
case V4L2_PIX_FMT_H264:
codec = HFI_VIDEO_CODEC_H264;
break;
case V4L2_PIX_FMT_H263:
codec = HFI_VIDEO_CODEC_H263;
break;
case V4L2_PIX_FMT_MPEG1:
codec = HFI_VIDEO_CODEC_MPEG1;
break;
case V4L2_PIX_FMT_MPEG2:
codec = HFI_VIDEO_CODEC_MPEG2;
break;
case V4L2_PIX_FMT_MPEG4:
codec = HFI_VIDEO_CODEC_MPEG4;
break;
case V4L2_PIX_FMT_VC1_ANNEX_G:
case V4L2_PIX_FMT_VC1_ANNEX_L:
codec = HFI_VIDEO_CODEC_VC1;
break;
case V4L2_PIX_FMT_VP8:
codec = HFI_VIDEO_CODEC_VP8;
break;
case V4L2_PIX_FMT_VP9:
codec = HFI_VIDEO_CODEC_VP9;
break;
case V4L2_PIX_FMT_XVID:
codec = HFI_VIDEO_CODEC_DIVX;
break;
default:
return false;
}
if (session_type == VIDC_SESSION_TYPE_ENC && core->enc_codecs & codec)
return true;
if (session_type == VIDC_SESSION_TYPE_DEC && core->dec_codecs & codec)
return true;
return false;
}
EXPORT_SYMBOL_GPL(venus_helper_check_codec);
static int intbufs_set_buffer(struct venus_inst *inst, u32 type)
{
struct venus_core *core = inst->core;
struct device *dev = core->dev;
struct hfi_buffer_requirements bufreq;
struct hfi_buffer_desc bd;
struct intbuf *buf;
unsigned int i;
int ret;
ret = venus_helper_get_bufreq(inst, type, &bufreq);
if (ret)
return 0;
if (!bufreq.size)
return 0;
for (i = 0; i < bufreq.count_actual; i++) {
buf = kzalloc(sizeof(*buf), GFP_KERNEL);
if (!buf) {
ret = -ENOMEM;
goto fail;
}
buf->type = bufreq.type;
buf->size = bufreq.size;
buf->attrs = DMA_ATTR_WRITE_COMBINE |
DMA_ATTR_NO_KERNEL_MAPPING;
buf->va = dma_alloc_attrs(dev, buf->size, &buf->da, GFP_KERNEL,
buf->attrs);
if (!buf->va) {
ret = -ENOMEM;
goto fail;
}
memset(&bd, 0, sizeof(bd));
bd.buffer_size = buf->size;
bd.buffer_type = buf->type;
bd.num_buffers = 1;
bd.device_addr = buf->da;
ret = hfi_session_set_buffers(inst, &bd);
if (ret) {
dev_err(dev, "set session buffers failed\n");
goto dma_free;
}
list_add_tail(&buf->list, &inst->internalbufs);
}
return 0;
dma_free:
dma_free_attrs(dev, buf->size, buf->va, buf->da, buf->attrs);
fail:
kfree(buf);
return ret;
}
static int intbufs_unset_buffers(struct venus_inst *inst)
{
struct hfi_buffer_desc bd = {0};
struct intbuf *buf, *n;
int ret = 0;
list_for_each_entry_safe(buf, n, &inst->internalbufs, list) {
bd.buffer_size = buf->size;
bd.buffer_type = buf->type;
bd.num_buffers = 1;
bd.device_addr = buf->da;
bd.response_required = true;
ret = hfi_session_unset_buffers(inst, &bd);
list_del_init(&buf->list);
dma_free_attrs(inst->core->dev, buf->size, buf->va, buf->da,
buf->attrs);
kfree(buf);
}
return ret;
}
static const unsigned int intbuf_types[] = {
HFI_BUFFER_INTERNAL_SCRATCH,
HFI_BUFFER_INTERNAL_SCRATCH_1,
HFI_BUFFER_INTERNAL_SCRATCH_2,
HFI_BUFFER_INTERNAL_PERSIST,
HFI_BUFFER_INTERNAL_PERSIST_1,
};
static int intbufs_alloc(struct venus_inst *inst)
{
unsigned int i;
int ret;
for (i = 0; i < ARRAY_SIZE(intbuf_types); i++) {
ret = intbufs_set_buffer(inst, intbuf_types[i]);
if (ret)
goto error;
}
return 0;
error:
intbufs_unset_buffers(inst);
return ret;
}
static int intbufs_free(struct venus_inst *inst)
{
return intbufs_unset_buffers(inst);
}
static u32 load_per_instance(struct venus_inst *inst)
{
u32 mbs;
if (!inst || !(inst->state >= INST_INIT && inst->state < INST_STOP))
return 0;
mbs = (ALIGN(inst->width, 16) / 16) * (ALIGN(inst->height, 16) / 16);
return mbs * inst->fps;
}
static u32 load_per_type(struct venus_core *core, u32 session_type)
{
struct venus_inst *inst = NULL;
u32 mbs_per_sec = 0;
mutex_lock(&core->lock);
list_for_each_entry(inst, &core->instances, list) {
if (inst->session_type != session_type)
continue;
mbs_per_sec += load_per_instance(inst);
}
mutex_unlock(&core->lock);
return mbs_per_sec;
}
static int load_scale_clocks(struct venus_core *core)
{
const struct freq_tbl *table = core->res->freq_tbl;
unsigned int num_rows = core->res->freq_tbl_size;
unsigned long freq = table[0].freq;
struct clk *clk = core->clks[0];
struct device *dev = core->dev;
u32 mbs_per_sec;
unsigned int i;
int ret;
mbs_per_sec = load_per_type(core, VIDC_SESSION_TYPE_ENC) +
load_per_type(core, VIDC_SESSION_TYPE_DEC);
if (mbs_per_sec > core->res->max_load)
dev_warn(dev, "HW is overloaded, needed: %d max: %d\n",
mbs_per_sec, core->res->max_load);
if (!mbs_per_sec && num_rows > 1) {
freq = table[num_rows - 1].freq;
goto set_freq;
}
for (i = 0; i < num_rows; i++) {
if (mbs_per_sec > table[i].load)
break;
freq = table[i].freq;
}
set_freq:
if (core->res->hfi_version == HFI_VERSION_3XX) {
ret = clk_set_rate(clk, freq);
ret |= clk_set_rate(core->core0_clk, freq);
ret |= clk_set_rate(core->core1_clk, freq);
} else {
ret = clk_set_rate(clk, freq);
}
if (ret) {
dev_err(dev, "failed to set clock rate %lu (%d)\n", freq, ret);
return ret;
}
return 0;
}
static void fill_buffer_desc(const struct venus_buffer *buf,
struct hfi_buffer_desc *bd, bool response)
{
memset(bd, 0, sizeof(*bd));
bd->buffer_type = HFI_BUFFER_OUTPUT;
bd->buffer_size = buf->size;
bd->num_buffers = 1;
bd->device_addr = buf->dma_addr;
bd->response_required = response;
}
static void return_buf_error(struct venus_inst *inst,
struct vb2_v4l2_buffer *vbuf)
{
struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx;
if (vbuf->vb2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
v4l2_m2m_src_buf_remove_by_buf(m2m_ctx, vbuf);
else
v4l2_m2m_dst_buf_remove_by_buf(m2m_ctx, vbuf);
v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR);
}
static int
session_process_buf(struct venus_inst *inst, struct vb2_v4l2_buffer *vbuf)
{
struct venus_buffer *buf = to_venus_buffer(vbuf);
struct vb2_buffer *vb = &vbuf->vb2_buf;
unsigned int type = vb->type;
struct hfi_frame_data fdata;
int ret;
memset(&fdata, 0, sizeof(fdata));
fdata.alloc_len = buf->size;
fdata.device_addr = buf->dma_addr;
fdata.timestamp = vb->timestamp;
do_div(fdata.timestamp, NSEC_PER_USEC);
fdata.flags = 0;
fdata.clnt_data = vbuf->vb2_buf.index;
if (!fdata.timestamp)
fdata.flags |= HFI_BUFFERFLAG_TIMESTAMPINVALID;
if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
fdata.buffer_type = HFI_BUFFER_INPUT;
fdata.filled_len = vb2_get_plane_payload(vb, 0);
fdata.offset = vb->planes[0].data_offset;
if (vbuf->flags & V4L2_BUF_FLAG_LAST || !fdata.filled_len)
fdata.flags |= HFI_BUFFERFLAG_EOS;
} else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
fdata.buffer_type = HFI_BUFFER_OUTPUT;
fdata.filled_len = 0;
fdata.offset = 0;
}
ret = hfi_session_process_buf(inst, &fdata);
if (ret)
return ret;
return 0;
}
static inline int is_reg_unreg_needed(struct venus_inst *inst)
{
if (inst->session_type == VIDC_SESSION_TYPE_DEC &&
inst->core->res->hfi_version == HFI_VERSION_3XX)
return 0;
if (inst->session_type == VIDC_SESSION_TYPE_DEC &&
inst->cap_bufs_mode_dynamic &&
inst->core->res->hfi_version == HFI_VERSION_1XX)
return 0;
return 1;
}
static int session_unregister_bufs(struct venus_inst *inst)
{
struct venus_buffer *buf, *n;
struct hfi_buffer_desc bd;
int ret = 0;
if (!is_reg_unreg_needed(inst))
return 0;
list_for_each_entry_safe(buf, n, &inst->registeredbufs, reg_list) {
fill_buffer_desc(buf, &bd, true);
ret = hfi_session_unset_buffers(inst, &bd);
list_del_init(&buf->reg_list);
}
return ret;
}
static int session_register_bufs(struct venus_inst *inst)
{
struct venus_core *core = inst->core;
struct device *dev = core->dev;
struct hfi_buffer_desc bd;
struct venus_buffer *buf;
int ret = 0;
if (!is_reg_unreg_needed(inst))
return 0;
list_for_each_entry(buf, &inst->registeredbufs, reg_list) {
fill_buffer_desc(buf, &bd, false);
ret = hfi_session_set_buffers(inst, &bd);
if (ret) {
dev_err(dev, "%s: set buffer failed\n", __func__);
break;
}
}
return ret;
}
int venus_helper_get_bufreq(struct venus_inst *inst, u32 type,
struct hfi_buffer_requirements *req)
{
u32 ptype = HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS;
union hfi_get_property hprop;
unsigned int i;
int ret;
if (req)
memset(req, 0, sizeof(*req));
ret = hfi_session_get_property(inst, ptype, &hprop);
if (ret)
return ret;
ret = -EINVAL;
for (i = 0; i < HFI_BUFFER_TYPE_MAX; i++) {
if (hprop.bufreq[i].type != type)
continue;
if (req)
memcpy(req, &hprop.bufreq[i], sizeof(*req));
ret = 0;
break;
}
return ret;
}
EXPORT_SYMBOL_GPL(venus_helper_get_bufreq);
int venus_helper_set_input_resolution(struct venus_inst *inst,
unsigned int width, unsigned int height)
{
u32 ptype = HFI_PROPERTY_PARAM_FRAME_SIZE;
struct hfi_framesize fs;
fs.buffer_type = HFI_BUFFER_INPUT;
fs.width = width;
fs.height = height;
return hfi_session_set_property(inst, ptype, &fs);
}
EXPORT_SYMBOL_GPL(venus_helper_set_input_resolution);
int venus_helper_set_output_resolution(struct venus_inst *inst,
unsigned int width, unsigned int height)
{
u32 ptype = HFI_PROPERTY_PARAM_FRAME_SIZE;
struct hfi_framesize fs;
fs.buffer_type = HFI_BUFFER_OUTPUT;
fs.width = width;
fs.height = height;
return hfi_session_set_property(inst, ptype, &fs);
}
EXPORT_SYMBOL_GPL(venus_helper_set_output_resolution);
int venus_helper_set_num_bufs(struct venus_inst *inst, unsigned int input_bufs,
unsigned int output_bufs)
{
u32 ptype = HFI_PROPERTY_PARAM_BUFFER_COUNT_ACTUAL;
struct hfi_buffer_count_actual buf_count;
int ret;
buf_count.type = HFI_BUFFER_INPUT;
buf_count.count_actual = input_bufs;
ret = hfi_session_set_property(inst, ptype, &buf_count);
if (ret)
return ret;
buf_count.type = HFI_BUFFER_OUTPUT;
buf_count.count_actual = output_bufs;
return hfi_session_set_property(inst, ptype, &buf_count);
}
EXPORT_SYMBOL_GPL(venus_helper_set_num_bufs);
int venus_helper_set_color_format(struct venus_inst *inst, u32 pixfmt)
{
struct hfi_uncompressed_format_select fmt;
u32 ptype = HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SELECT;
int ret;
if (inst->session_type == VIDC_SESSION_TYPE_DEC)
fmt.buffer_type = HFI_BUFFER_OUTPUT;
else if (inst->session_type == VIDC_SESSION_TYPE_ENC)
fmt.buffer_type = HFI_BUFFER_INPUT;
else
return -EINVAL;
switch (pixfmt) {
case V4L2_PIX_FMT_NV12:
fmt.format = HFI_COLOR_FORMAT_NV12;
break;
case V4L2_PIX_FMT_NV21:
fmt.format = HFI_COLOR_FORMAT_NV21;
break;
default:
return -EINVAL;
}
ret = hfi_session_set_property(inst, ptype, &fmt);
if (ret)
return ret;
return 0;
}
EXPORT_SYMBOL_GPL(venus_helper_set_color_format);
static void delayed_process_buf_func(struct work_struct *work)
{
struct venus_buffer *buf, *n;
struct venus_inst *inst;
int ret;
inst = container_of(work, struct venus_inst, delayed_process_work);
mutex_lock(&inst->lock);
if (!(inst->streamon_out & inst->streamon_cap))
goto unlock;
list_for_each_entry_safe(buf, n, &inst->delayed_process, ref_list) {
if (buf->flags & HFI_BUFFERFLAG_READONLY)
continue;
ret = session_process_buf(inst, &buf->vb);
if (ret)
return_buf_error(inst, &buf->vb);
list_del_init(&buf->ref_list);
}
unlock:
mutex_unlock(&inst->lock);
}
void venus_helper_release_buf_ref(struct venus_inst *inst, unsigned int idx)
{
struct venus_buffer *buf;
list_for_each_entry(buf, &inst->registeredbufs, reg_list) {
if (buf->vb.vb2_buf.index == idx) {
buf->flags &= ~HFI_BUFFERFLAG_READONLY;
schedule_work(&inst->delayed_process_work);
break;
}
}
}
EXPORT_SYMBOL_GPL(venus_helper_release_buf_ref);
void venus_helper_acquire_buf_ref(struct vb2_v4l2_buffer *vbuf)
{
struct venus_buffer *buf = to_venus_buffer(vbuf);
buf->flags |= HFI_BUFFERFLAG_READONLY;
}
EXPORT_SYMBOL_GPL(venus_helper_acquire_buf_ref);
static int is_buf_refed(struct venus_inst *inst, struct vb2_v4l2_buffer *vbuf)
{
struct venus_buffer *buf = to_venus_buffer(vbuf);
if (buf->flags & HFI_BUFFERFLAG_READONLY) {
list_add_tail(&buf->ref_list, &inst->delayed_process);
schedule_work(&inst->delayed_process_work);
return 1;
}
return 0;
}
struct vb2_v4l2_buffer *
venus_helper_find_buf(struct venus_inst *inst, unsigned int type, u32 idx)
{
struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx;
if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
return v4l2_m2m_src_buf_remove_by_idx(m2m_ctx, idx);
else
return v4l2_m2m_dst_buf_remove_by_idx(m2m_ctx, idx);
}
EXPORT_SYMBOL_GPL(venus_helper_find_buf);
int venus_helper_vb2_buf_init(struct vb2_buffer *vb)
{
struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue);
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct venus_buffer *buf = to_venus_buffer(vbuf);
struct sg_table *sgt;
sgt = vb2_dma_sg_plane_desc(vb, 0);
if (!sgt)
return -EFAULT;
buf->size = vb2_plane_size(vb, 0);
buf->dma_addr = sg_dma_address(sgt->sgl);
if (vb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
list_add_tail(&buf->reg_list, &inst->registeredbufs);
return 0;
}
EXPORT_SYMBOL_GPL(venus_helper_vb2_buf_init);
int venus_helper_vb2_buf_prepare(struct vb2_buffer *vb)
{
struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue);
if (vb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
vb2_plane_size(vb, 0) < inst->output_buf_size)
return -EINVAL;
if (vb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE &&
vb2_plane_size(vb, 0) < inst->input_buf_size)
return -EINVAL;
return 0;
}
EXPORT_SYMBOL_GPL(venus_helper_vb2_buf_prepare);
void venus_helper_vb2_buf_queue(struct vb2_buffer *vb)
{
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue);
struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx;
int ret;
mutex_lock(&inst->lock);
if (inst->cmd_stop) {
vbuf->flags |= V4L2_BUF_FLAG_LAST;
v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_DONE);
inst->cmd_stop = false;
goto unlock;
}
v4l2_m2m_buf_queue(m2m_ctx, vbuf);
if (!(inst->streamon_out & inst->streamon_cap))
goto unlock;
ret = is_buf_refed(inst, vbuf);
if (ret)
goto unlock;
ret = session_process_buf(inst, vbuf);
if (ret)
return_buf_error(inst, vbuf);
unlock:
mutex_unlock(&inst->lock);
}
EXPORT_SYMBOL_GPL(venus_helper_vb2_buf_queue);
void venus_helper_buffers_done(struct venus_inst *inst,
enum vb2_buffer_state state)
{
struct vb2_v4l2_buffer *buf;
while ((buf = v4l2_m2m_src_buf_remove(inst->m2m_ctx)))
v4l2_m2m_buf_done(buf, state);
while ((buf = v4l2_m2m_dst_buf_remove(inst->m2m_ctx)))
v4l2_m2m_buf_done(buf, state);
}
EXPORT_SYMBOL_GPL(venus_helper_buffers_done);
void venus_helper_vb2_stop_streaming(struct vb2_queue *q)
{
struct venus_inst *inst = vb2_get_drv_priv(q);
struct venus_core *core = inst->core;
int ret;
mutex_lock(&inst->lock);
if (inst->streamon_out & inst->streamon_cap) {
ret = hfi_session_stop(inst);
ret |= hfi_session_unload_res(inst);
ret |= session_unregister_bufs(inst);
ret |= intbufs_free(inst);
ret |= hfi_session_deinit(inst);
if (inst->session_error || core->sys_error)
ret = -EIO;
if (ret)
hfi_session_abort(inst);
load_scale_clocks(core);
}
venus_helper_buffers_done(inst, VB2_BUF_STATE_ERROR);
if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
inst->streamon_out = 0;
else
inst->streamon_cap = 0;
mutex_unlock(&inst->lock);
}
EXPORT_SYMBOL_GPL(venus_helper_vb2_stop_streaming);
int venus_helper_vb2_start_streaming(struct venus_inst *inst)
{
struct venus_core *core = inst->core;
int ret;
ret = intbufs_alloc(inst);
if (ret)
return ret;
ret = session_register_bufs(inst);
if (ret)
goto err_bufs_free;
load_scale_clocks(core);
ret = hfi_session_load_res(inst);
if (ret)
goto err_unreg_bufs;
ret = hfi_session_start(inst);
if (ret)
goto err_unload_res;
return 0;
err_unload_res:
hfi_session_unload_res(inst);
err_unreg_bufs:
session_unregister_bufs(inst);
err_bufs_free:
intbufs_free(inst);
return ret;
}
EXPORT_SYMBOL_GPL(venus_helper_vb2_start_streaming);
void venus_helper_m2m_device_run(void *priv)
{
struct venus_inst *inst = priv;
struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx;
struct v4l2_m2m_buffer *buf, *n;
int ret;
mutex_lock(&inst->lock);
v4l2_m2m_for_each_dst_buf_safe(m2m_ctx, buf, n) {
ret = session_process_buf(inst, &buf->vb);
if (ret)
return_buf_error(inst, &buf->vb);
}
v4l2_m2m_for_each_src_buf_safe(m2m_ctx, buf, n) {
ret = session_process_buf(inst, &buf->vb);
if (ret)
return_buf_error(inst, &buf->vb);
}
mutex_unlock(&inst->lock);
}
EXPORT_SYMBOL_GPL(venus_helper_m2m_device_run);
void venus_helper_m2m_job_abort(void *priv)
{
struct venus_inst *inst = priv;
v4l2_m2m_job_finish(inst->m2m_dev, inst->m2m_ctx);
}
EXPORT_SYMBOL_GPL(venus_helper_m2m_job_abort);
void venus_helper_init_instance(struct venus_inst *inst)
{
if (inst->session_type == VIDC_SESSION_TYPE_DEC) {
INIT_LIST_HEAD(&inst->delayed_process);
INIT_WORK(&inst->delayed_process_work,
delayed_process_buf_func);
}
}
EXPORT_SYMBOL_GPL(venus_helper_init_instance);
|