staging: media: wave5: add wave5 codec driver
Subsystems (3)
cover staging: media: wave5: add wave5 codec driver
The wave5 codec is a stateful encoder/decoder.
It is found on the JH7100 SoC.
The driver currently supports V4L2_PIX_FMT_HEVC, V4L2_PIX_FMT_H264.
This driver has so far been tested on pre-silicon FPGA and on the beta BeagleV board which uses the StarFive JH7100 beta SoC.
Testing on FPGA shows it working fine, though the FPGA uses polled interrupts and copied buffers between the host and it's on board RAM.
Testing on BeagleV shows buffer corruption that is currently attributed to a known silicon issue in the SoC that makes the cache coherent interconnect not so coherent.
This can likely be solved when the riscv non-coherent dma support lands and provide optional v4l2 non-contiguous allocator, though it remains to be seen whether support non-coherent use cases will be useful in real world hw.
Until we can test and resolve any issues on final silicon (due 2H 2021) this driver should remain in staging.
We currently tested only the decoder.
Testing the encoder is currently impossible because of the BeagleV buffer problems, That will need to be tested once we have fixed beaglev buffer problems.
v4l2-compliance:
# v4l2-compliance -d0 v4l2-compliance SHA: not available , 64 bits, 64-bit time_t
Compliance test for vpu-dec device /dev/video0:
Driver Info:
Driver name : vpu-dec Card type : vpu-dec Bus info : platform:vpu-dec Driver version : 5.14.0 Capabilities : 0x84204000
Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04204000
Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Detected Stateful Decoder
Required ioctls:
test VIDIOC_QUERYCAP: OK
Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK
test invalid ioctls: OK
Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)
Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 2 Private Controls: 1
Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK (Not Supported) test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK
test Scaling: OK (Not Supported)
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK
Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)
Total for vpu-dec device /dev/video0: 45, Succeeded: 45, Failed: 0, Warnings: 0
Dafna Hirschfeld (4):
staging: media: wave5: Add vpuapi layer
staging: media: wave5: Add the vdi layer
staging: media: wave5: Add the v4l2 layer
staging: wave5: Add TODO file
Robert Beckett (2):
dt-bindings: media: staging: wave5: add yaml devicetree bindings
media: wave5: Add wave5 driver to maintainers file
.../bindings/staging/media/cnm,wave.yaml | 71 + MAINTAINERS | 9 + drivers/staging/media/Kconfig | 2 + drivers/staging/media/Makefile | 1 + drivers/staging/media/wave5/Kconfig | 10 + drivers/staging/media/wave5/Makefile | 10 + drivers/staging/media/wave5/TODO | 42 + drivers/staging/media/wave5/v4l2/vpu.c | 386 ++ drivers/staging/media/wave5/v4l2/vpu.h | 76 + drivers/staging/media/wave5/v4l2/vpu_dec.c | 1393 +++++++ drivers/staging/media/wave5/v4l2/vpu_dec.h | 20 + drivers/staging/media/wave5/v4l2/vpu_enc.c | 1580 +++++++ drivers/staging/media/wave5/v4l2/vpu_enc.h | 18 + drivers/staging/media/wave5/vdi/vdi.c | 325 ++ drivers/staging/media/wave5/vdi/vdi.h | 79 + drivers/staging/media/wave5/vpuapi/vpuapi.c | 1094 +++++ drivers/staging/media/wave5/vpuapi/vpuapi.h | 1176 ++++++ .../staging/media/wave5/vpuapi/vpuconfig.h | 81 + drivers/staging/media/wave5/vpuapi/vpuerror.h | 455 +++ .../staging/media/wave5/vpuapi/wave/wave5.c | 3626 +++++++++++++++++ .../staging/media/wave5/vpuapi/wave/wave5.h | 86 + .../media/wave5/vpuapi/wave/wave5_regdefine.h | 638 +++ 22 files changed, 11178 insertions(+) create mode 100644 Documentation/devicetree/bindings/staging/media/cnm,wave.yaml create mode 100644 drivers/staging/media/wave5/Kconfig create mode 100644 drivers/staging/media/wave5/Makefile create mode 100644 drivers/staging/media/wave5/TODO create mode 100644 drivers/staging/media/wave5/v4l2/vpu.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu.h create mode 100644 drivers/staging/media/wave5/v4l2/vpu_dec.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu_dec.h create mode 100644 drivers/staging/media/wave5/v4l2/vpu_enc.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu_enc.h create mode 100644 drivers/staging/media/wave5/vdi/vdi.c create mode 100644 drivers/staging/media/wave5/vdi/vdi.h create mode 100644 drivers/staging/media/wave5/vpuapi/vpuapi.c create mode 100644 drivers/staging/media/wave5/vpuapi/vpuapi.h create mode 100644 drivers/staging/media/wave5/vpuapi/vpuconfig.h create mode 100644 drivers/staging/media/wave5/vpuapi/vpuerror.h create mode 100644 drivers/staging/media/wave5/vpuapi/wave/wave5.c create mode 100644 drivers/staging/media/wave5/vpuapi/wave/wave5.h create mode 100644 drivers/staging/media/wave5/vpuapi/wave/wave5_regdefine.h
Signature · 1 line
2.17.1
PATCH 1/6 staging: media: wave5: Add vpuapi layer
Add the the vpuapi layer of the wave5 codec driver. This layer is used to configure the hardware according to the parameters.
--- drivers/staging/media/wave5/vpuapi/vpuapi.c | 1094 +++++ drivers/staging/media/wave5/vpuapi/vpuapi.h | 1176 ++++++ .../staging/media/wave5/vpuapi/vpuconfig.h | 81 + drivers/staging/media/wave5/vpuapi/vpuerror.h | 455 +++ .../staging/media/wave5/vpuapi/wave/wave5.c | 3626 +++++++++++++++++ .../staging/media/wave5/vpuapi/wave/wave5.h | 86 + .../media/wave5/vpuapi/wave/wave5_regdefine.h | 638 +++ 7 files changed, 7156 insertions(+) create mode 100644 drivers/staging/media/wave5/vpuapi/vpuapi.c create mode 100644 drivers/staging/media/wave5/vpuapi/vpuapi.h create mode 100644 drivers/staging/media/wave5/vpuapi/vpuconfig.h create mode 100644 drivers/staging/media/wave5/vpuapi/vpuerror.h create mode 100644 drivers/staging/media/wave5/vpuapi/wave/wave5.c create mode 100644 drivers/staging/media/wave5/vpuapi/wave/wave5.h create mode 100644 drivers/staging/media/wave5/vpuapi/wave/wave5_regdefine.h
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +1094 -0
@@ -0,0 +1,1094 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - helper functions +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ + +#include <linux/bug.h> +#include "vpuapi.h" +#include "wave/wave5_regdefine.h" +#include "wave/wave5.h" + +#define DECODE_ALL_TEMPORAL_LAYERS -1 +#define DECODE_ALL_SPATIAL_LAYERS -1 + +void vpu_clear_interrupt_ex (struct vpu_instance *inst,int32_t intr_flag) +{ +wave5_vpu_clear_interrupt (inst, intr_flag); +} + +static enum ret_code initialize_vpu (struct device *dev,const uint16_t *code,uint32_t size) +{ +enum ret_code ret; +struct vpu_device *vpu_dev = (struct vpu_device *)dev_get_drvdata (dev); + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + +if (wave5_vpu_is_init (vpu_dev) !=0 ) { +wave5_vpu_re_init (dev, (void *)code, size); + ret =RETCODE_CALLED_BEFORE ; + goto err_out; + } + + ret =wave5_vpu_reset (dev,SW_RESET_ON_BOOT ); +if (ret !=RETCODE_SUCCESS ) + goto err_out; + + ret =wave5_vpu_init (dev, (void *)code, size); + +err_out: +mutex_unlock (&vpu_dev->hw_lock); +return ret; +} + +enum ret_code vpu_init_with_bitcode (struct device *dev,const uint16_t *code,uint32_t size) +{ +if (!code || size ==0 ) +return RETCODE_INVALID_PARAM ; + +return initialize_vpu (dev, code, size); +} + +enum ret_code vpu_get_version_info (struct device *dev,uint32_t *version_info, +u32 *revision,uint32_t *product_id) +{ +enum ret_code ret; +struct vpu_device *vpu_dev = (struct vpu_device *)dev_get_drvdata (dev); + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + +if (wave5_vpu_is_init (vpu_dev) ==0 ) { + ret =RETCODE_NOT_INITIALIZED ; + goto err_out; + } + +if (product_id) + *product_id = vpu_dev->product; + ret =wave5_vpu_get_version (vpu_dev, version_info, revision); + +err_out: +mutex_unlock (&vpu_dev->hw_lock); +return ret; +} + +static int check_dec_open_param (struct vpu_device *dev,struct dec_open_param *param) +{ +struct vpu_attr *p_attr; + +if (param ==0 ) +return -EINVAL ; + + p_attr = &dev->attr; + +if (param->bitstream_buffer %8 ) +return -EINVAL ; + +if (param->bitstream_mode ==BS_MODE_INTERRUPT ) { +if (param->bitstream_buffer_size %1024 || param->bitstream_buffer_size <1024 ) +return -EINVAL ; + } + +// check bitstream mode +if ((p_attr->support_bitstream_mode & (1 << param->bitstream_mode)) ==0 ) +return -EINVAL ; + +/* check framebuffer endian */ +if ((p_attr->support_endian_mask & (1 << param->frame_endian)) ==0 ) +return -EINVAL ; + +/* check streambuffer endian */ +if ((p_attr->support_endian_mask & (1 << param->stream_endian)) ==0 ) +return -EINVAL ; + +return 0 ; +} + +int vpu_dec_open_api (struct vpu_instance *vpu_inst,struct dec_open_param *pop) +{ +struct dec_info *p_dec_info; +int ret; +struct vpu_device *vpu_dev = vpu_inst->dev; + + ret =check_dec_open_param (vpu_dev, pop); +if (ret !=0 ) +return ret; + + ret =mutex_lock_interruptible (&vpu_dev->hw_lock); +if (ret) +return ret; + +if (wave5_vpu_is_init (vpu_dev) ==0 ) { + ret = -ENODEV ; + goto err_out; + } + + vpu_inst->codec_info =kzalloc (sizeof (*vpu_inst->codec_info),GFP_KERNEL ); +if (!vpu_inst->codec_info) { + ret = -ENOMEM ; + goto err_out; + } + + vpu_inst->id =ida_alloc_max (&vpu_inst->dev->inst_ida,MAX_NUM_INSTANCE -1 ,GFP_KERNEL ); +if (vpu_inst->id <0 ) { +dev_warn (vpu_inst->dev->dev,"unable to allocate instance ID: %d\n" , vpu_inst->id); + ret = vpu_inst->id; + goto err_out; + } + p_dec_info = &vpu_inst->codec_info->dec_info; +memcpy ((void *)&p_dec_info->open_param, pop,sizeof (struct dec_open_param )); + +if (vpu_inst->std ==STD_UNKNOWN ) { + ret = -EINVAL ; + goto err_out; + } + + p_dec_info->stream_wr_ptr = pop->bitstream_buffer; + p_dec_info->stream_rd_ptr = pop->bitstream_buffer; + p_dec_info->stream_buf_start_addr = pop->bitstream_buffer; + p_dec_info->stream_buf_size = pop->bitstream_buffer_size; + p_dec_info->stream_buf_end_addr = pop->bitstream_buffer + pop->bitstream_buffer_size; + p_dec_info->reorder_enable = TRUE; + p_dec_info->mirror_direction =MIRDIR_NONE ; + p_dec_info->temp_id_select_mode =TEMPORAL_ID_MODE_ABSOLUTE ; + p_dec_info->target_temp_id =DECODE_ALL_TEMPORAL_LAYERS ; + p_dec_info->target_spatial_id =DECODE_ALL_SPATIAL_LAYERS ; + + ret =wave5_vpu_build_up_dec_param (vpu_inst, pop); +if (ret !=RETCODE_SUCCESS ) + goto err_out; + +mutex_unlock (&vpu_dev->hw_lock); + +return 0 ; + +err_out: +if (vpu_inst->id >=0 ) +ida_free (&vpu_inst->dev->inst_ida, vpu_inst->id); +kfree (vpu_inst->codec_info); +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_close (struct vpu_instance *inst) +{ +struct dec_info *p_dec_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; +int i; + +if (!inst->codec_info) +return RETCODE_INVALID_HANDLE ; + p_dec_info = &inst->codec_info->dec_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_dec_fini_seq (inst); +if (ret !=RETCODE_SUCCESS ) { +dev_warn (inst->dev->dev,"dec sec end timed out\n" ); + +if (ret ==RETCODE_VPU_STILL_RUNNING ) { +mutex_unlock (&vpu_dev->hw_lock); +return ret; + } + } + +dev_dbg (inst->dev->dev,"dec seq end complete\n" ); + +if (p_dec_info->vb_work.size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_work); + +for (i =0 ; i <MAX_REG_FRAME ; i++) { +if (p_dec_info->vb_mv[i].size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_mv[i]); +if (p_dec_info->vb_fbc_y_tbl[i].size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_fbc_y_tbl[i]); +if (p_dec_info->vb_fbc_c_tbl[i].size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_fbc_c_tbl[i]); + } + +if (p_dec_info->vb_task.size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_task); + +if (inst->id >=0 ) +ida_free (&inst->dev->inst_ida, inst->id); + +mutex_unlock (&vpu_dev->hw_lock); + +kfree (inst->codec_info); + +return ret; +} + +enum ret_code vpu_dec_issue_seq_init (struct vpu_instance *inst) +{ +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_dec_init_seq (inst); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_complete_seq_init (struct vpu_instance *inst,struct dec_initial_info *info) +{ +struct dec_info *p_dec_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (info ==0 ) +return RETCODE_INVALID_PARAM ; + + p_dec_info = &inst->codec_info->dec_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_dec_get_seq_info (inst, info); +if (ret ==RETCODE_SUCCESS ) + p_dec_info->initial_info_obtained =1 ; + + info->rd_ptr =wave5_vpu_dec_get_rd_ptr (inst); + info->wr_ptr = p_dec_info->stream_wr_ptr; + + p_dec_info->initial_info = *info; + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_register_frame_buffer_ex (struct vpu_instance *inst, +int num_fbs_for_decoding,int num_fbs_for_wtl, +int stride,int height,int map_type) +{ +struct dec_info *p_dec_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; +struct frame_buffer *fb; + +if (num_fbs_for_decoding >MAX_GDI_IDX ) +return RETCODE_INVALID_PARAM ; + +if (num_fbs_for_wtl >MAX_GDI_IDX ) +return RETCODE_INVALID_PARAM ; + + p_dec_info = &inst->codec_info->dec_info; + p_dec_info->num_fbs_for_decoding = num_fbs_for_decoding; + p_dec_info->num_fbs_for_wtl = num_fbs_for_wtl; + p_dec_info->stride = stride; + +if (!p_dec_info->initial_info_obtained) +return RETCODE_WRONG_CALL_SEQUENCE ; + +if (stride < p_dec_info->initial_info.pic_width || (stride %8 !=0 ) || + height < p_dec_info->initial_info.pic_height) +return RETCODE_INVALID_STRIDE ; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + fb = inst->frame_buf; + ret =wave5_vpu_dec_register_framebuffer (inst, &fb[p_dec_info->num_fbs_for_decoding], +LINEAR_FRAME_MAP , p_dec_info->num_fbs_for_wtl); +if (ret !=RETCODE_SUCCESS ) + goto err_out; + + ret =wave5_vpu_dec_register_framebuffer (inst, &fb[0 ], +COMPRESSED_FRAME_MAP , p_dec_info->num_fbs_for_decoding); + +err_out: +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_get_bitstream_buffer (struct vpu_instance *inst,dma_addr_t *prd_ptr, +dma_addr_t *pwr_ptr,uint32_t *size) +{ +struct dec_info *p_dec_info; +dma_addr_t rd_ptr; +dma_addr_t wr_ptr; +dma_addr_t temp_ptr; +int room; +struct vpu_attr *p_attr; +struct vpu_device *vpu_dev = inst->dev; + + p_attr = &vpu_dev->attr; + p_dec_info = &inst->codec_info->dec_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + rd_ptr =wave5_vpu_dec_get_rd_ptr (inst); +mutex_unlock (&vpu_dev->hw_lock); + + wr_ptr = p_dec_info->stream_wr_ptr; + + temp_ptr = rd_ptr; + +if (p_dec_info->open_param.bitstream_mode !=BS_MODE_PIC_END ) { +if (wr_ptr < temp_ptr) + room = temp_ptr - wr_ptr; +else + room = (p_dec_info->stream_buf_end_addr - wr_ptr) + + (temp_ptr - p_dec_info->stream_buf_start_addr); + room--; + }else { + room = (p_dec_info->stream_buf_end_addr - wr_ptr); + } + +if (prd_ptr) + *prd_ptr = temp_ptr; +if (pwr_ptr) + *pwr_ptr = wr_ptr; +if (size) + *size = room; + +return RETCODE_SUCCESS ; +} + +enum ret_code vpu_dec_update_bitstream_buffer (struct vpu_instance *inst,int size) +{ +struct dec_info *p_dec_info; +dma_addr_t wr_ptr; +dma_addr_t rd_ptr; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (!inst->codec_info) +return RETCODE_INVALID_HANDLE ; + + p_dec_info = &inst->codec_info->dec_info; + wr_ptr = p_dec_info->stream_wr_ptr; + rd_ptr = p_dec_info->stream_rd_ptr; + +if (size >0 ) { +if (wr_ptr < rd_ptr && rd_ptr <= wr_ptr + size) +return RETCODE_INVALID_PARAM ; + + wr_ptr += size; + +if (p_dec_info->open_param.bitstream_mode !=BS_MODE_PIC_END ) { +if (wr_ptr > p_dec_info->stream_buf_end_addr) { +u32 room = wr_ptr - p_dec_info->stream_buf_end_addr; + + wr_ptr = p_dec_info->stream_buf_start_addr; + wr_ptr += room; + }else if (wr_ptr == p_dec_info->stream_buf_end_addr) { + wr_ptr = p_dec_info->stream_buf_start_addr; + } + } + + p_dec_info->stream_wr_ptr = wr_ptr; + p_dec_info->stream_rd_ptr = rd_ptr; + } + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + ret =wave5_vpu_dec_set_bitstream_flag (inst, (size ==0 )); +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_start_one_frame (struct vpu_instance *inst,struct dec_param *param) +{ +struct dec_info *p_dec_info; +enum ret_code ret =RETCODE_SUCCESS ; +struct vpu_device *vpu_dev = inst->dev; + + p_dec_info = &inst->codec_info->dec_info; + +if (p_dec_info->stride ==0 )// this means frame buffers have not been registered. +return RETCODE_WRONG_CALL_SEQUENCE ; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + p_dec_info->frame_start_pos = p_dec_info->stream_rd_ptr; + + ret =wave5_vpu_decode (inst, param); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_get_output_info (struct vpu_instance *inst,struct dec_output_info *info) +{ +struct dec_info *p_dec_info; +enum ret_code ret; +struct vpu_rect rect_info; +u32 val; +s32 decoded_index; +s32 disp_idx; +u32 max_dec_index; +struct vpu_device *vpu_dev = inst->dev; + +if (info ==0 ) +return RETCODE_INVALID_PARAM ; + + p_dec_info = &inst->codec_info->dec_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + +memset ((void *)info,0x00 ,sizeof (struct dec_output_info )); + + ret =wave5_vpu_dec_get_result (inst, info); +if (ret !=RETCODE_SUCCESS ) { + info->rd_ptr = p_dec_info->stream_rd_ptr; + info->wr_ptr = p_dec_info->stream_wr_ptr; + goto err_out; + } + + decoded_index = info->index_frame_decoded; + +// calculate display frame region + val =0 ; +if (decoded_index >=0 && decoded_index <MAX_GDI_IDX ) { +//default value + rect_info.left =0 ; + rect_info.right = info->dec_pic_width; + rect_info.top =0 ; + rect_info.bottom = info->dec_pic_height; + +if (inst->std ==W_HEVC_DEC || inst->std ==W_AVC_DEC ) + rect_info = p_dec_info->initial_info.pic_crop_rect; + +if (inst->std ==W_HEVC_DEC ) + p_dec_info->dec_out_info[decoded_index].decoded_poc = info->decoded_poc; + +if (inst->std ==W_AVS2_DEC ) + p_dec_info->dec_out_info[decoded_index].avs2_info.decoded_poi = + info->avs2_info.decoded_poi; + + info->rc_decoded.left = rect_info.left; + p_dec_info->dec_out_info[decoded_index].rc_decoded.left = rect_info.left; + info->rc_decoded.right = rect_info.right; + p_dec_info->dec_out_info[decoded_index].rc_decoded.right = rect_info.right; + info->rc_decoded.top = rect_info.top; + p_dec_info->dec_out_info[decoded_index].rc_decoded.top = rect_info.top; + info->rc_decoded.bottom = rect_info.bottom; + p_dec_info->dec_out_info[decoded_index].rc_decoded.bottom = rect_info.bottom; + }else { + info->rc_decoded.left =0 ; + info->rc_decoded.right = info->dec_pic_width; + info->rc_decoded.top =0 ; + info->rc_decoded.bottom = info->dec_pic_height; + } + + disp_idx = info->index_frame_display; +if (info->index_frame_display >=0 && info->index_frame_display <MAX_GDI_IDX ) { +if (p_dec_info->rotation_enable) { +switch (p_dec_info->rotation_angle) { +case 90 : + info->rc_display.left = + p_dec_info->dec_out_info[disp_idx].rc_decoded.top; + info->rc_display.right = + p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; + info->rc_display.top = + p_dec_info->dec_out_info[disp_idx].dec_pic_width - + p_dec_info->dec_out_info[disp_idx].rc_decoded.right; + info->rc_display.bottom = + p_dec_info->dec_out_info[disp_idx].dec_pic_width - + p_dec_info->dec_out_info[disp_idx].rc_decoded.left; +break ; +case 270 : + info->rc_display.left = + p_dec_info->dec_out_info[disp_idx].dec_pic_height - + p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; + info->rc_display.right = + p_dec_info->dec_out_info[disp_idx].dec_pic_height - + p_dec_info->dec_out_info[disp_idx].rc_decoded.top; + info->rc_display.top = + p_dec_info->dec_out_info[disp_idx].rc_decoded.left; + info->rc_display.bottom = + p_dec_info->dec_out_info[disp_idx].rc_decoded.right; +break ; +case 180 : + info->rc_display.left = + p_dec_info->dec_out_info[disp_idx].rc_decoded.left; + info->rc_display.right = + p_dec_info->dec_out_info[disp_idx].rc_decoded.right; + info->rc_display.top = + p_dec_info->dec_out_info[disp_idx].dec_pic_height - + p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; + info->rc_display.bottom = + p_dec_info->dec_out_info[disp_idx].dec_pic_height - + p_dec_info->dec_out_info[disp_idx].rc_decoded.top; +break ; +default : + info->rc_display.left = + p_dec_info->dec_out_info[disp_idx].rc_decoded.left; + info->rc_display.right = + p_dec_info->dec_out_info[disp_idx].rc_decoded.right; + info->rc_display.top = + p_dec_info->dec_out_info[disp_idx].rc_decoded.top; + info->rc_display.bottom = + p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; +break ; + } + + }else { + info->rc_display.left = p_dec_info->dec_out_info[disp_idx].rc_decoded.left; + info->rc_display.right = p_dec_info->dec_out_info[disp_idx].rc_decoded.right; + info->rc_display.top = p_dec_info->dec_out_info[disp_idx].rc_decoded.top; + info->rc_display.bottom = p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; + } + +if (p_dec_info->mirror_enable) { +u32 temp; +u32 width = (p_dec_info->rotation_angle ==90 || + p_dec_info->rotation_angle ==270 ) ? info->dec_pic_height : + info->dec_pic_width; +u32 height = (p_dec_info->rotation_angle ==90 || + p_dec_info->rotation_angle ==270 ) ? info->dec_pic_width : + info->dec_pic_height; + +if (p_dec_info->mirror_direction &MIRDIR_VER ) { + temp = info->rc_display.top; + info->rc_display.top = height - info->rc_display.bottom; + info->rc_display.bottom = height - temp; + } +if (p_dec_info->mirror_direction &MIRDIR_HOR ) { + temp = info->rc_display.left; + info->rc_display.left = width - info->rc_display.right; + info->rc_display.right = width - temp; + } + } + +switch (inst->std) { +case W_HEVC_DEC : + info->display_poc = p_dec_info->dec_out_info[disp_idx].decoded_poc; +break ; +case W_AVS2_DEC : + info->avs2_info.display_poi = p_dec_info->dec_out_info[disp_idx].avs2_info.decoded_poi; +break ; +case W_AVC_DEC : + info->display_poc = p_dec_info->dec_out_info[disp_idx].decoded_poc; +break ; +default : +break ; + } + +if (info->index_frame_display == info->index_frame_decoded) { + info->disp_pic_width = info->dec_pic_width; + info->disp_pic_height = info->dec_pic_height; + }else { +/* +* when index_frame_decoded < 0, and index_frame_display >= 0 +* info->dec_pic_width and info->dec_pic_height are still valid +* but those of p_dec_info->dec_out_info[disp_idx] are invalid in VP9 +*/ + info->disp_pic_width = p_dec_info->dec_out_info[disp_idx].dec_pic_width; + info->disp_pic_height = p_dec_info->dec_out_info[disp_idx].dec_pic_height; + } + + }else { + info->rc_display.left =0 ; + info->rc_display.right =0 ; + info->rc_display.top =0 ; + info->rc_display.bottom =0 ; + +if (p_dec_info->rotation_enable || p_dec_info->mirror_enable || + p_dec_info->dering_enable) { + info->disp_pic_width = info->dec_pic_width; + info->disp_pic_height = info->dec_pic_height; + }else { + info->disp_pic_width =0 ; + info->disp_pic_height =0 ; + } + } + + p_dec_info->stream_rd_ptr =wave5_vpu_dec_get_rd_ptr (inst); + p_dec_info->frame_display_flag =vpu_read_reg (vpu_dev,W5_RET_DEC_DISP_IDC ); +if (inst->std ==W_VP9_DEC ) + p_dec_info->frame_display_flag &=0xFFFF ; + p_dec_info->frame_end_pos = p_dec_info->stream_rd_ptr; + +if (p_dec_info->frame_end_pos < p_dec_info->frame_start_pos) + info->consumed_byte = p_dec_info->frame_end_pos + p_dec_info->stream_buf_size - + p_dec_info->frame_start_pos; +else + info->consumed_byte = p_dec_info->frame_end_pos - p_dec_info->frame_start_pos; + +if (p_dec_info->dering_enable || p_dec_info->mirror_enable || p_dec_info->rotation_enable) { + info->disp_frame = p_dec_info->rotator_output; + info->disp_frame.stride = p_dec_info->rotator_stride; + }else { + val = p_dec_info->num_fbs_for_decoding;//fb_offset + + max_dec_index = (p_dec_info->num_fbs_for_decoding > p_dec_info->num_fbs_for_wtl) ? + p_dec_info->num_fbs_for_decoding : p_dec_info->num_fbs_for_wtl; + +if (info->index_frame_display >=0 && info->index_frame_display < (int )max_dec_index) + info->disp_frame = inst->frame_buf[val + info->index_frame_display]; + } + + info->rd_ptr = p_dec_info->stream_rd_ptr; + info->wr_ptr = p_dec_info->stream_wr_ptr; + info->frame_display_flag = p_dec_info->frame_display_flag; + + info->sequence_no = p_dec_info->initial_info.sequence_no; +if (decoded_index >=0 && decoded_index <MAX_GDI_IDX ) + p_dec_info->dec_out_info[decoded_index] = *info; + +if (disp_idx >=0 && disp_idx <MAX_GDI_IDX ) { + info->num_of_tot_m_bs_in_display = p_dec_info->dec_out_info[disp_idx].num_of_tot_m_bs; + info->num_of_err_m_bs_in_display = p_dec_info->dec_out_info[disp_idx].num_of_err_m_bs; + info->disp_frame.sequence_no = info->sequence_no; + }else { + info->num_of_tot_m_bs_in_display =0 ; + info->num_of_err_m_bs_in_display =0 ; + } + +if (info->sequence_changed !=0 ) { +if ((info->sequence_changed &SEQ_CHANGE_INTER_RES_CHANGE ) !=SEQ_CHANGE_INTER_RES_CHANGE ) + p_dec_info->initial_info.sequence_no++; + } + +err_out: +mutex_unlock (&vpu_dev->hw_lock); + +return RETCODE_SUCCESS ; +} + +enum ret_code vpu_dec_clr_disp_flag (struct vpu_instance *inst,int index) +{ +struct dec_info *p_dec_info; +enum ret_code ret =RETCODE_SUCCESS ; +s32 end_index; +struct vpu_device *vpu_dev = inst->dev; + + p_dec_info = &inst->codec_info->dec_info; + + end_index = p_dec_info->num_fbs_for_wtl; + +if (index <0 || index > end_index -1 ) +return RETCODE_INVALID_PARAM ; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + ret =wave5_dec_clr_disp_flag (inst, index); +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_give_command (struct vpu_instance *inst,enum codec_command cmd,void *param) +{ +struct dec_info *p_dec_info; + + p_dec_info = &inst->codec_info->dec_info; +switch (cmd) { +case DEC_GET_QUEUE_STATUS : + { +struct queue_status_info *queue_info = (struct queue_status_info *)param; + + queue_info->instance_queue_count = p_dec_info->instance_queue_count; + queue_info->report_queue_count = p_dec_info->report_queue_count; +break ; + } + +case ENABLE_DEC_THUMBNAIL_MODE : + { + p_dec_info->thumbnail_mode =1 ; +break ; + } +default : +return RETCODE_INVALID_COMMAND ; + } + +return 0 ; +} + +int vpu_enc_open_api (struct vpu_instance *vpu_inst,struct enc_open_param *pop) +{ +struct enc_info *p_enc_info; +int ret; +struct vpu_device *vpu_dev = vpu_inst->dev; + + ret =wave5_vpu_enc_check_open_param (vpu_inst, pop); +if (ret !=RETCODE_SUCCESS ) +return ret; + + ret =mutex_lock_interruptible (&vpu_dev->hw_lock); +if (ret) +return ret; + +if (wave5_vpu_is_init (vpu_dev) ==0 ) { + ret = -ENODEV ; + goto err_out; + } + + vpu_inst->codec_info =kzalloc (sizeof (vpu_inst->codec_info),GFP_KERNEL ); +if (!vpu_inst->codec_info) { + ret = -ENOMEM ; + goto err_out; + } + + vpu_inst->id =ida_alloc_max (&vpu_inst->dev->inst_ida,MAX_NUM_INSTANCE -1 ,GFP_KERNEL ); +if (vpu_inst->id <0 ) { +dev_warn (vpu_inst->dev->dev,"unable to allocate instance ID: %d\n" , vpu_inst->id); + ret = vpu_inst->id; + goto err_out; + } + p_enc_info = &vpu_inst->codec_info->enc_info; + p_enc_info->open_param = *pop; + + ret =wave5_vpu_build_up_enc_param (vpu_dev->dev, vpu_inst, pop); +if (ret !=RETCODE_SUCCESS ) + goto err_out; +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +err_out: +if (vpu_inst->id >=0 ) +ida_free (&vpu_inst->dev->inst_ida, vpu_inst->id); +kfree (vpu_inst->codec_info); +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_enc_close (struct vpu_instance *inst) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (!inst->codec_info) +return RETCODE_INVALID_HANDLE ; + p_enc_info = &inst->codec_info->enc_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_enc_fini_seq (inst); +if (ret !=RETCODE_SUCCESS ) { +dev_warn (inst->dev->dev,"enc seq end timed out\n" ); + +if (ret ==RETCODE_VPU_STILL_RUNNING ) { +mutex_unlock (&vpu_dev->hw_lock); +return ret; + } + } + +dev_dbg (inst->dev->dev,"enc seq end timed out\n" ); + +if (p_enc_info->vb_work.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_work); + +if (inst->std ==W_HEVC_ENC || inst->std ==W_AVC_ENC ) { +if (p_enc_info->vb_sub_sam_buf.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_sub_sam_buf); + +if (p_enc_info->vb_mv.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_mv); + +if (p_enc_info->vb_fbc_y_tbl.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_fbc_y_tbl); + +if (p_enc_info->vb_fbc_c_tbl.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_fbc_c_tbl); + } + +if (p_enc_info->vb_task.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_task); + +if (inst->id >=0 ) +ida_free (&inst->dev->inst_ida, inst->id); + +mutex_unlock (&vpu_dev->hw_lock); + +kfree (inst->codec_info); + +return ret; +} + +enum ret_code vpu_enc_register_frame_buffer (struct vpu_instance *inst,int num,int stride, +int height,enum tiled_map_type map_type) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct enc_open_param *open_param; +struct frame_buffer *fb; +struct vpu_device *vpu_dev = inst->dev; +u32 size_luma, size_chroma; +int i; + + p_enc_info = &inst->codec_info->enc_info; + open_param = &p_enc_info->open_param; + +if (p_enc_info->stride) +return RETCODE_CALLED_BEFORE ; + +if (!p_enc_info->initial_info_obtained) +return RETCODE_WRONG_CALL_SEQUENCE ; + +if (num < p_enc_info->initial_info.min_frame_buffer_count) +return RETCODE_INSUFFICIENT_FRAME_BUFFERS ; + +if (stride ==0 || (stride %8 !=0 ) || stride <0 ) +return RETCODE_INVALID_STRIDE ; + +if (height ==0 || height <0 ) +return RETCODE_INVALID_PARAM ; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + p_enc_info->num_frame_buffers = num; + p_enc_info->stride = stride; + + fb = inst->frame_buf; + size_luma = stride * height; + size_chroma =ALIGN (stride /2 ,16 ) * height; + +for (i =0 ; i < num; i++) { +if (fb[i].update_fb_info) { + fb[i].update_fb_info = FALSE; + fb[i].stride = stride; + fb[i].height = height; + fb[i].map_type =COMPRESSED_FRAME_MAP ; + fb[i].cbcr_interleave = true; + fb[i].endian =VDI_128BIT_LITTLE_ENDIAN ; + fb[i].buf_y_size = size_luma; + fb[i].buf_cb = fb[i].buf_y + size_luma; + fb[i].buf_cb_size = size_chroma; + fb[i].buf_cr_size =0 ; + } + } + + ret =wave5_vpu_enc_register_framebuffer (inst->dev->dev, inst, &fb[0 ], +COMPRESSED_FRAME_MAP , p_enc_info->num_frame_buffers); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +static enum ret_code check_enc_param (struct vpu_instance *inst,struct enc_param *param) +{ +struct enc_info *p_enc_info; + + p_enc_info = &inst->codec_info->enc_info; + +if (param ==0 ) +return RETCODE_INVALID_PARAM ; + +if (param->skip_picture !=0 && param->skip_picture !=1 ) +return RETCODE_INVALID_PARAM ; +if (param->skip_picture ==0 ) { +if (param->source_frame ==0 ) +return RETCODE_INVALID_FRAME_BUFFER ; + } +if (p_enc_info->open_param.bit_rate ==0 ) {// no rate control +if (inst->std ==W_HEVC_ENC ) { +if (param->force_pic_qp_enable ==1 ) { +if (param->force_pic_qp_i <0 || param->force_pic_qp_i >63 ) +return RETCODE_INVALID_PARAM ; + +if (param->force_pic_qp_p <0 || param->force_pic_qp_p >63 ) +return RETCODE_INVALID_PARAM ; + +if (param->force_pic_qp_b <0 || param->force_pic_qp_b >63 ) +return RETCODE_INVALID_PARAM ; + } +if (p_enc_info->ring_buffer_enable ==0 ) { +if (param->pic_stream_buffer_addr %16 || param->pic_stream_buffer_size ==0 ) +return RETCODE_INVALID_PARAM ; + } + } + } +if (p_enc_info->ring_buffer_enable ==0 ) { +if (param->pic_stream_buffer_addr %8 || param->pic_stream_buffer_size ==0 ) +return RETCODE_INVALID_PARAM ; + } + +return RETCODE_SUCCESS ; +} + +static uint64_t get_timestamp (struct vpu_instance *vpu_inst) +{ +struct enc_info *p_enc_info =NULL ; +u64 pts; +u32 fps; + +if (!vpu_inst->codec_info) +return 0 ; + + p_enc_info = &vpu_inst->codec_info->enc_info; + fps = p_enc_info->open_param.frame_rate_info; +if (fps ==0 ) + fps =30 ;/* 30 fps */ + + pts = p_enc_info->cur_pts; + p_enc_info->cur_pts +=90000 / fps;/* 90_k_hz/fps */ + +return pts; +} + +enum ret_code vpu_enc_start_one_frame (struct vpu_instance *inst,struct enc_param *param) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + + p_enc_info = &inst->codec_info->enc_info; + +if (p_enc_info->stride ==0 )// this means frame buffers have not been registered. +return RETCODE_WRONG_CALL_SEQUENCE ; + + ret =check_enc_param (inst, param); +if (ret !=RETCODE_SUCCESS ) +return ret; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + p_enc_info->pts_map[param->src_idx] = p_enc_info->open_param.enable_pts ?get_timestamp (inst) : param->pts; + + ret =wave5_vpu_encode (inst, param); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_enc_get_output_info (struct vpu_instance *inst,struct enc_output_info *info) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (info ==0 ) +return RETCODE_INVALID_PARAM ; + + p_enc_info = &inst->codec_info->enc_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_enc_get_result (inst, info); + +if (ret ==RETCODE_SUCCESS ) { +if (info->enc_src_idx >=0 && info->recon_frame_index >=0 ) + info->pts = p_enc_info->pts_map[info->enc_src_idx]; + }else { + info->pts =0LL ; + } + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_enc_give_command (struct vpu_instance *inst,enum codec_command cmd,void *param) +{ +struct enc_info *p_enc_info; + + p_enc_info = &inst->codec_info->enc_info; +switch (cmd) { +case ENABLE_ROTATION : + { + p_enc_info->rotation_enable =1 ; + } +break ; +case ENABLE_MIRRORING : + { + p_enc_info->mirror_enable =1 ; + } +break ; +case SET_MIRROR_DIRECTION : + { +enum mirror_direction mir_dir; + +if (param ==0 ) +return RETCODE_INVALID_PARAM ; + + mir_dir = *(enum mirror_direction *)param; +if (!(mir_dir ==MIRDIR_NONE ) && !(mir_dir ==MIRDIR_HOR ) && + !(mir_dir ==MIRDIR_VER ) && !(mir_dir ==MIRDIR_HOR_VER )) +return RETCODE_INVALID_PARAM ; + p_enc_info->mirror_direction = mir_dir; + } +break ; +case SET_ROTATION_ANGLE : + { +int angle; + +if (param ==0 ) +return RETCODE_INVALID_PARAM ; + angle = *(int *)param; +if (angle !=0 && angle !=90 && angle !=180 && angle !=270 ) +return RETCODE_INVALID_PARAM ; +if (p_enc_info->initial_info_obtained && (angle ==90 || angle ==270 )) +return RETCODE_INVALID_PARAM ; + p_enc_info->rotation_angle = angle; + } +break ; +case ENC_GET_QUEUE_STATUS : + { +struct queue_status_info *queue_info = (struct queue_status_info *)param; + + queue_info->instance_queue_count = p_enc_info->instance_queue_count; + queue_info->report_queue_count = p_enc_info->report_queue_count; +break ; + } +default : +return RETCODE_INVALID_COMMAND ; + } +return RETCODE_SUCCESS ; +} + +enum ret_code vpu_enc_issue_seq_init (struct vpu_instance *inst) +{ +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_enc_init_seq (inst); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_enc_complete_seq_init (struct vpu_instance *inst,struct enc_initial_info *info) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (info ==0 ) +return RETCODE_INVALID_PARAM ; + + p_enc_info = &inst->codec_info->enc_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_enc_get_seq_info (inst, info); +if (ret ==RETCODE_SUCCESS ) + p_enc_info->initial_info_obtained =1 ; + + p_enc_info->initial_info = *info; + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} +
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +1176 -0
1,176 lines not on this page · raw message
drivers/staging/media/wave5/vpuapi/vpuconfig.h new file +81 -0
81 lines not on this page · raw message
drivers/staging/media/wave5/vpuapi/vpuerror.h new file +455 -0
455 lines not on this page · raw message
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +3626 -0
194 lines not on this page · raw message
drivers/staging/media/wave5/vpuapi/wave/wave5.h new file +86 -0
86 lines not on this page · raw message
drivers/staging/media/wave5/vpuapi/wave/wave5_regdefine.h new file +638 -0
638 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH 1/6] staging: media: wave5: Add vpuapi layer
This code needs a lot of clean up. I reviewed random functions in this patch. I tried to give some guidelines to get you started.
The way this code is aligned is kind of painful. There are too many extra spaces around the assignments. It looks bad when people edit at different times and then can't make the alignment work. Also it looks bad when you're reviewing it in email clients. Restrict the complicated alignment to .h files where the UAPI is not going to change regularly.
The types are not consistent either.
I wrote some about error handling bugs. Missing error handling. There were a couple off by one bugs. A wrong sized allocation. Some dead code.
Quoted 1 line · Dafna Hirschfeld
Add the the vpuapi layer of the wave5 codec driver.
^^^^^^^
Run checkpatch.pl --strict on your patch.
Quoted 45 lines
This layer is used to configure the hardware according to the parameters.
Signed-off-by Robert Beckett <[email protected]>Signed-off-by Dafna Hirschfeld <[email protected]>--- drivers/staging/media/wave5/vpuapi/vpuapi.c | 1094 +++++ drivers/staging/media/wave5/vpuapi/vpuapi.h | 1176 ++++++ .../staging/media/wave5/vpuapi/vpuconfig.h | 81 + drivers/staging/media/wave5/vpuapi/vpuerror.h | 455 +++ .../staging/media/wave5/vpuapi/wave/wave5.c | 3626 +++++++++++++++++ .../staging/media/wave5/vpuapi/wave/wave5.h | 86 + .../media/wave5/vpuapi/wave/wave5_regdefine.h | 638 +++ 7 files changed, 7156 insertions(+) create mode 100644 drivers/staging/media/wave5/vpuapi/vpuapi.c create mode 100644 drivers/staging/media/wave5/vpuapi/vpuapi.h create mode 100644 drivers/staging/media/wave5/vpuapi/vpuconfig.h create mode 100644 drivers/staging/media/wave5/vpuapi/vpuerror.h create mode 100644 drivers/staging/media/wave5/vpuapi/wave/wave5.c create mode 100644 drivers/staging/media/wave5/vpuapi/wave/wave5.h create mode 100644 drivers/staging/media/wave5/vpuapi/wave/wave5_regdefine.hdrivers/staging/media/wave5/vpuapi/vpuapi.c new file +17
-0@@ -0,0 +1,1094 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - helper functions +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ + +#include <linux/bug.h> +#include "vpuapi.h" +#include "wave/wave5_regdefine.h" +#include "wave/wave5.h" + +#define DECODE_ALL_TEMPORAL_LAYERS -1 +#define DECODE_ALL_SPATIAL_LAYERS -1 + +void vpu_clear_interrupt_ex (struct vpu_instance *inst,int32_t intr_flag) +{
drivers/staging/media/wave5/vpuapi/vpuapi.c line 27
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+wave5_vpu_clear_interrupt (inst, intr_flag); +} + +static enum ret_code initialize_vpu (struct device *dev,const uint16_t *code,uint32_t size) +{ +enum ret_code ret; +struct vpu_device *vpu_dev = (struct vpu_device *)dev_get_drvdata (dev); + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ;
I hate these error codes a lot. At first I assumed they were something that came from the hardware but this is not a hardware error code... I think the hardware error codes are WAVE5_SYSERR_QUEUEING_FAIL etc. Get rid of these custom error codes and try to keep the WAVE5_ codes as local and isolated as possible.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 32
Quoted 5 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +5
-0+ +if (wave5_vpu_is_init (vpu_dev) !=0 ) { +wave5_vpu_re_init (dev, (void *)code, size); + ret =RETCODE_CALLED_BEFORE ; + goto err_out;
It's always best to avoid "err_out" labels. Those are two words error and out but they don't tell the reader anything useful about what the goto does. "goto unlock;"
err_out labels lead to bugs as we will see below.
Actually this code has a lot of error handling issues. There is a simple way to do clean up which is that you just free the last thing which was allocated.
a = alloc(); if (!a) return -ENOMEM; b = alloc(); if (!b) goto free_a; c = alloc(); if (!c) goto free_b; return 0;
free_b:
free(b); free_c: free(a); return -ENOMEM;
Use good label names. Every function must clean up after itself. Every alloc function needs to have a mirror clean up function. Copy and paste the error handling, delete the labels and add a free(c);
void free()
{
free(c);
free(b);
free(a);
}Quoted 16 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +16
-0+ } + + ret =wave5_vpu_reset (dev,SW_RESET_ON_BOOT ); +if (ret !=RETCODE_SUCCESS ) + goto err_out; + + ret =wave5_vpu_init (dev, (void *)code, size); + +err_out: +mutex_unlock (&vpu_dev->hw_lock); +return ret; +} + +enum ret_code vpu_init_with_bitcode (struct device *dev,const uint16_t *code,uint32_t size) +{ +if (!code || size ==0 )
drivers/staging/media/wave5/vpuapi/vpuapi.c line 58
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+return RETCODE_INVALID_PARAM ; + +return initialize_vpu (dev, code, size); +} + +enum ret_code vpu_get_version_info (struct device *dev,uint32_t *version_info, +u32 *revision,uint32_t *product_id) +{ +enum ret_code ret; +struct vpu_device *vpu_dev = (struct vpu_device *)dev_get_drvdata (dev);
These declarations started out as aligned probably but now they're not. Don't try to align the declarations. It just ends up a mess.
Quoted 16 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +16
-0+ +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + +if (wave5_vpu_is_init (vpu_dev) ==0 ) { + ret =RETCODE_NOT_INITIALIZED ; + goto err_out; + } + +if (product_id) + *product_id = vpu_dev->product; + ret =wave5_vpu_get_version (vpu_dev, version_info, revision); + +err_out: +mutex_unlock (&vpu_dev->hw_lock); +return ret;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 84
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+} + +static int check_dec_open_param (struct vpu_device *dev,struct dec_open_param *param) +{ +struct vpu_attr *p_attr; + +if (param ==0 ) +return -EINVAL ; + + p_attr = &dev->attr;
Delete extra spaces.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 90
Quoted 6 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +6
-0+ +if (param->bitstream_buffer %8 ) +return -EINVAL ; + +if (param->bitstream_mode ==BS_MODE_INTERRUPT ) { +if (param->bitstream_buffer_size %1024 || param->bitstream_buffer_size <1024 )
if (param->bitstream_mode == BS_MODE_INTERRUPT && (param->bitstream_buffer_size == 0 || param->bitstream_buffer_size % 1024) return -EINVAL;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 95
Quoted 5 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +5
-0+return -EINVAL ; + } + +// check bitstream mode +if ((p_attr->support_bitstream_mode & (1 << param->bitstream_mode)) ==0 )
Only use "== 0" when you are talking about a number as number of elements or the size or length of something. The other time when you would use == 0 is with strcmp() functions, because that's idiomatic.
if (strcmp(a, b) == 0) <-- this means a == b if (strcmp(a, b) < 0) <-- this means a < b
In this case we're talking about set/not-set so it would be:
if (!(p_attr->support_bitstream_mode & (1 << param->bitstream_mode)))
drivers/staging/media/wave5/vpuapi/vpuapi.c line 98
Quoted 3 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +3
-0+return -EINVAL ; + +/* check framebuffer endian */
Delete this comment. Actually probably the reason for the comment is that the variable is on the right instead of the left so it's a bit confusing. Flip that around. The variable you're checking always comes first.
if (!(BIT(param->bitstream_mode) & p_attr->support_bitstream_mode) || !(BIT(param->frame_endian) & p_attr->support_endian_mask) !(BIT(param->stream_endian) & p_attr->support_endian_mask)) return -EINVAL;
Quoted 8 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +8
-0+if ((p_attr->support_endian_mask & (1 << param->frame_endian)) ==0 ) +return -EINVAL ; + +/* check streambuffer endian */ +if ((p_attr->support_endian_mask & (1 << param->stream_endian)) ==0 ) +return -EINVAL ; + +return 0 ;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 116
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+} + +int vpu_dec_open_api (struct vpu_instance *vpu_inst,struct dec_open_param *pop) +{ +struct dec_info *p_dec_info; +int ret; +struct vpu_device *vpu_dev = vpu_inst->dev; + + ret =check_dec_open_param (vpu_dev, pop); +if (ret !=0 )
if (ret) return ret;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 123
Quoted 7 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +7
-0+return ret; + + ret =mutex_lock_interruptible (&vpu_dev->hw_lock); +if (ret) +return ret; + +if (wave5_vpu_is_init (vpu_dev) ==0 ) {
if (!wave5_vpu_is_init(vpu_dev)) {drivers/staging/media/wave5/vpuapi/vpuapi.c line 125
Quoted 2 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +2
-0+ ret = -ENODEV ; + goto err_out;
This err_out label is a do everything label. That will cause bugs. Instead of doing everything a goto should just undo the last allocation which succeeded. That way you never free something which has not been allocated. In this case we are trying to free "vpu_inst->id" and that isn't allocated until a few lines later so it will trigger a WARN().
goto unlock;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 131
Quoted 6 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +6
-0+ } + + vpu_inst->codec_info =kzalloc (sizeof (*vpu_inst->codec_info),GFP_KERNEL ); +if (!vpu_inst->codec_info) { + ret = -ENOMEM ; + goto err_out;
This should also be "goto unlock;" because no allocations have succeeded.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 138
Quoted 7 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +7
-0+ } + + vpu_inst->id =ida_alloc_max (&vpu_inst->dev->inst_ida,MAX_NUM_INSTANCE -1 ,GFP_KERNEL ); +if (vpu_inst->id <0 ) { +dev_warn (vpu_inst->dev->dev,"unable to allocate instance ID: %d\n" , vpu_inst->id); + ret = vpu_inst->id; + goto err_out;
goto free_codec_info;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 145
Quoted 7 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +7
-0+ } + p_dec_info = &vpu_inst->codec_info->dec_info; +memcpy ((void *)&p_dec_info->open_param, pop,sizeof (struct dec_open_param )); + +if (vpu_inst->std ==STD_UNKNOWN ) { + ret = -EINVAL ; + goto err_out;
goto free_ida;
Quoted 5 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +5
-0+ } + + p_dec_info->stream_wr_ptr = pop->bitstream_buffer; + p_dec_info->stream_rd_ptr = pop->bitstream_buffer; + p_dec_info->stream_buf_start_addr = pop->bitstream_buffer;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 160
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+ p_dec_info->stream_buf_size = pop->bitstream_buffer_size; + p_dec_info->stream_buf_end_addr = pop->bitstream_buffer + pop->bitstream_buffer_size; + p_dec_info->reorder_enable = TRUE; + p_dec_info->mirror_direction =MIRDIR_NONE ; + p_dec_info->temp_id_select_mode =TEMPORAL_ID_MODE_ABSOLUTE ; + p_dec_info->target_temp_id =DECODE_ALL_TEMPORAL_LAYERS ; + p_dec_info->target_spatial_id =DECODE_ALL_SPATIAL_LAYERS ; + + ret =wave5_vpu_build_up_dec_param (vpu_inst, pop); +if (ret !=RETCODE_SUCCESS )
This function is using a mix of kernel error codes and custom error codes.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 161
Quoted 1 line
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +1
-0+ goto err_out;
goto free_ida;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 171
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+ +mutex_unlock (&vpu_dev->hw_lock); + +return 0 ; + +err_out: +if (vpu_inst->id >=0 ) +ida_free (&vpu_inst->dev->inst_ida, vpu_inst->id); +kfree (vpu_inst->codec_info); +mutex_unlock (&vpu_dev->hw_lock);
free_ida:
ida_free(&vpu_inst->dev->inst_ida, vpu_inst->id); free_codec_info: kfree(vpu_inst->codec_info); unlock: mutex_unlock(&vpu_dev->hw_lock);
Quoted 4 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +4
-0+ +return ret; +} +
drivers/staging/media/wave5/vpuapi/vpuapi.c line 185
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+enum ret_code vpu_dec_close (struct vpu_instance *inst) +{ +struct dec_info *p_dec_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; +int i; + +if (!inst->codec_info) +return RETCODE_INVALID_HANDLE ; + p_dec_info = &inst->codec_info->dec_info;
Remove extra spaces.
Quoted 22 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +22
-0+ +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_dec_fini_seq (inst); +if (ret !=RETCODE_SUCCESS ) { +dev_warn (inst->dev->dev,"dec sec end timed out\n" ); + +if (ret ==RETCODE_VPU_STILL_RUNNING ) { +mutex_unlock (&vpu_dev->hw_lock); +return ret; + } + } + +dev_dbg (inst->dev->dev,"dec seq end complete\n" ); + +if (p_dec_info->vb_work.size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_work); + +for (i =0 ; i <MAX_REG_FRAME ; i++) { +if (p_dec_info->vb_mv[i].size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_mv[i]);
drivers/staging/media/wave5/vpuapi/vpuapi.c line 217
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+if (p_dec_info->vb_fbc_y_tbl[i].size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_fbc_y_tbl[i]); +if (p_dec_info->vb_fbc_c_tbl[i].size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_fbc_c_tbl[i]); + } + +if (p_dec_info->vb_task.size) +vdi_free_dma_memory (vpu_dev, &p_dec_info->vb_task); + +if (inst->id >=0 )
No need for this check.
Quoted 56 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +56
-0+ida_free (&inst->dev->inst_ida, inst->id); + +mutex_unlock (&vpu_dev->hw_lock); + +kfree (inst->codec_info); + +return ret; +} + +enum ret_code vpu_dec_issue_seq_init (struct vpu_instance *inst) +{ +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_dec_init_seq (inst); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_complete_seq_init (struct vpu_instance *inst,struct dec_initial_info *info) +{ +struct dec_info *p_dec_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (info ==0 ) +return RETCODE_INVALID_PARAM ; + + p_dec_info = &inst->codec_info->dec_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_dec_get_seq_info (inst, info); +if (ret ==RETCODE_SUCCESS ) + p_dec_info->initial_info_obtained =1 ; + + info->rd_ptr =wave5_vpu_dec_get_rd_ptr (inst); + info->wr_ptr = p_dec_info->stream_wr_ptr; + + p_dec_info->initial_info = *info; + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_register_frame_buffer_ex (struct vpu_instance *inst, +int num_fbs_for_decoding,int num_fbs_for_wtl, +int stride,int height,int map_type) +{
drivers/staging/media/wave5/vpuapi/vpuapi.c line 283
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+struct dec_info *p_dec_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; +struct frame_buffer *fb; + +if (num_fbs_for_decoding >MAX_GDI_IDX ) +return RETCODE_INVALID_PARAM ; + +if (num_fbs_for_wtl >MAX_GDI_IDX ) +return RETCODE_INVALID_PARAM ;
These checks are off by one. They should should >=.
The variable names are too many words.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 294
Quoted 11 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +11
-0+ + p_dec_info = &inst->codec_info->dec_info; + p_dec_info->num_fbs_for_decoding = num_fbs_for_decoding; + p_dec_info->num_fbs_for_wtl = num_fbs_for_wtl; + p_dec_info->stride = stride; + +if (!p_dec_info->initial_info_obtained) +return RETCODE_WRONG_CALL_SEQUENCE ; + +if (stride < p_dec_info->initial_info.pic_width || (stride %8 !=0 ) || + height < p_dec_info->initial_info.pic_height)
These checks should be done before we say "p_dec_info->stride = stride".
drivers/staging/media/wave5/vpuapi/vpuapi.c line 300
Quoted 6 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +6
-0+return RETCODE_INVALID_STRIDE ; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + fb = inst->frame_buf;
Get rid of the "fb" variable. Delete the other "fb = inst->frame_buf;" too.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 307
Quoted 7 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +7
-0+ ret =wave5_vpu_dec_register_framebuffer (inst, &fb[p_dec_info->num_fbs_for_decoding], +LINEAR_FRAME_MAP , p_dec_info->num_fbs_for_wtl); +if (ret !=RETCODE_SUCCESS ) + goto err_out; + + ret =wave5_vpu_dec_register_framebuffer (inst, &fb[0 ], +COMPRESSED_FRAME_MAP , p_dec_info->num_fbs_for_decoding);
If these functions fail then they need clean up after themselves.
Quoted 120 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +120
-0+ +err_out: +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_get_bitstream_buffer (struct vpu_instance *inst,dma_addr_t *prd_ptr, +dma_addr_t *pwr_ptr,uint32_t *size) +{ +struct dec_info *p_dec_info; +dma_addr_t rd_ptr; +dma_addr_t wr_ptr; +dma_addr_t temp_ptr; +int room; +struct vpu_attr *p_attr; +struct vpu_device *vpu_dev = inst->dev; + + p_attr = &vpu_dev->attr; + p_dec_info = &inst->codec_info->dec_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + rd_ptr =wave5_vpu_dec_get_rd_ptr (inst); +mutex_unlock (&vpu_dev->hw_lock); + + wr_ptr = p_dec_info->stream_wr_ptr; + + temp_ptr = rd_ptr; + +if (p_dec_info->open_param.bitstream_mode !=BS_MODE_PIC_END ) { +if (wr_ptr < temp_ptr) + room = temp_ptr - wr_ptr; +else + room = (p_dec_info->stream_buf_end_addr - wr_ptr) + + (temp_ptr - p_dec_info->stream_buf_start_addr); + room--; + }else { + room = (p_dec_info->stream_buf_end_addr - wr_ptr); + } + +if (prd_ptr) + *prd_ptr = temp_ptr; +if (pwr_ptr) + *pwr_ptr = wr_ptr; +if (size) + *size = room; + +return RETCODE_SUCCESS ; +} + +enum ret_code vpu_dec_update_bitstream_buffer (struct vpu_instance *inst,int size) +{ +struct dec_info *p_dec_info; +dma_addr_t wr_ptr; +dma_addr_t rd_ptr; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (!inst->codec_info) +return RETCODE_INVALID_HANDLE ; + + p_dec_info = &inst->codec_info->dec_info; + wr_ptr = p_dec_info->stream_wr_ptr; + rd_ptr = p_dec_info->stream_rd_ptr; + +if (size >0 ) { +if (wr_ptr < rd_ptr && rd_ptr <= wr_ptr + size) +return RETCODE_INVALID_PARAM ; + + wr_ptr += size; + +if (p_dec_info->open_param.bitstream_mode !=BS_MODE_PIC_END ) { +if (wr_ptr > p_dec_info->stream_buf_end_addr) { +u32 room = wr_ptr - p_dec_info->stream_buf_end_addr; + + wr_ptr = p_dec_info->stream_buf_start_addr; + wr_ptr += room; + }else if (wr_ptr == p_dec_info->stream_buf_end_addr) { + wr_ptr = p_dec_info->stream_buf_start_addr; + } + } + + p_dec_info->stream_wr_ptr = wr_ptr; + p_dec_info->stream_rd_ptr = rd_ptr; + } + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + ret =wave5_vpu_dec_set_bitstream_flag (inst, (size ==0 )); +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_start_one_frame (struct vpu_instance *inst,struct dec_param *param) +{ +struct dec_info *p_dec_info; +enum ret_code ret =RETCODE_SUCCESS ; +struct vpu_device *vpu_dev = inst->dev; + + p_dec_info = &inst->codec_info->dec_info; + +if (p_dec_info->stride ==0 )// this means frame buffers have not been registered. +return RETCODE_WRONG_CALL_SEQUENCE ; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + p_dec_info->frame_start_pos = p_dec_info->stream_rd_ptr; + + ret =wave5_vpu_decode (inst, param); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_get_output_info (struct vpu_instance *inst,struct dec_output_info *info) +{
drivers/staging/media/wave5/vpuapi/vpuapi.c line 437
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+struct dec_info *p_dec_info; +enum ret_code ret; +struct vpu_rect rect_info; +u32 val; +s32 decoded_index; +s32 disp_idx; +u32 max_dec_index; +struct vpu_device *vpu_dev = inst->dev; + +if (info ==0 )
info is a pointer. Please run Sparse on your code.
if (!info) {drivers/staging/media/wave5/vpuapi/vpuapi.c line 445
Quoted 8 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +8
-0+return RETCODE_INVALID_PARAM ; + + p_dec_info = &inst->codec_info->dec_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + +memset ((void *)info,0x00 ,sizeof (struct dec_output_info ));
Remove the cast and the hex. Use the variable name instead of the struct type.
memset(info, 0, sizeof(*info));
drivers/staging/media/wave5/vpuapi/vpuapi.c line 451
Quoted 6 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +6
-0+ + ret =wave5_vpu_dec_get_result (inst, info); +if (ret !=RETCODE_SUCCESS ) { + info->rd_ptr = p_dec_info->stream_rd_ptr; + info->wr_ptr = p_dec_info->stream_wr_ptr; + goto err_out;
This goto always returns RETCODE_SUCCESS.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 457
Quoted 6 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +6
-0+ } + + decoded_index = info->index_frame_decoded; + +// calculate display frame region + val =0 ;
This assignment is never used.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 458
Quoted 1 line
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +1
-0+if (decoded_index >=0 && decoded_index <MAX_GDI_IDX ) {
Flip this condition around. Always do error handling instead of success handling. Error handling is normally shorter so it just makes the code easier to read. You could move the default assignment forward.
/* default value */
rect_info.left = 0;
rect_info.right = info->dec_pic_width;
rect_info.top = 0;
rect_info.bottom = info->dec_pic_height;
if (decoded_index < 0 || decoded_index >= MAX_GDI_IDX) {
info->rc_decoded = rect_info;
} else {Quoted 255 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +255
-0+//default value + rect_info.left =0 ; + rect_info.right = info->dec_pic_width; + rect_info.top =0 ; + rect_info.bottom = info->dec_pic_height; + +if (inst->std ==W_HEVC_DEC || inst->std ==W_AVC_DEC ) + rect_info = p_dec_info->initial_info.pic_crop_rect; + +if (inst->std ==W_HEVC_DEC ) + p_dec_info->dec_out_info[decoded_index].decoded_poc = info->decoded_poc; + +if (inst->std ==W_AVS2_DEC ) + p_dec_info->dec_out_info[decoded_index].avs2_info.decoded_poi = + info->avs2_info.decoded_poi; + + info->rc_decoded.left = rect_info.left; + p_dec_info->dec_out_info[decoded_index].rc_decoded.left = rect_info.left; + info->rc_decoded.right = rect_info.right; + p_dec_info->dec_out_info[decoded_index].rc_decoded.right = rect_info.right; + info->rc_decoded.top = rect_info.top; + p_dec_info->dec_out_info[decoded_index].rc_decoded.top = rect_info.top; + info->rc_decoded.bottom = rect_info.bottom; + p_dec_info->dec_out_info[decoded_index].rc_decoded.bottom = rect_info.bottom; + }else { + info->rc_decoded.left =0 ; + info->rc_decoded.right = info->dec_pic_width; + info->rc_decoded.top =0 ; + info->rc_decoded.bottom = info->dec_pic_height; + } + + disp_idx = info->index_frame_display; +if (info->index_frame_display >=0 && info->index_frame_display <MAX_GDI_IDX ) { +if (p_dec_info->rotation_enable) { +switch (p_dec_info->rotation_angle) { +case 90 : + info->rc_display.left = + p_dec_info->dec_out_info[disp_idx].rc_decoded.top; + info->rc_display.right = + p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; + info->rc_display.top = + p_dec_info->dec_out_info[disp_idx].dec_pic_width - + p_dec_info->dec_out_info[disp_idx].rc_decoded.right; + info->rc_display.bottom = + p_dec_info->dec_out_info[disp_idx].dec_pic_width - + p_dec_info->dec_out_info[disp_idx].rc_decoded.left; +break ; +case 270 : + info->rc_display.left = + p_dec_info->dec_out_info[disp_idx].dec_pic_height - + p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; + info->rc_display.right = + p_dec_info->dec_out_info[disp_idx].dec_pic_height - + p_dec_info->dec_out_info[disp_idx].rc_decoded.top; + info->rc_display.top = + p_dec_info->dec_out_info[disp_idx].rc_decoded.left; + info->rc_display.bottom = + p_dec_info->dec_out_info[disp_idx].rc_decoded.right; +break ; +case 180 : + info->rc_display.left = + p_dec_info->dec_out_info[disp_idx].rc_decoded.left; + info->rc_display.right = + p_dec_info->dec_out_info[disp_idx].rc_decoded.right; + info->rc_display.top = + p_dec_info->dec_out_info[disp_idx].dec_pic_height - + p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; + info->rc_display.bottom = + p_dec_info->dec_out_info[disp_idx].dec_pic_height - + p_dec_info->dec_out_info[disp_idx].rc_decoded.top; +break ; +default : + info->rc_display.left = + p_dec_info->dec_out_info[disp_idx].rc_decoded.left; + info->rc_display.right = + p_dec_info->dec_out_info[disp_idx].rc_decoded.right; + info->rc_display.top = + p_dec_info->dec_out_info[disp_idx].rc_decoded.top; + info->rc_display.bottom = + p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; +break ; + } + + }else { + info->rc_display.left = p_dec_info->dec_out_info[disp_idx].rc_decoded.left; + info->rc_display.right = p_dec_info->dec_out_info[disp_idx].rc_decoded.right; + info->rc_display.top = p_dec_info->dec_out_info[disp_idx].rc_decoded.top; + info->rc_display.bottom = p_dec_info->dec_out_info[disp_idx].rc_decoded.bottom; + } + +if (p_dec_info->mirror_enable) { +u32 temp; +u32 width = (p_dec_info->rotation_angle ==90 || + p_dec_info->rotation_angle ==270 ) ? info->dec_pic_height : + info->dec_pic_width; +u32 height = (p_dec_info->rotation_angle ==90 || + p_dec_info->rotation_angle ==270 ) ? info->dec_pic_width : + info->dec_pic_height; + +if (p_dec_info->mirror_direction &MIRDIR_VER ) { + temp = info->rc_display.top; + info->rc_display.top = height - info->rc_display.bottom; + info->rc_display.bottom = height - temp; + } +if (p_dec_info->mirror_direction &MIRDIR_HOR ) { + temp = info->rc_display.left; + info->rc_display.left = width - info->rc_display.right; + info->rc_display.right = width - temp; + } + } + +switch (inst->std) { +case W_HEVC_DEC : + info->display_poc = p_dec_info->dec_out_info[disp_idx].decoded_poc; +break ; +case W_AVS2_DEC : + info->avs2_info.display_poi = p_dec_info->dec_out_info[disp_idx].avs2_info.decoded_poi; +break ; +case W_AVC_DEC : + info->display_poc = p_dec_info->dec_out_info[disp_idx].decoded_poc; +break ; +default : +break ; + } + +if (info->index_frame_display == info->index_frame_decoded) { + info->disp_pic_width = info->dec_pic_width; + info->disp_pic_height = info->dec_pic_height; + }else { +/* +* when index_frame_decoded < 0, and index_frame_display >= 0 +* info->dec_pic_width and info->dec_pic_height are still valid +* but those of p_dec_info->dec_out_info[disp_idx] are invalid in VP9 +*/ + info->disp_pic_width = p_dec_info->dec_out_info[disp_idx].dec_pic_width; + info->disp_pic_height = p_dec_info->dec_out_info[disp_idx].dec_pic_height; + } + + }else { + info->rc_display.left =0 ; + info->rc_display.right =0 ; + info->rc_display.top =0 ; + info->rc_display.bottom =0 ; + +if (p_dec_info->rotation_enable || p_dec_info->mirror_enable || + p_dec_info->dering_enable) { + info->disp_pic_width = info->dec_pic_width; + info->disp_pic_height = info->dec_pic_height; + }else { + info->disp_pic_width =0 ; + info->disp_pic_height =0 ; + } + } + + p_dec_info->stream_rd_ptr =wave5_vpu_dec_get_rd_ptr (inst); + p_dec_info->frame_display_flag =vpu_read_reg (vpu_dev,W5_RET_DEC_DISP_IDC ); +if (inst->std ==W_VP9_DEC ) + p_dec_info->frame_display_flag &=0xFFFF ; + p_dec_info->frame_end_pos = p_dec_info->stream_rd_ptr; + +if (p_dec_info->frame_end_pos < p_dec_info->frame_start_pos) + info->consumed_byte = p_dec_info->frame_end_pos + p_dec_info->stream_buf_size - + p_dec_info->frame_start_pos; +else + info->consumed_byte = p_dec_info->frame_end_pos - p_dec_info->frame_start_pos; + +if (p_dec_info->dering_enable || p_dec_info->mirror_enable || p_dec_info->rotation_enable) { + info->disp_frame = p_dec_info->rotator_output; + info->disp_frame.stride = p_dec_info->rotator_stride; + }else { + val = p_dec_info->num_fbs_for_decoding;//fb_offset + + max_dec_index = (p_dec_info->num_fbs_for_decoding > p_dec_info->num_fbs_for_wtl) ? + p_dec_info->num_fbs_for_decoding : p_dec_info->num_fbs_for_wtl; + +if (info->index_frame_display >=0 && info->index_frame_display < (int )max_dec_index) + info->disp_frame = inst->frame_buf[val + info->index_frame_display]; + } + + info->rd_ptr = p_dec_info->stream_rd_ptr; + info->wr_ptr = p_dec_info->stream_wr_ptr; + info->frame_display_flag = p_dec_info->frame_display_flag; + + info->sequence_no = p_dec_info->initial_info.sequence_no; +if (decoded_index >=0 && decoded_index <MAX_GDI_IDX ) + p_dec_info->dec_out_info[decoded_index] = *info; + +if (disp_idx >=0 && disp_idx <MAX_GDI_IDX ) { + info->num_of_tot_m_bs_in_display = p_dec_info->dec_out_info[disp_idx].num_of_tot_m_bs; + info->num_of_err_m_bs_in_display = p_dec_info->dec_out_info[disp_idx].num_of_err_m_bs; + info->disp_frame.sequence_no = info->sequence_no; + }else { + info->num_of_tot_m_bs_in_display =0 ; + info->num_of_err_m_bs_in_display =0 ; + } + +if (info->sequence_changed !=0 ) { +if ((info->sequence_changed &SEQ_CHANGE_INTER_RES_CHANGE ) !=SEQ_CHANGE_INTER_RES_CHANGE ) + p_dec_info->initial_info.sequence_no++; + } + +err_out: +mutex_unlock (&vpu_dev->hw_lock); + +return RETCODE_SUCCESS ; +} + +enum ret_code vpu_dec_clr_disp_flag (struct vpu_instance *inst,int index) +{ +struct dec_info *p_dec_info; +enum ret_code ret =RETCODE_SUCCESS ; +s32 end_index; +struct vpu_device *vpu_dev = inst->dev; + + p_dec_info = &inst->codec_info->dec_info; + + end_index = p_dec_info->num_fbs_for_wtl; + +if (index <0 || index > end_index -1 ) +return RETCODE_INVALID_PARAM ; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + ret =wave5_dec_clr_disp_flag (inst, index); +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_dec_give_command (struct vpu_instance *inst,enum codec_command cmd,void *param) +{ +struct dec_info *p_dec_info; + + p_dec_info = &inst->codec_info->dec_info; +switch (cmd) { +case DEC_GET_QUEUE_STATUS : + { +struct queue_status_info *queue_info = (struct queue_status_info *)param; + + queue_info->instance_queue_count = p_dec_info->instance_queue_count; + queue_info->report_queue_count = p_dec_info->report_queue_count; +break ; + } + +case ENABLE_DEC_THUMBNAIL_MODE : + { + p_dec_info->thumbnail_mode =1 ; +break ; + } +default : +return RETCODE_INVALID_COMMAND ; + } + +return 0 ; +}
drivers/staging/media/wave5/vpuapi/vpuapi.c line 723
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+ +int vpu_enc_open_api (struct vpu_instance *vpu_inst,struct enc_open_param *pop) +{ +struct enc_info *p_enc_info; +int ret; +struct vpu_device *vpu_dev = vpu_inst->dev; + + ret =wave5_vpu_enc_check_open_param (vpu_inst, pop); +if (ret !=RETCODE_SUCCESS ) +return ret;
This function returns int not ret codes.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 125
Quoted 8 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +8
-0+ + ret =mutex_lock_interruptible (&vpu_dev->hw_lock); +if (ret) +return ret; + +if (wave5_vpu_is_init (vpu_dev) ==0 ) { + ret = -ENODEV ; + goto err_out;
Freeing ida when it hasn't been allocated will trigger a WARN().
drivers/staging/media/wave5/vpuapi/vpuapi.c line 734
Quoted 3 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +3
-0+ } + + vpu_inst->codec_info =kzalloc (sizeof (vpu_inst->codec_info),GFP_KERNEL );
The sizeof() is wrong. It should be sizeof(*vpu_inst->codec_info).
Quoted 65 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +65
-0+if (!vpu_inst->codec_info) { + ret = -ENOMEM ; + goto err_out; + } + + vpu_inst->id =ida_alloc_max (&vpu_inst->dev->inst_ida,MAX_NUM_INSTANCE -1 ,GFP_KERNEL ); +if (vpu_inst->id <0 ) { +dev_warn (vpu_inst->dev->dev,"unable to allocate instance ID: %d\n" , vpu_inst->id); + ret = vpu_inst->id; + goto err_out; + } + p_enc_info = &vpu_inst->codec_info->enc_info; + p_enc_info->open_param = *pop; + + ret =wave5_vpu_build_up_enc_param (vpu_dev->dev, vpu_inst, pop); +if (ret !=RETCODE_SUCCESS ) + goto err_out; +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +err_out: +if (vpu_inst->id >=0 ) +ida_free (&vpu_inst->dev->inst_ida, vpu_inst->id); +kfree (vpu_inst->codec_info); +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_enc_close (struct vpu_instance *inst) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (!inst->codec_info) +return RETCODE_INVALID_HANDLE ; + p_enc_info = &inst->codec_info->enc_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_enc_fini_seq (inst); +if (ret !=RETCODE_SUCCESS ) { +dev_warn (inst->dev->dev,"enc seq end timed out\n" ); + +if (ret ==RETCODE_VPU_STILL_RUNNING ) { +mutex_unlock (&vpu_dev->hw_lock); +return ret; + } + } + +dev_dbg (inst->dev->dev,"enc seq end timed out\n" ); + +if (p_enc_info->vb_work.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_work); + +if (inst->std ==W_HEVC_ENC || inst->std ==W_AVC_ENC ) { +if (p_enc_info->vb_sub_sam_buf.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_sub_sam_buf); + +if (p_enc_info->vb_mv.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_mv); + +if (p_enc_info->vb_fbc_y_tbl.size)
drivers/staging/media/wave5/vpuapi/vpuapi.c line 809
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_fbc_y_tbl); + +if (p_enc_info->vb_fbc_c_tbl.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_fbc_c_tbl); + } + +if (p_enc_info->vb_task.size) +vdi_free_dma_memory (vpu_dev, &p_enc_info->vb_task); + +if (inst->id >=0 )
Delete this check.
Quoted 23 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +23
-0+ida_free (&inst->dev->inst_ida, inst->id); + +mutex_unlock (&vpu_dev->hw_lock); + +kfree (inst->codec_info); + +return ret; +} + +enum ret_code vpu_enc_register_frame_buffer (struct vpu_instance *inst,int num,int stride, +int height,enum tiled_map_type map_type) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct enc_open_param *open_param; +struct frame_buffer *fb; +struct vpu_device *vpu_dev = inst->dev; +u32 size_luma, size_chroma; +int i; + + p_enc_info = &inst->codec_info->enc_info; + open_param = &p_enc_info->open_param; +
drivers/staging/media/wave5/vpuapi/vpuapi.c line 842
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+if (p_enc_info->stride) +return RETCODE_CALLED_BEFORE ; + +if (!p_enc_info->initial_info_obtained) +return RETCODE_WRONG_CALL_SEQUENCE ; + +if (num < p_enc_info->initial_info.min_frame_buffer_count) +return RETCODE_INSUFFICIENT_FRAME_BUFFERS ; + +if (stride ==0 || (stride %8 !=0 ) || stride <0 )
if (stride <= 0 || stride % 8)
Quoted 82 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +82
-0+return RETCODE_INVALID_STRIDE ; + +if (height ==0 || height <0 ) +return RETCODE_INVALID_PARAM ; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + p_enc_info->num_frame_buffers = num; + p_enc_info->stride = stride; + + fb = inst->frame_buf; + size_luma = stride * height; + size_chroma =ALIGN (stride /2 ,16 ) * height; + +for (i =0 ; i < num; i++) { +if (fb[i].update_fb_info) { + fb[i].update_fb_info = FALSE; + fb[i].stride = stride; + fb[i].height = height; + fb[i].map_type =COMPRESSED_FRAME_MAP ; + fb[i].cbcr_interleave = true; + fb[i].endian =VDI_128BIT_LITTLE_ENDIAN ; + fb[i].buf_y_size = size_luma; + fb[i].buf_cb = fb[i].buf_y + size_luma; + fb[i].buf_cb_size = size_chroma; + fb[i].buf_cr_size =0 ; + } + } + + ret =wave5_vpu_enc_register_framebuffer (inst->dev->dev, inst, &fb[0 ], +COMPRESSED_FRAME_MAP , p_enc_info->num_frame_buffers); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +static enum ret_code check_enc_param (struct vpu_instance *inst,struct enc_param *param) +{ +struct enc_info *p_enc_info; + + p_enc_info = &inst->codec_info->enc_info; + +if (param ==0 ) +return RETCODE_INVALID_PARAM ; + +if (param->skip_picture !=0 && param->skip_picture !=1 ) +return RETCODE_INVALID_PARAM ; +if (param->skip_picture ==0 ) { +if (param->source_frame ==0 ) +return RETCODE_INVALID_FRAME_BUFFER ; + } +if (p_enc_info->open_param.bit_rate ==0 ) {// no rate control +if (inst->std ==W_HEVC_ENC ) { +if (param->force_pic_qp_enable ==1 ) { +if (param->force_pic_qp_i <0 || param->force_pic_qp_i >63 ) +return RETCODE_INVALID_PARAM ; + +if (param->force_pic_qp_p <0 || param->force_pic_qp_p >63 ) +return RETCODE_INVALID_PARAM ; + +if (param->force_pic_qp_b <0 || param->force_pic_qp_b >63 ) +return RETCODE_INVALID_PARAM ; + } +if (p_enc_info->ring_buffer_enable ==0 ) { +if (param->pic_stream_buffer_addr %16 || param->pic_stream_buffer_size ==0 ) +return RETCODE_INVALID_PARAM ; + } + } + } +if (p_enc_info->ring_buffer_enable ==0 ) { +if (param->pic_stream_buffer_addr %8 || param->pic_stream_buffer_size ==0 ) +return RETCODE_INVALID_PARAM ; + } + +return RETCODE_SUCCESS ; +} + +static uint64_t get_timestamp (struct vpu_instance *vpu_inst) +{ +struct enc_info *p_enc_info =NULL ;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 934
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+u64 pts; +u32 fps; + +if (!vpu_inst->codec_info) +return 0 ; + + p_enc_info = &vpu_inst->codec_info->enc_info; + fps = p_enc_info->open_param.frame_rate_info; +if (fps ==0 ) + fps =30 ;/* 30 fps */
Delete the obvious comment.
Quoted 41 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +41
-0+ + pts = p_enc_info->cur_pts; + p_enc_info->cur_pts +=90000 / fps;/* 90_k_hz/fps */ + +return pts; +} + +enum ret_code vpu_enc_start_one_frame (struct vpu_instance *inst,struct enc_param *param) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + + p_enc_info = &inst->codec_info->enc_info; + +if (p_enc_info->stride ==0 )// this means frame buffers have not been registered. +return RETCODE_WRONG_CALL_SEQUENCE ; + + ret =check_enc_param (inst, param); +if (ret !=RETCODE_SUCCESS ) +return ret; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + p_enc_info->pts_map[param->src_idx] = p_enc_info->open_param.enable_pts ?get_timestamp (inst) : param->pts; + + ret =wave5_vpu_encode (inst, param); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_enc_get_output_info (struct vpu_instance *inst,struct enc_output_info *info) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (info ==0 )
drivers/staging/media/wave5/vpuapi/vpuapi.c line 985
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+return RETCODE_INVALID_PARAM ; + + p_enc_info = &inst->codec_info->enc_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_enc_get_result (inst, info); + +if (ret ==RETCODE_SUCCESS ) {
Do error handling not success handling.
if (ret != RETCODE_SUCCESS) goto unlock;
drivers/staging/media/wave5/vpuapi/vpuapi.c line 987
Quoted 2 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +2
-0+if (info->enc_src_idx >=0 && info->recon_frame_index >=0 ) + info->pts = p_enc_info->pts_map[info->enc_src_idx];
Why do we even allow negative indexes? Make these unsigned.
Quoted 9 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +9
-0+ }else { + info->pts =0LL ; + } + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} +
drivers/staging/media/wave5/vpuapi/vpuapi.c line 1006
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +10
-0+enum ret_code vpu_enc_give_command (struct vpu_instance *inst,enum codec_command cmd,void *param) +{ +struct enc_info *p_enc_info; + + p_enc_info = &inst->codec_info->enc_info; +switch (cmd) { +case ENABLE_ROTATION : + { + p_enc_info->rotation_enable =1 ; + }
Pointless curly braces.
drivers/staging/media/wave5/vpuapi/vpuapi.c line 1014
Quoted 8 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +8
-0+break ; +case ENABLE_MIRRORING : + { + p_enc_info->mirror_enable =1 ; + } +break ; +case SET_MIRROR_DIRECTION : + {
Put the curly brace on the line before and pull this code in one tab.
case SET_MIRROR_DIRECTION: {
enum mirror_direction mir_dir;
...Quoted 864 lines
drivers/staging/media/wave5/vpuapi/vpuapi.c new file +80
-0+enum mirror_direction mir_dir; + +if (param ==0 ) +return RETCODE_INVALID_PARAM ; + + mir_dir = *(enum mirror_direction *)param; +if (!(mir_dir ==MIRDIR_NONE ) && !(mir_dir ==MIRDIR_HOR ) && + !(mir_dir ==MIRDIR_VER ) && !(mir_dir ==MIRDIR_HOR_VER )) +return RETCODE_INVALID_PARAM ; + p_enc_info->mirror_direction = mir_dir; + } +break ; +case SET_ROTATION_ANGLE : + { +int angle; + +if (param ==0 ) +return RETCODE_INVALID_PARAM ; + angle = *(int *)param; +if (angle !=0 && angle !=90 && angle !=180 && angle !=270 ) +return RETCODE_INVALID_PARAM ; +if (p_enc_info->initial_info_obtained && (angle ==90 || angle ==270 )) +return RETCODE_INVALID_PARAM ; + p_enc_info->rotation_angle = angle; + } +break ; +case ENC_GET_QUEUE_STATUS : + { +struct queue_status_info *queue_info = (struct queue_status_info *)param; + + queue_info->instance_queue_count = p_enc_info->instance_queue_count; + queue_info->report_queue_count = p_enc_info->report_queue_count; +break ; + } +default : +return RETCODE_INVALID_COMMAND ; + } +return RETCODE_SUCCESS ; +} + +enum ret_code vpu_enc_issue_seq_init (struct vpu_instance *inst) +{ +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_enc_init_seq (inst); + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} + +enum ret_code vpu_enc_complete_seq_init (struct vpu_instance *inst,struct enc_initial_info *info) +{ +struct enc_info *p_enc_info; +enum ret_code ret; +struct vpu_device *vpu_dev = inst->dev; + +if (info ==0 ) +return RETCODE_INVALID_PARAM ; + + p_enc_info = &inst->codec_info->enc_info; + +if (mutex_lock_interruptible (&vpu_dev->hw_lock)) +return RETCODE_FAILURE ; + + ret =wave5_vpu_enc_get_seq_info (inst, info); +if (ret ==RETCODE_SUCCESS ) + p_enc_info->initial_info_obtained =1 ; + + p_enc_info->initial_info = *info; + +mutex_unlock (&vpu_dev->hw_lock); + +return ret; +} +drivers/staging/media/wave5/vpuapi/vpuapi.h new file +778
-0@@ -0,0 +1,1176 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* +* Wave5 series multi-standard codec IP - helper definitions +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ + +#ifndef VPUAPI_H_INCLUDED +#define VPUAPI_H_INCLUDED + +#include <linux/kfifo.h> +#include <linux/idr.h> +#include <media/v4l2-device.h> +#include <media/v4l2-mem2mem.h> +#include <media/v4l2-ctrls.h> +#include "vpuerror.h" +#include "vpuconfig.h" +#include "../vdi/vdi.h" + +enum product_id { + PRODUCT_ID_521, + PRODUCT_ID_511, + PRODUCT_ID_517, + PRODUCT_ID_NONE, +}; + +#define PRODUCT_ID_W_SERIES(x) ((x) == PRODUCT_ID_521 || (x) == PRODUCT_ID_511 || (x) == PRODUCT_ID_517) +#define PRODUCT_ID_NOT_W_SERIES(x) !PRODUCT_ID_W_SERIES(x) + +struct vpu_attr; + +enum vpu_instance_type { + VPU_INST_TYPE_DEC = 0, + VPU_INST_TYPE_ENC = 1 +}; + +enum vpu_instance_state { + VPU_INST_STATE_NONE = 0, + VPU_INST_STATE_OPEN = 1, + VPU_INST_STATE_INIT_SEQ = 2, + VPU_INST_STATE_PIC_RUN = 3, + VPU_INST_STATE_STOP = 4, + VPU_INST_STATE_WAIT_BUF = 5 +}; + +#define MAX_GDI_IDX 31 +#define MAX_REG_FRAME (MAX_GDI_IDX * 2) + +#define WAVE5_DEC_HEVC_MVCOL_BUF_SIZE(_w, _h) (DIV_ROUND_UP(_w, 64) * DIV_ROUND_UP(_h, 64) * 256 + 64) +#define WAVE5_DEC_AVC_MVCOL_BUF_SIZE(_w, _h) ((((ALIGN(_w, 256) / 16) * (ALIGN(_h, 16) / 16)) + 16) * 80) +#define WAVE5_DEC_VP9_MVCOL_BUF_SIZE(_w, _h) (((ALIGN(_w, 64) * ALIGN(_h, 64)) >> 2)) +#define WAVE5_DEC_AVS2_MVCOL_BUF_SIZE(_w, _h) (((ALIGN(_w, 64) * ALIGN(_h, 64)) >> 5)) +// AV1 MVCOL BUF SIZE : MFMV + segment ID + CDF probs table + film grain param Y+ film graim param C +#define WAVE5_DEC_AV1_MVCOL_BUF_SZ_1(_w, _h) \ + (((ALIGN(_w, 64) / 64) * (ALIGN(_h, 64) / 64) * 512) + 41984 + 8192 + 4864) +#define WAVE5_DEC_AV1_MVCOL_BUF_SZ_2(_w1, _w2, _h) \ + (((ALIGN(_w1, 64) / 64) * 256 + (ALIGN(_w2, 256) / 64) * 128) * (ALIGN(_h, 64) / 64)) + +#define WAVE5_FBC_LUMA_TABLE_SIZE(_w, _h) (ALIGN(_h, 64) * ALIGN(_w, 256) / 32) +#define WAVE5_FBC_CHROMA_TABLE_SIZE(_w, _h) (ALIGN((_h), 64) * ALIGN((_w) / 2, 256) / 32) +#define WAVE5_ENC_AVC_MVCOL_BUF_SIZE(_w, _h) (ALIGN(_w, 64) * ALIGN(_h, 64) / 32) +#define WAVE5_ENC_HEVC_MVCOL_BUF_SIZE(_w, _h) (ALIGN(_w, 64) / 64 * ALIGN(_h, 64) / 64 * 128) + +/* + * common struct and definition + */ +enum cod_std { + STD_AVC = 0, + STD_VC1 = 1, + STD_MPEG2 = 2, + STD_MPEG4 = 3, + STD_H263 = 4, + STD_DIV3 = 5, + STD_RV = 6, + STD_AVS = 7, + STD_THO = 9, + STD_VP3 = 10, + STD_VP8 = 11, + STD_HEVC = 12, + STD_VP9 = 13, + STD_AVS2 = 14, + STD_AV1 = 16, + STD_MAX +}; + +enum wave_std { + W_HEVC_DEC = 0x00, + W_HEVC_ENC = 0x01, + W_AVC_DEC = 0x02, + W_AVC_ENC = 0x03, + W_VP9_DEC = 0x16, + W_AVS2_DEC = 0x18, + W_AV1_DEC = 0x1A, + STD_UNKNOWN = 0xFF +}; + +enum SET_PARAM_OPTION { + OPT_COMMON = 0, /* SET_PARAM command option for encoding sequence */ + OPT_CUSTOM_GOP = 1, /* SET_PARAM command option for setting custom GOP */ + OPT_CUSTOM_HEADER = 2, /* SET_PARAM command option for setting custom VPS/SPS/PPS */ + OPT_VUI = 3, /* SET_PARAM command option for encoding VUI */ + OPT_CHANGE_PARAM = 0x10, +}; + +enum DEC_PIC_HDR_OPTION { + INIT_SEQ_NORMAL = 0x01, + INIT_SEQ_W_THUMBNAIL = 0x11, +}; + +enum DEC_PIC_OPTION { + DEC_PIC_NORMAL = 0x00, /* it is normal mode of DEC_PIC command. */ + DEC_PIC_W_THUMBNAIL = 0x10, /* thumbnail mode (skip non-IRAP without reference reg.) */ + SKIP_NON_IRAP = 0x11, /* it skips to decode non-IRAP pictures. */ + SKIP_NON_REF_PIC = 0x13 +}; + +/************************************************************************/ +/* PROFILE & LEVEL */ +/************************************************************************/ +/* HEVC */ +#define HEVC_PROFILE_MAIN 1 +#define HEVC_PROFILE_MAIN10 2 +#define HEVC_PROFILE_STILLPICTURE 3 +#define HEVC_PROFILE_MAIN10_STILLPICTURE 2 + +/* H.264 profile for encoder*/ +#define H264_PROFILE_BP 1 +#define H264_PROFILE_MP 2 +#define H264_PROFILE_EXTENDED 3 +#define H264_PROFILE_HP 4 +#define H264_PROFILE_HIGH10 5 +#define H264_PROFILE_HIGH422 6 +#define H264_PROFILE_HIGH444 7 + +/************************************************************************/ +/* error codes */ +/************************************************************************/ + +enum ret_code { + RETCODE_SUCCESS, + RETCODE_FAILURE, + RETCODE_INVALID_HANDLE, + RETCODE_INVALID_PARAM, + RETCODE_INVALID_COMMAND, + RETCODE_ROTATOR_OUTPUT_NOT_SET, + RETCODE_ROTATOR_STRIDE_NOT_SET, + RETCODE_FRAME_NOT_COMPLETE, + RETCODE_INVALID_FRAME_BUFFER, + RETCODE_INSUFFICIENT_FRAME_BUFFERS, + RETCODE_INVALID_STRIDE, + RETCODE_WRONG_CALL_SEQUENCE, + RETCODE_CALLED_BEFORE, + RETCODE_NOT_INITIALIZED, + RETCODE_USERDATA_BUF_NOT_SET, + RETCODE_MEMORY_ACCESS_VIOLATION, + RETCODE_VPU_RESPONSE_TIMEOUT, + RETCODE_INSUFFICIENT_RESOURCE, + RETCODE_NOT_FOUND_BITCODE_PATH, + RETCODE_NOT_SUPPORTED_FEATURE, + RETCODE_NOT_FOUND_VPU_DEVICE, + RETCODE_CP0_EXCEPTION, /* this means that coprocessor exception has occurred. (WAVE only) */ + RETCODE_STREAM_BUF_FULL, /* this means that stream buffer is full in encoder. */ + RETCODE_ACCESS_VIOLATION_HW, + RETCODE_QUERY_FAILURE, /* this means that query command was not successful. (WAVE5 only) */ + RETCODE_QUEUEING_FAILURE, /* this means that commands cannot be queued. (WAVE5 only) */ + RETCODE_VPU_STILL_RUNNING, + RETCODE_REPORT_NOT_READY, + RETCODE_VLC_BUF_FULL, /* this means that VLC buffer is full in encoder. (WAVE5 only) */ + RETCODE_VPU_BUS_ERROR, + RETCODE_INVALID_SFS_INSTANCE, +}; + +/************************************************************************/ +/* utility macros */ +/************************************************************************/ +#define VPU_CEIL(_data, _align) (((_data) + ((_align) - 1)) & ~((_align) - 1)) + +/************************************************************************/ +/* */ +/************************************************************************/ +/** + * \brief parameters of DEC_SET_SEQ_CHANGE_MASK + */ +#define SEQ_CHANGE_ENABLE_PROFILE BIT(5) +#define SEQ_CHANGE_CHROMA_FORMAT_IDC BIT(15) /* AV1 */ +#define SEQ_CHANGE_ENABLE_SIZE BIT(16) +#define SEQ_CHANGE_INTER_RES_CHANGE BIT(17) /* VP9 */ +#define SEQ_CHANGE_ENABLE_BITDEPTH BIT(18) +#define SEQ_CHANGE_ENABLE_DPB_COUNT BIT(19) + +#define SEQ_CHANGE_ENABLE_ALL_VP9 (SEQ_CHANGE_ENABLE_PROFILE | \ + SEQ_CHANGE_ENABLE_SIZE | \ + SEQ_CHANGE_INTER_RES_CHANGE | \ + SEQ_CHANGE_ENABLE_BITDEPTH | \ + SEQ_CHANGE_ENABLE_DPB_COUNT) + +#define SEQ_CHANGE_ENABLE_ALL_HEVC (SEQ_CHANGE_ENABLE_PROFILE | \ + SEQ_CHANGE_ENABLE_SIZE | \ + SEQ_CHANGE_ENABLE_BITDEPTH | \ + SEQ_CHANGE_ENABLE_DPB_COUNT) + +#define SEQ_CHANGE_ENABLE_ALL_AVS2 (SEQ_CHANGE_ENABLE_PROFILE | \ + SEQ_CHANGE_ENABLE_SIZE | \ + SEQ_CHANGE_ENABLE_BITDEPTH | \ + SEQ_CHANGE_ENABLE_DPB_COUNT) + +#define SEQ_CHANGE_ENABLE_ALL_AVC (SEQ_CHANGE_ENABLE_SIZE | \ + SEQ_CHANGE_ENABLE_BITDEPTH | \ + SEQ_CHANGE_ENABLE_DPB_COUNT) + +#define SEQ_CHANGE_ENABLE_ALL_AV1 (SEQ_CHANGE_ENABLE_PROFILE | \ + SEQ_CHANGE_CHROMA_FORMAT_IDC | \ + SEQ_CHANGE_ENABLE_SIZE | \ + SEQ_CHANGE_ENABLE_BITDEPTH | \ + SEQ_CHANGE_ENABLE_DPB_COUNT) + +#define DISPLAY_IDX_FLAG_SEQ_END -1 +#define DISPLAY_IDX_FLAG_NO_FB -3 +#define DECODED_IDX_FLAG_NO_FB -1 +#define DECODED_IDX_FLAG_SKIP -2 + +#define RECON_IDX_FLAG_ENC_END -1 +#define RECON_IDX_FLAG_ENC_DELAY -2 +#define RECON_IDX_FLAG_HEADER_ONLY -3 +#define RECON_IDX_FLAG_CHANGE_PARAM -4 + +enum codec_command { + ENABLE_ROTATION, + ENABLE_MIRRORING, + SET_MIRROR_DIRECTION, + SET_ROTATION_ANGLE, + ENABLE_DEC_THUMBNAIL_MODE, + DEC_GET_QUEUE_STATUS, + ENC_GET_QUEUE_STATUS, +}; + +enum error_conceal_mode { + ERROR_CONCEAL_MODE_OFF = 0, /* conceal off */ + ERROR_CONCEAL_MODE_INTRA_ONLY = 1, /* intra conceal in intra-picture, inter-picture */ + ERROR_CONCEAL_MODE_INTRA_INTER = 2 +}; + +enum error_conceal_unit { + ERROR_CONCEAL_UNIT_PICTURE = 0, /* picture-level error conceal */ + ERROR_CONCEAL_UNIT_SLICE_TILE = 1, /* slice/tile-level error conceal */ + ERROR_CONCEAL_UNIT_BLOCK_ROW = 2, /* block-row-level error conceal */ + ERROR_CONCEAL_UNIT_BLOCK = 3 /* block-level conceal */ +}; + +enum cb_cr_order { + CBCR_ORDER_NORMAL, + CBCR_ORDER_REVERSED +}; + +enum mirror_direction { + MIRDIR_NONE, /* no mirroring */ + MIRDIR_VER, /* vertical mirroring */ + MIRDIR_HOR, /* horizontal mirroring */ + MIRDIR_HOR_VER /* horizontal and vertical mirroring */ +}; + +enum frame_buffer_format { + FORMAT_ERR = -1, + FORMAT_420 = 0, /* 8bit */ + FORMAT_422, /* 8bit */ + FORMAT_224, /* 8bit */ + FORMAT_444, /* 8bit */ + FORMAT_400, /* 8bit */ + + /* little endian perspective */ + /* | addr 0 | addr 1 | */ + FORMAT_420_P10_16BIT_MSB = 5, /* lsb |000000xx|xxxxxxxx | msb */ + FORMAT_420_P10_16BIT_LSB, /* lsb |xxxxxxx |xx000000 | msb */ + FORMAT_420_P10_32BIT_MSB, /* lsb |00xxxxxxxxxxxxxxxxxxxxxxxxxxx| msb */ + FORMAT_420_P10_32BIT_LSB, /* lsb |xxxxxxxxxxxxxxxxxxxxxxxxxxx00| msb */ + + /* 4:2:2 packed format */ + /* little endian perspective */ + /* | addr 0 | addr 1 | */ + FORMAT_422_P10_16BIT_MSB, /* lsb |000000xx |xxxxxxxx | msb */ + FORMAT_422_P10_16BIT_LSB, /* lsb |xxxxxxxx |xx000000 | msb */ + FORMAT_422_P10_32BIT_MSB, /* lsb |00xxxxxxxxxxxxxxxxxxxxxxxxxxx| msb */ + FORMAT_422_P10_32BIT_LSB, /* lsb |xxxxxxxxxxxxxxxxxxxxxxxxxxx00| msb */ + + FORMAT_YUYV, /* 8bit packed format : Y0U0Y1V0 Y2U1Y3V1 ... */ + FORMAT_YUYV_P10_16BIT_MSB, + FORMAT_YUYV_P10_16BIT_LSB, + FORMAT_YUYV_P10_32BIT_MSB, + FORMAT_YUYV_P10_32BIT_LSB, + + FORMAT_YVYU, /* 8bit packed format : Y0V0Y1U0 Y2V1Y3U1 ... */ + FORMAT_YVYU_P10_16BIT_MSB, + FORMAT_YVYU_P10_16BIT_LSB, + FORMAT_YVYU_P10_32BIT_MSB, + FORMAT_YVYU_P10_32BIT_LSB, + + FORMAT_UYVY, /* 8bit packed format : U0Y0V0Y1 U1Y2V1Y3 ... */ + FORMAT_UYVY_P10_16BIT_MSB, + FORMAT_UYVY_P10_16BIT_LSB, + FORMAT_UYVY_P10_32BIT_MSB, + FORMAT_UYVY_P10_32BIT_LSB, + + FORMAT_VYUY, /* 8bit packed format : V0Y0U0Y1 V1Y2U1Y3 ... */ + FORMAT_VYUY_P10_16BIT_MSB, + FORMAT_VYUY_P10_16BIT_LSB, + FORMAT_VYUY_P10_32BIT_MSB, + FORMAT_VYUY_P10_32BIT_LSB, + + FORMAT_MAX, +}; + +enum packed_format_num { + NOT_PACKED = 0, + PACKED_YUYV, + PACKED_YVYU, + PACKED_UYVY, + PACKED_VYUY, +}; + +enum wave5_interrupt_bit { + INT_WAVE5_INIT_VPU = 0, + INT_WAVE5_WAKEUP_VPU = 1, + INT_WAVE5_SLEEP_VPU = 2, + INT_WAVE5_CREATE_INSTANCE = 3, + INT_WAVE5_FLUSH_INSTANCE = 4, + INT_WAVE5_DESTROY_INSTANCE = 5, + INT_WAVE5_INIT_SEQ = 6, + INT_WAVE5_SET_FRAMEBUF = 7, + INT_WAVE5_DEC_PIC = 8, + INT_WAVE5_ENC_PIC = 8, + INT_WAVE5_ENC_SET_PARAM = 9, + INT_WAVE5_DEC_QUERY = 14, + INT_WAVE5_BSBUF_EMPTY = 15, + INT_WAVE5_BSBUF_FULL = 15, +}; + +enum pic_type { + PIC_TYPE_I = 0, /* I picture */ + PIC_TYPE_KEY = 0, /* KEY frame for AV1*/ + PIC_TYPE_P = 1, /* P picture */ + PIC_TYPE_INTER = 1, /* inter frame for AV1*/ + PIC_TYPE_B = 2, /* B picture (except VC1) */ + PIC_TYPE_REPEAT = 2, /* repeat frame (VP9 only) */ + PIC_TYPE_AV1_INTRA = 2, /* intra only frame (AV1 only) */ + PIC_TYPE_VC1_BI = 2, /* VC1 BI picture (VC1 only) */ + PIC_TYPE_VC1_B = 3, /* VC1 B picture (VC1 only) */ + PIC_TYPE_D = 3, + PIC_TYPE_S = 3, + PIC_TYPE_AVS2_F = 3, /* F picture in AVS2 */ + PIC_TYPE_AV1_SWITCH = 3, /* switch frame (AV1 only) */ + PIC_TYPE_VC1_P_SKIP = 4, /* VC1 P skip picture (VC1 only) */ + PIC_TYPE_MP4_P_SKIP_NOT_CODED = 4, /* not coded P picture in MPEG4 packed mode */ + PIC_TYPE_AVS2_S = 4, /* S picture in AVS2 */ + PIC_TYPE_IDR = 5, /* H.264/H.265 IDR picture */ + PIC_TYPE_AVS2_G = 5, /* G picture in AVS2 */ + PIC_TYPE_AVS2_GB = 6, /* GB picture in AVS2 */ + PIC_TYPE_MAX /* no meaning */ +}; + +enum bit_stream_mode { + BS_MODE_INTERRUPT, + BS_MODE_RESERVED, /* reserved for the future */ + BS_MODE_PIC_END, +}; + +enum sw_reset_mode { + SW_RESET_SAFETY, + SW_RESET_FORCE, + SW_RESET_ON_BOOT +}; + +enum tiled_map_type { + LINEAR_FRAME_MAP = 0, /* linear frame map type */ + COMPRESSED_FRAME_MAP = 17, /* compressed frame map type*/ +}; + +enum temporal_id_mode { + TEMPORAL_ID_MODE_ABSOLUTE, + TEMPORAL_ID_MODE_RELATIVE, +}; + +struct vpu_attr { + u32 product_id; /* the product ID */ + char product_name[8]; /* the product name in ascii code */ + u32 product_version; /* the product version number */ + u32 fw_version; /* the F/W version */ + u32 customer_id; /* customer ID number */ + u32 support_decoders; /* bitmask: see <<vpuapi_h_cod_std>> */ + u32 support_encoders; /* bitmask: see <<vpuapi_h_cod_std>> */ + bool support_bitstream_mode; + bool support_backbone; + bool support_avc10bit_enc; + bool support_hevc10bit_enc; + u32 support_endian_mask; /* A variable of supported endian mode in product */ + bool support_dual_core; /* this indicates whether a product has two vcores. */ + bool support_vcore_backbone; + bool support_vcpu_backbone; +}; + +struct frame_buffer { + dma_addr_t buf_y; + dma_addr_t buf_cb; + dma_addr_t buf_cr; + u32 buf_y_size; + u32 buf_cb_size; + u32 buf_cr_size; + int cbcr_interleave; + int endian; + enum tiled_map_type map_type; + int stride; /* A horizontal stride for given frame buffer */ + int width; /* A width for given frame buffer */ + int height; /* A height for given frame buffer */ + int size; /* A size for given frame buffer */ + int sequence_no; + bool update_fb_info; +}; + +struct vpu_rect { + u32 left; /* A horizontal pixel offset of top-left corner of rectangle from (0, 0) */ + u32 top; /* A vertical pixel offset of top-left corner of rectangle from (0, 0) */ + u32 right; /* A horizontal pixel offset of bottom-right corner of rectangle from (0, 0) */ + u32 bottom; /* A vertical pixel offset of bottom-right corner of rectangle from (0, 0) */ +}; + +/* + * decode struct and definition + */ + +struct dec_open_param { + dma_addr_t bitstream_buffer; + int bitstream_buffer_size; + int cbcr_interleave; + int nv21; + int cbcr_order; + enum endian_mode frame_endian; + enum endian_mode stream_endian; + enum bit_stream_mode bitstream_mode; + bool enable_non_ref_fbc_write; + int av1_format; + enum error_conceal_unit error_conceal_unit; + enum error_conceal_mode error_conceal_mode; +}; + +struct dec_initial_info { + s32 pic_width; + s32 pic_height; + s32 f_rate_numerator; /* the numerator part of frame rate fraction */ + s32 f_rate_denominator; /* the denominator part of frame rate fraction */ + struct vpu_rect pic_crop_rect; + s32 min_frame_buffer_count; + s32 frame_buf_delay; + + s32 max_temporal_layers; /* it indicates the max number of temporal sub-layers. */ + s32 max_spatial_layers; + s32 profile; + s32 level; + s32 tier; + s32 interlace; + s32 is_ext_sar; + s32 aspect_rate_info; + s32 bit_rate; + u32 user_data_header; + s32 user_data_num; + s32 user_data_size; + s32 user_data_buf_full; + s32 chroma_format_idc;/* A chroma format indicator */ + s32 luma_bitdepth; /* A bit-depth of luma sample */ + s32 chroma_bitdepth; /* A bit-depth of chroma sample */ + u32 seq_init_err_reason; + s32 warn_info; + dma_addr_t rd_ptr; /* A read pointer of bitstream buffer */ + dma_addr_t wr_ptr; /* A write pointer of bitstream buffer */ + u32 sequence_no; + u32 output_bit_depth; + u32 vlc_buf_size; /* the size of vlc buffer */ + u32 param_buf_size; /* the size of param buffer */ +}; + +#define WAVE_SKIPMODE_WAVE_NONE 0 +#define WAVE_SKIPMODE_NON_IRAP 1 +#define WAVE_SKIPMODE_NON_REF 2 + +struct dec_param { + s32 skipframe_mode; + bool cra_as_bla_flag; + bool disable_film_grain; +}; + +struct dec_output_ext_data { + u32 user_data_header; + u32 user_data_num; /* this is the number of user data. */ + u32 user_data_size; /* this is the size of user data. */ + u32 user_data_buf_full; + u32 active_format; +}; + +struct h265_rp_sei { + unsigned int exist; + int recovery_poc_cnt; /* recovery_poc_cnt */ + int exact_match_flag; /* exact_match_flag */ + int broken_link_flag; /* broken_link_flag */ +}; + +struct avs2_info { + int decoded_poi; + int display_poi; +}; + +struct av1_info { + int allow_screen_content_tools; /* it indicates whether screen content tool is enabled. */ + int allow_intra_bc; /* it indicates whether intra block copy is enabled. */ + int spatial_id; /* it indicates a spatial ID of the picture. */ +}; + +struct dec_output_info { + /** + * this is a frame buffer index for the picture to be displayed at the moment among + * frame buffers which are registered using vpu_dec_register_frame_buffer(). frame + * data to be displayed are stored into the frame buffer with this index. + * when there is no display delay, this index is always + * the same with index_frame_decoded. however, if display delay does exist for display + * reordering in AVC + * or B-frames in VC1), this index might be different with index_frame_decoded. + * by checking this index, HOST application can easily know whether sequence decoding + * has been finished or not. + * + * -3(0xFFFD) or -2(0xFFFE) : it is when a display output cannot be given due to picture + * reordering or skip option. + * -1(0xFFFF) : it is when there is no more output for display at the end of sequence + * decoding. + */ + int index_frame_display; + int index_frame_display_for_tiled; /* in case of WTL mode, this index indicates a display + * index of tiled or compressed framebuffer. + */ + /** + * this is a frame buffer index of decoded picture among frame buffers which were + * registered using vpu_dec_register_frame_buffer(). the currently decoded frame is stored + * into the frame buffer specified by + * this index. + * + * -2 : it indicates that no decoded output is generated because decoder meets EOS + * (end of sequence) or skip. + * -1 : it indicates that decoder fails to decode a picture because there is no available + * frame buffer. + */ + int index_frame_decoded; + int index_inter_frame_decoded; + int index_frame_decoded_for_tiled; + int nal_type; + int pic_type; + int num_of_err_m_bs; + int num_of_tot_m_bs; + int num_of_err_m_bs_in_display; + int num_of_tot_m_bs_in_display; + u32 decoding_success; + struct vpu_rect rc_display; + int disp_pic_width; + int disp_pic_height; + struct vpu_rect rc_decoded; + int dec_pic_width; + int dec_pic_height; + struct avs2_info avs2_info; + struct av1_info av1_info; + int decoded_poc; + int display_poc; + int temporal_id; /* A temporal ID of the picture */ + struct h265_rp_sei h265_rp_sei; + struct dec_output_ext_data dec_output_ext_data; + int consumed_byte; /* the number of bytes that are consumed by VPU. */ + int rd_ptr; /* A stream buffer read pointer for the current decoder instance */ + int wr_ptr; /* A stream buffer write pointer for the current decoder instance */ + dma_addr_t byte_pos_frame_start; + dma_addr_t byte_pos_frame_end; + struct frame_buffer disp_frame; + int frame_display_flag; /* it reports a frame buffer flag to be displayed. */ + /** + * this variable reports that sequence has been changed while H.264/AVC stream decoding. + * if it is 1, HOST application can get the new sequence information by calling + * vpu_dec_get_initial_info() or vpu_dec_issue_seq_init(). + * + * for H.265/HEVC decoder, each bit has a different meaning as follows. + * + * sequence_changed[5] : it indicates that the profile_idc has been changed. + * sequence_changed[16] : it indicates that the resolution has been changed. + * sequence_changed[19] : it indicates that the required number of frame buffer has + * been changed. + */ + int sequence_changed; + int frame_cycle; /* this variable reports the number of cycles for processing a frame. */ + int error_reason; + u32 error_reason_ext; + int warn_info; + u32 sequence_no; + + u32 dec_host_cmd_tick; /* tick of DEC_PIC command for the picture */ + u32 dec_seek_start_tick; /* start tick of seeking slices of the picture */ + u32 dec_seek_end_tick; /* end tick of seeking slices of the picture */ + u32 dec_parse_start_tick; /* start tick of parsing slices of the picture */ + u32 dec_parse_end_tick; /* end tick of parsing slices of the picture */ + u32 dec_decode_start_tick; /* start tick of decoding slices of the picture */ + u32 dec_decode_end_tick; /* end tick of decoding slices of the picture */ + + u32 seek_cycle; + u32 parse_cycle; + u32 decoded_cycle; + + s32 ctu_size; + s32 output_flag; +}; + +struct queue_status_info { + u32 instance_queue_count; + u32 report_queue_count; +}; + +/* + * encode struct and definition + */ + +#define MAX_NUM_TEMPORAL_LAYER 7 +#define MAX_NUM_SPATIAL_LAYER 3 +#define MAX_GOP_NUM 8 + +struct custom_gop_pic_param { + int pic_type; /* A picture type of nth picture in the custom GOP */ + int poc_offset; /* A POC of nth picture in the custom GOP */ + int pic_qp; /* A quantization parameter of nth picture in the custom GOP */ + int use_multi_ref_p; /* use multiref pic for P picture. valid only if PIC_TYPE is P */ + int ref_poc_l0; /* A POC of reference L0 of nth picture in the custom GOP */ + int ref_poc_l1; /* A POC of reference L1 of nth picture in the custom GOP */ + int temporal_id; /* A temporal ID of nth picture in the custom GOP */ +}; + +struct custom_gop_param { + int custom_gop_size; /* the size of custom GOP (0~8) */ + struct custom_gop_pic_param pic_param[MAX_GOP_NUM]; +}; + +struct wave_custom_map_opt { + int roi_avg_qp; /* it sets an average QP of ROI map. */ + int custom_roi_map_enable; /* it enables ROI map. */ + int custom_lambda_map_enable; /* it enables custom lambda map. */ + int custom_mode_map_enable; + int custom_coef_drop_enable; + dma_addr_t addr_custom_map; +}; + +struct enc_wave_param { + /* + * A profile indicator (HEVC only) + * + * 0 : the firmware determines a profile according to internalbitdepth. + * 1 : main profile + * 2 : main10 profile + * 3 : main still picture profile + * in AVC encoder, a profile cannot be set by host application. the firmware decides it + * based on internalbitdepth. it is HIGH profile for bitdepth of 8 and HIGH10 profile for + * bitdepth of 10. + */ + int profile; + int en_still_picture; /* still picture profile */ + int level; /* A level indicator (level * 10) */ + int tier; /* 0=main, 1=high */ + int internal_bit_depth; + int gop_preset_idx; + int decoding_refresh_type; /* 0=non-IRAP, 1=CRA, 2=IDR */ + int intra_qp; /* A quantization parameter of intra picture */ + int intra_period; /* A period of intra picture in GOP size */ + int forced_idr_header_enable; + int conf_win_top; /* A top offset of conformance window */ + int conf_win_bot; /* A bottom offset of conformance window */ + int conf_win_left; /* A left offset of conformance window */ + int conf_win_right; /* A right offset of conformance window */ + int independ_slice_mode; /* 0=no-multi-slice, 1=slice-in-ctu-number*/ + int independ_slice_mode_arg; + int depend_slice_mode; + int depend_slice_mode_arg; + int intra_refresh_mode; + /* + * it specifies an intra CTU refresh interval. depending on intra_refresh_mode, + * it can mean one of the following. + * + * the number of consecutive CTU rows for intra_ctu_refresh_mode of 1 + * the number of consecutive CTU columns for intra_ctu_refresh_mode of 2 + * A step size in CTU for intra_ctu_refresh_mode of 3 + * the number of intra ct_us to be encoded in a picture for intra_ctu_refresh_mode of 4 + */ + int intra_refresh_arg; + /* + * 0 : custom setting + * 1 : recommended encoder parameters (slow encoding speed, highest picture quality) + * 2 : boost mode (normal encoding speed, moderate picture quality) + * 3 : fast mode (fast encoding speed, low picture quality) + */ + uint32_t use_recommend_enc_param: 2; + uint32_t max_num_merge: 2; + uint32_t scaling_list_enable: 2; + uint32_t bit_alloc_mode: 2; /* 0=ref-pic-priority, 1=uniform, 2=fixed_bit_ratio */ + int beta_offset_div2: 4; /* it sets beta_offset_div2 for deblocking filter. */ + int tc_offset_div2: 4; /* it sets tc_offset_div3 for deblocking filter. */ + int hvs_qp_scale: 4; /* QP scaling factor for CU QP adjustmnt if hvs_qp_scale_enable is 1 */ + int hvs_max_delta_qp; /* A maximum delta QP for HVS */ + /* + * A fixed bit ratio (1 ~ 255) for each picture of GOP's bit + * allocation + * + * N = 0 ~ (MAX_GOP_SIZE - 1) + * MAX_GOP_SIZE = 8 + * + * for instance when MAX_GOP_SIZE is 3, fixed_bit_ratio0, fixed_bit_ratio1, and + * fixed_bit_ratio2 can be set as 2, 1, and 1 repsectively for + * the fixed bit ratio 2:1:1. this is only valid when bit_alloc_mode is 2. + */ + u8 fixed_bit_ratio[MAX_GOP_NUM]; + struct custom_gop_param gop_param; /* <<vpuapi_h_custom_gop_param>> */ + u32 num_units_in_tick; + u32 time_scale; + u32 num_ticks_poc_diff_one; + int chroma_cb_qp_offset; /* the value of chroma(cb) QP offset */ + int chroma_cr_qp_offset; /* the value of chroma(cr) QP offset */ + int initial_rc_qp; + u32 nr_intra_weight_y; + u32 nr_intra_weight_cb; /* A weight to cb noise level for intra picture (0 ~ 31) */ + u32 nr_intra_weight_cr; /* A weight to cr noise level for intra picture (0 ~ 31) */ + u32 nr_inter_weight_y; + u32 nr_inter_weight_cb; /* A weight to cb noise level for inter picture (0 ~ 31) */ + u32 nr_inter_weight_cr; /* A weight to cr noise level for inter picture (0 ~ 31) */ + u32 nr_noise_sigma_y; /* Y noise standard deviation if nr_noise_est_enable is 0. */ + u32 nr_noise_sigma_cb;/* cb noise standard deviation if nr_noise_est_enable is 0. */ + u32 nr_noise_sigma_cr;/* cr noise standard deviation if nr_noise_est_enable is 0. */ + u32 bg_thr_diff; + u32 bg_thr_mean_diff; + u32 bg_lambda_qp; + int bg_delta_qp; + int pu04_delta_rate: 8; /* added to the total cost of 4x4 blocks */ + int pu08_delta_rate: 8; /* added to the total cost of 8x8 blocks */ + int pu16_delta_rate: 8; /* added to the total cost of 16x16 blocks */ + int pu32_delta_rate: 8; /* added to the total cost of 32x32 blocks */ + int pu04_intra_planar_delta_rate: 8; + int pu04_intra_dc_delta_rate: 8; + int pu04_intra_angle_delta_rate: 8; + int pu08_intra_planar_delta_rate: 8; + int pu08_intra_dc_delta_rate: 8; + int pu08_intra_angle_delta_rate: 8; + int pu16_intra_planar_delta_rate: 8; + int pu16_intra_dc_delta_rate: 8; + int pu16_intra_angle_delta_rate: 8; + int pu32_intra_planar_delta_rate: 8; + int pu32_intra_dc_delta_rate: 8; + int pu32_intra_angle_delta_rate: 8; + int cu08_intra_delta_rate: 8; + int cu08_inter_delta_rate: 8; + int cu08_merge_delta_rate: 8; + int cu16_intra_delta_rate: 8; + int cu16_inter_delta_rate: 8; + int cu16_merge_delta_rate: 8; + int cu32_intra_delta_rate: 8; + int cu32_inter_delta_rate: 8; + int cu32_merge_delta_rate: 8; + int coef_clear_disable: 8; + int min_qp_i; /* A minimum QP of I picture for rate control */ + int max_qp_i; /* A maximum QP of I picture for rate control */ + int min_qp_p; /* A minimum QP of P picture for rate control */ + int max_qp_p; /* A maximum QP of P picture for rate control */ + int min_qp_b; /* A minimum QP of B picture for rate control */ + int max_qp_b; /* A maximum QP of B picture for rate control */ + dma_addr_t custom_lambda_addr; /* it specifies the address of custom lambda map. */ + dma_addr_t user_scaling_list_addr; /* it specifies the address of user scaling list file. */ + int avc_idr_period;/* A period of IDR picture (0 ~ 1024). 0 - implies an infinite period */ + int avc_slice_mode; /* 0=none, 1=slice-in-mb-number */ + int avc_slice_arg; /* the number of MB for a slice when avc_slice_mode is set with 1 */ + int intra_mb_refresh_mode; /* 0=none, 1=row, 2=column, 3=step-size-in-mb */ + /** + * it specifies an intra MB refresh interval. depending on intra_mb_refresh_mode, + * it can mean one of the following. + * + * the number of consecutive MB rows for intra_mb_refresh_mode of 1
drivers/staging/media/wave5/vpuapi/vpuapi.h line 788
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +10
-0+* the number of consecutive MB columns for intra_mb_refresh_mode of 2 +* A step size in MB for intra_mb_refresh_mode of 3 +*/ +int intra_mb_refresh_arg; +int entropy_coding_mode;/* 0=CAVLC, 1=CABAC */ +u32 rc_weight_param; +u32 rc_weight_buf; + +/* flags */ + uint32_t lossless_enable: 1; /*enables lossless coding. */
Why the switch from u32 to uint32_t?
Quoted 22 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +22
-0+ uint32_t const_intra_pred_flag: 1; /*enables constrained intra prediction. */ + uint32_t tmvp_enable: 1; /*enables temporal motion vector prediction. */ + uint32_t wpp_enable: 1; + uint32_t disable_deblk: 1; /* it disables in-loop deblocking filtering. */ + uint32_t lf_cross_slice_boundary_enable: 1; + uint32_t skip_intra_trans: 1; + uint32_t sao_enable: 1; /* it enables SAO (sample adaptive offset). */ + uint32_t intra_nx_n_enable: 1; /* it enables intra nx_n p_us. */ + uint32_t cu_level_rc_enable: 1; /* it enable CU level rate control. */ + uint32_t hvs_qp_enable: 1; /* enable CU QP adjustment for subjective quality enhancement. */ + uint32_t roi_enable: 1; /* it enables ROI map. NOTE: it is valid when rate control is on. */ + uint32_t nr_y_enable: 1; /* it enables noise reduction algorithm to Y component. */ + uint32_t nr_noise_est_enable: 1; + uint32_t nr_cb_enable: 1; /* it enables noise reduction algorithm to cb component. */ + uint32_t nr_cr_enable: 1; /* it enables noise reduction algorithm to cr component. */ + uint32_t use_long_term: 1; /* it enables long-term reference function. */ + uint32_t monochrome_enable: 1; /* it enables monochrom encoding mode. */ + uint32_t strong_intra_smooth_enable: 1; /* it enables strong intra smoothing. */ + uint32_t weight_pred_enable: 1; /* it enables to use weighted prediction.*/ + uint32_t bg_detect_enable: 1; /* it enables background detection. */ + uint32_t custom_lambda_enable: 1; /* it enables custom lambda table. */ + uint32_t custom_md_enable: 1; /* it enables custom mode decision. */
drivers/staging/media/wave5/vpuapi/vpuapi.h line 820
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +10
-0+ uint32_t rdo_skip: 1; /* it skips RDO(rate distortion optimization). */ + uint32_t lambda_scaling_enable: 1; /* it enables lambda scaling using custom GOP. */ + uint32_t transform8x8_enable: 1; /* it enables 8x8 intra prediction and 8x8 transform. */ + uint32_t mb_level_rc_enable: 1; /* it enables MB-level rate control. */ + uint32_t s2fme_disable: 1; /* it disables s2me_fme (only for AVC encoder). */ +}; + +struct enc_sub_frame_sync_config { +u32 sub_frame_sync_mode;/* 0=wire-based, 1=register-based */ +u32 sub_frame_sync_on;
Bool?
Quoted 52 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +52
-0+}; + +struct enc_open_param { +dma_addr_t bitstream_buffer; +u32 bitstream_buffer_size; +int ring_buffer_enable; +int pic_width;/* the width of a picture to be encoded in unit of sample. */ +int pic_height;/* the height of a picture to be encoded in unit of sample. */ +int frame_rate_info;/* desired fps */ +int vbv_buffer_size; +int bit_rate;/* target bitrate in bps */ +int rc_enable;/* rate control */ +struct enc_wave_param wave_param; +int cbcr_interleave; +int cbcr_order; +int stream_endian; +int source_endian; +int line_buf_int_en; +int packed_format;/* <<vpuapi_h_packed_format_num>> */ +enum frame_buffer_format src_format; +enum frame_buffer_format output_format; +int nv21; +bool enable_pts;/* an enable flag to report PTS(presentation timestamp) */ +bool enable_non_ref_fbc_write; +int sub_frame_sync_enable; +int sub_frame_sync_mode; +u32 encode_hrd_rbsp_in_vps;/* it encodes the HRD syntax rbsp into VPS. */ +u32 hrd_rbsp_data_size;/* the bit size of the HRD rbsp data */ +dma_addr_t hrd_rbsp_data_addr;/* the address of the HRD rbsp data */ +u32 encode_vui_rbsp; +u32 vui_rbsp_data_size;/* the bit size of the VUI rbsp data */ +dma_addr_t vui_rbsp_data_addr;/* the address of the VUI rbsp data */ +}; + +struct enc_initial_info { +int min_frame_buffer_count;/* minimum number of frame buffer */ +int min_src_frame_count;/* minimum number of source buffer */ +int max_latency_pictures;/* maximum number of picture latency */ +int seq_init_err_reason;/* error information */ +int warn_info;/* warn information */ +u32 vlc_buf_size;/* the size of task buffer */ +u32 param_buf_size;/* the size of task buffer */ +}; + +struct enc_code_opt { +int implicit_header_encode; +int encode_vcl;/* A flag to encode VCL nal unit explicitly */ +int encode_vps;/* A flag to encode VPS nal unit explicitly */ +int encode_sps;/* A flag to encode SPS nal unit explicitly */ +int encode_pps;/* A flag to encode PPS nal unit explicitly */ +int encode_aud;/* A flag to encode AUD nal unit explicitly */ +int encode_eos;
drivers/staging/media/wave5/vpuapi/vpuapi.h line 882
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +10
-0+int encode_eob; +int encode_vui;/* A flag to encode VUI nal unit explicitly */ +}; + +struct enc_param { +struct frame_buffer *source_frame; +int skip_picture; +dma_addr_t pic_stream_buffer_addr; +int pic_stream_buffer_size; +int force_pic_qp_enable;/* flag used to force picture quantization parameter */
My concern with this is that it looks like it might come from the user and then it's negative leading to undefined behavior. But I looked and I don't think it's not actually possible to set this. Just delete any unused code.
drivers/staging/media/wave5/vpuapi/vpuapi.h line 887
Quoted 5 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +5
-0+int force_pic_qp_i; +int force_pic_qp_p; +int force_pic_qp_b; +int force_pic_type_enable;/* A flag to use a force picture type */ +int force_pic_type;
Same same. Delete.
Quoted 49 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +49
-0+int src_idx;/* A source frame buffer index */ +int src_end_flag; +struct enc_code_opt code_option; +u32 use_cur_src_as_longterm_pic; +u32 use_longterm_ref; +u64 pts;/* the presentation timestamp (PTS) of input source */ +struct wave_custom_map_opt custom_map_opt; +u32 wp_pix_sigma_y;/* pixel variance of Y component for weighted prediction */ +u32 wp_pix_sigma_cb;/* pixel variance of cb component for weighted prediction */ +u32 wp_pix_sigma_cr;/* pixel variance of cr component for weighted prediction */ +u32 wp_pix_mean_y;/* pixel mean value of Y component for weighted prediction */ +u32 wp_pix_mean_cb;/* pixel mean value of cb component for weighted prediction */ +u32 wp_pix_mean_cr;/* pixel mean value of cr component for weighted prediction */ +u32 force_all_ctu_coef_drop_enable;/* it forces all coefficients to be zero after TQ . */ +}; + +struct enc_output_info { +dma_addr_t bitstream_buffer; +u32 bitstream_size;/* the byte size of encoded bitstream */ +int bitstream_wrap_around; +int pic_type;/* <<vpuapi_h_pic_type>> */ +int num_of_slices;/* the number of slices of the currently being encoded picture */ +int recon_frame_index; +struct frame_buffer recon_frame; +int rd_ptr; +int wr_ptr; +int pic_skipped;/* whether the current encoding has been skipped or not */ +int num_of_intra;/* the number of intra coded block */ +int num_of_merge;/* the number of merge block in 8x8 */ +int num_of_skip_block;/* the number of skip block in 8x8 */ +int avg_ctu_qp;/* the average value of CTU q_ps */ +int enc_pic_byte;/* the number of encoded picture bytes */ +int enc_gop_pic_idx;/* the GOP index of the currently encoded picture */ +int enc_pic_poc;/* the POC(picture order count) of the currently encoded picture */ +int release_src_flag;/* the source buffer indicator of the encoded pictures */ +int enc_src_idx;/* the source buffer index of the currently encoded picture */ +int enc_vcl_nut; +int enc_pic_cnt;/* the encoded picture number */ +int error_reason;/* the error reason of the currently encoded picture */ +int warn_info;/* the warning information of the currently encoded picture */ +int frame_cycle;/* the param for reporting the cycle number of encoding one frame.*/ +u64 pts; +u32 enc_host_cmd_tick;/* tick of ENC_PIC command for the picture */ +u32 enc_prepare_start_tick;/* start tick of preparing slices of the picture */ +u32 enc_prepare_end_tick;/* end tick of preparing slices of the picture */ +u32 enc_processing_start_tick;/* start tick of processing slices of the picture */ +u32 enc_processing_end_tick;/* end tick of processing slices of the picture */ +u32 enc_encode_start_tick;/* start tick of encoding slices of the picture */ +u32 enc_encode_end_tick;/* end tick of encoding slices of the picture */
drivers/staging/media/wave5/vpuapi/vpuapi.h line 946
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +10
-0+u32 prepare_cycle;/* the number of cycles for preparing slices of a picture */ +u32 processing;/* the number of cycles for processing slices of a picture */ +u32 encoded_cycle;/* the number of cycles for encoding slices of a picture */ +u32 pic_distortion_low; +u32 pic_distortion_high; +}; + +enum ENC_PIC_CODE_OPTION { +CODEOPT_ENC_HEADER_IMPLICIT = (1 <<0 ), +CODEOPT_ENC_VCL = (1 <<1 ),/* A flag to encode VCL nal unit explicitly */
BIT(0)
BIT(1)
Quoted 14 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +14
-0+}; + +enum GOP_PRESET_IDX { +PRESET_IDX_CUSTOM_GOP =0 ,/* user defined GOP structure */ +PRESET_IDX_ALL_I =1 ,/* all intra, gopsize = 1 */ +PRESET_IDX_IPP =2 ,/* consecutive P, cyclic gopsize = 1 */ +PRESET_IDX_IBBB =3 ,/* consecutive B, cyclic gopsize = 1 */ +PRESET_IDX_IBPBP =4 ,/* gopsize = 2 */ +PRESET_IDX_IBBBP =5 ,/* gopsize = 4 */ +PRESET_IDX_IPPPP =6 ,/* consecutive P, cyclic gopsize = 4 */ +PRESET_IDX_IBBBB =7 ,/* consecutive B, cyclic gopsize = 4 */ +PRESET_IDX_RA_IB =8 ,/* random access, cyclic gopsize = 8 */ +PRESET_IDX_IPP_SINGLE =9 ,/* consecutive P, cyclic gopsize = 1, with single ref */ +};
drivers/staging/media/wave5/vpuapi/vpuapi.h line 970
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +10
-0+ +struct sec_axi_info { +struct { +int use_ip_enable; +int use_lf_row_enable; +int use_bit_enable; +int use_enc_rdo_enable; +int use_enc_lf_enable; + } wave; +int buf_size;
Delete all the extra spaces in this struct.
drivers/staging/media/wave5/vpuapi/vpuapi.h line 980
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +10
-0+dma_addr_t buf_base; +}; + +struct dec_info { +struct dec_open_param open_param; +struct dec_initial_info initial_info; +struct dec_initial_info new_seq_info;/* temporal new sequence information */ +dma_addr_t stream_wr_ptr; +dma_addr_t stream_rd_ptr; +int stream_endflag;
Make this a bool. Get rid of the "flag" in the name.
drivers/staging/media/wave5/vpuapi/vpuapi.h line 981
Quoted 1 line
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +1
-0+int frame_display_flag;
I haven't looked at the patches bug it's not clear how this is used. It's a bitmask so it should be unsigned and probably named something plural.
drivers/staging/media/wave5/vpuapi/vpuapi.h line 993
Quoted 12 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +12
-0+dma_addr_t stream_buf_start_addr; +dma_addr_t stream_buf_end_addr; +int stream_buf_size; +struct vpu_buf vb_mv[MAX_REG_FRAME ]; +struct vpu_buf vb_fbc_y_tbl[MAX_REG_FRAME ]; +struct vpu_buf vb_fbc_c_tbl[MAX_REG_FRAME ]; +int num_fbs_for_decoding; +int num_fbs_for_wtl; +int stride; +int rotation_enable; +int mirror_enable; +int dering_enable;
Make these bool.
Quoted 746 lines
drivers/staging/media/wave5/vpuapi/vpuapi.h new file +183
-0+enum mirror_direction mirror_direction; +int rotation_angle; +struct frame_buffer rotator_output; +int rotator_stride; +int initial_info_obtained; +struct sec_axi_info sec_axi_info; +int seq_init_escape; +dma_addr_t user_data_buf_addr; +u32 user_data_enable; +int user_data_buf_size; +int frame_start_pos; +int frame_end_pos; +struct vpu_buf vb_work; +struct vpu_buf vb_task; +struct dec_output_info dec_out_info[MAX_GDI_IDX ]; +int reorder_enable; +int thumbnail_mode; +int seq_change_mask; +enum temporal_id_mode temp_id_select_mode; +s32 target_temp_id; +s32 target_spatial_id; +s32 instance_queue_count; +s32 report_queue_count; +u32 first_cycle_check; +u32 cycle_per_tick; +u32 product_code; +u32 vlc_buf_size; +u32 param_buf_size; +}; + +struct enc_info { +struct enc_open_param open_param; +struct enc_initial_info initial_info; +dma_addr_t stream_rd_ptr; +dma_addr_t stream_wr_ptr; +dma_addr_t stream_buf_start_addr; +dma_addr_t stream_buf_end_addr; +int stream_buf_size; +int num_frame_buffers; +int stride; +int rotation_enable; +int mirror_enable; +enum mirror_direction mirror_direction; +int rotation_angle; +int initial_info_obtained; +int ring_buffer_enable; +struct sec_axi_info sec_axi_info; +struct enc_sub_frame_sync_config sub_frame_sync_config; +int line_buf_int_en; +struct vpu_buf vb_work; +struct vpu_buf vb_mv;/* col_mv buffer */ +struct vpu_buf vb_fbc_y_tbl;/* FBC luma table buffer */ +struct vpu_buf vb_fbc_c_tbl;/* FBC chroma table buffer */ +struct vpu_buf vb_sub_sam_buf;/* sub-sampled buffer for ME */ +struct vpu_buf vb_task; +u64 cur_pts;/* current timestamp in 90_k_hz */ +u64 pts_map[32 ];/* PTS mapped with source frame index */ +u32 instance_queue_count; +u32 report_queue_count; +u32 first_cycle_check; +u32 cycle_per_tick; +u32 product_code; +u32 vlc_buf_size; +u32 param_buf_size; +}; + +struct vpu_device { +struct device *dev; +struct v4l2_device v4l2_dev; +struct v4l2_m2m_dev *v4l2_m2m_dev; +struct video_device *video_dev_dec; +struct video_device *video_dev_enc; +struct mutex dev_lock;/* the lock for the src,dst v4l2 queues */ +struct mutex hw_lock;/* lock hw condigurations */ +struct kfifo irq_status; +int irq; +struct completion irq_done; +enum product_id product; +struct vpu_attr attr; +struct vpu_buf common_mem; +u32 last_performance_cycles; +struct vpu_buf sram_buf; +struct vpu_buf vdb_register; +int product_code; +struct ida inst_ida; +struct clk *clk; +}; + +struct vpu_instance ; + +struct vpu_instance_ops { +void (*start_process)(struct vpu_instance *inst); +void (*stop_process)(struct vpu_instance *inst); +void (*finish_process)(struct vpu_instance *inst); +}; + +struct vpu_instance { +struct v4l2_fh v4l2_fh; +struct v4l2_ctrl_handler v4l2_ctrl_hdl; +struct vpu_device *dev; + +struct v4l2_pix_format_mplane src_fmt; +struct v4l2_pix_format_mplane dst_fmt; +enum v4l2_colorspace colorspace; +enum v4l2_xfer_func xfer_func; +enum v4l2_ycbcr_encoding ycbcr_enc; +enum v4l2_quantization quantization; +enum v4l2_hsv_encoding hsv_enc; + +enum vpu_instance_state state; +enum vpu_instance_type type; +const struct vpu_instance_ops *ops; + +enum wave_std std; +int id; +union { +struct enc_info enc_info; +struct dec_info dec_info; + } *codec_info; +struct frame_buffer frame_buf[MAX_REG_FRAME ]; +struct vpu_buf frame_vbuf[MAX_REG_FRAME ]; +u32 min_dst_frame_buf_count; +u32 queued_src_buf_num; +u32 queued_dst_buf_num; +u64 timestamp; + +spinlock_t bitstream_lock;/* lock the src buf queue of the m2m ctx */ +struct vpu_buf bitstream_vbuf; +bool thumbnail_mode; + +unsigned int min_src_frame_buf_count; +unsigned int rot_angle; +unsigned int mirror_direction; +unsigned int profile; +unsigned int level; +unsigned int bit_depth; +unsigned int frame_rate; +unsigned int vbv_buf_size; +unsigned int min_qp_i; +unsigned int max_qp_i; +unsigned int min_qp_p; +unsigned int max_qp_p; +unsigned int min_qp_b; +unsigned int max_qp_b; +}; + +void vdi_write_register (struct vpu_device *vpu_device,unsigned int addr,unsigned int data); +unsigned int vdi_read_register (struct vpu_device *vpu_dev,unsigned int addr); +int vdi_clear_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb); +int vdi_allocate_dma_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb); +int vdi_write_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb,size_t offset,unsigned char *data,int len,int endian); +int vdi_convert_endian (struct vpu_device *vpu_dev,unsigned int endian); +void vdi_free_dma_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb); + +enum ret_code vpu_init_with_bitcode (struct device *dev,const uint16_t *bitcode,uint32_t size_in_word); +void vpu_clear_interrupt_ex (struct vpu_instance *inst,int32_t intr_flag); +enum ret_code vpu_get_version_info (struct device *dev,uint32_t *version_info,uint32_t *revision,uint32_t *product_id); +int vpu_dec_open_api (struct vpu_instance *vpu_inst,struct dec_open_param *pop); +enum ret_code vpu_dec_close (struct vpu_instance *inst); +enum ret_code vpu_dec_issue_seq_init (struct vpu_instance *inst); +enum ret_code vpu_dec_complete_seq_init (struct vpu_instance *inst,struct dec_initial_info *info); +enum ret_code vpu_dec_register_frame_buffer_ex (struct vpu_instance *inst,int num_of_dec_fbs, +int num_of_display_fbs,int stride,int height,int map_type); +enum ret_code vpu_dec_start_one_frame (struct vpu_instance *inst,struct dec_param *param); +enum ret_code vpu_dec_get_output_info (struct vpu_instance *inst,struct dec_output_info *info); +enum ret_code vpu_dec_give_command (struct vpu_instance *inst,enum codec_command cmd,void *parameter); +enum ret_code vpu_dec_get_bitstream_buffer (struct vpu_instance *inst,dma_addr_t *prd_prt, +dma_addr_t *pwr_ptr,uint32_t *size); +enum ret_code vpu_dec_update_bitstream_buffer (struct vpu_instance *inst,int size); +enum ret_code vpu_dec_clr_disp_flag (struct vpu_instance *inst,int index); + +int vpu_enc_open_api (struct vpu_instance *vpu_inst,struct enc_open_param *enc_op_param); +enum ret_code vpu_enc_close (struct vpu_instance *inst); +enum ret_code vpu_enc_issue_seq_init (struct vpu_instance *inst); +enum ret_code vpu_enc_complete_seq_init (struct vpu_instance *inst,struct enc_initial_info *info); +enum ret_code vpu_enc_register_frame_buffer (struct vpu_instance *inst,int num,int stride, +int height,enum tiled_map_type map_type); +enum ret_code vpu_enc_start_one_frame (struct vpu_instance *inst,struct enc_param *param); +enum ret_code vpu_enc_get_output_info (struct vpu_instance *inst,struct enc_output_info *info); +enum ret_code vpu_enc_give_command (struct vpu_instance *inst,enum codec_command cmd,void *parameter); + +#endif +drivers/staging/media/wave5/vpuapi/vpuconfig.h new file +81
-0@@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* +* Wave5 series multi-standard codec IP - product config definitions +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ + +#ifndef _VPU_CONFIG_H_ +#define _VPU_CONFIG_H_ + +#define WAVE517_CODE 0x5170 +#define WAVE537_CODE 0x5370 +#define WAVE511_CODE 0x5110 +#define WAVE521_CODE 0x5210 +#define WAVE521C_CODE 0x521c +#define WAVE521C_DUAL_CODE 0x521d // wave521 dual core +#define WAVE521E1_CODE 0x5211 + +#define PRODUCT_CODE_W_SERIES (x) ((x) == WAVE517_CODE || (x) == WAVE537_CODE || \ + (x) == WAVE511_CODE || (x) == WAVE521_CODE || \ + (x) == WAVE521E1_CODE || (x) == WAVE521C_CODE || (x) == WAVE521C_DUAL_CODE) + +#define WAVE517_WORKBUF_SIZE (2 * 1024 * 1024) +#define WAVE521ENC_WORKBUF_SIZE (128 * 1024) //HEVC 128K, AVC 40K +#define WAVE521DEC_WORKBUF_SIZE (1784 * 1024) + +#define MAX_NUM_INSTANCE 32 + +#define W5_MIN_ENC_PIC_WIDTH 256 +#define W5_MIN_ENC_PIC_HEIGHT 128 +#define W5_MAX_ENC_PIC_WIDTH 8192 +#define W5_MAX_ENC_PIC_HEIGHT 8192 + +// application specific configuration +#define VPU_ENC_TIMEOUT 60000 +#define VPU_DEC_TIMEOUT 60000 +#define VPU_BUSY_CHECK_TIMEOUT 10000 + +#define HOST_ENDIAN VDI_128BIT_LITTLE_ENDIAN +#define VPU_FRAME_ENDIAN HOST_ENDIAN +#define VPU_STREAM_ENDIAN HOST_ENDIAN +#define VPU_USER_DATA_ENDIAN HOST_ENDIAN +#define VPU_SOURCE_ENDIAN HOST_ENDIAN + +// for WAVE encoder +#define USE_SRC_PRP_AXI 0 +#define USE_SRC_PRI_AXI 1 +#define DEFAULT_SRC_AXI USE_SRC_PRP_AXI + +/************************************************************************/ +/* VPU COMMON MEMORY */ +/************************************************************************/ +#define VLC_BUF_NUM (3) + +#define COMMAND_QUEUE_DEPTH (4) + +#define W5_REMAP_INDEX0 0 +#define W5_REMAP_INDEX1 1 +#define W5_REMAP_MAX_SIZE (1024 * 1024) + +#define WAVE5_MAX_CODE_BUF_SIZE (2 * 1024 * 1024) +#define WAVE5_TEMPBUF_OFFSET WAVE5_MAX_CODE_BUF_SIZE +#define WAVE5_TEMPBUF_SIZE (1024 * 1024) + +#define SIZE_COMMON (WAVE5_MAX_CODE_BUF_SIZE + WAVE5_TEMPBUF_SIZE) + +//=====4. VPU REPORT MEMORY ======================// + +#define WAVE5_UPPER_PROC_AXI_ID 0x0 + +#define WAVE5_PROC_AXI_ID 0x0 +#define WAVE5_PRP_AXI_ID 0x0 +#define WAVE5_FBD_Y_AXI_ID 0x0 +#define WAVE5_FBC_Y_AXI_ID 0x0 +#define WAVE5_FBD_C_AXI_ID 0x0 +#define WAVE5_FBC_C_AXI_ID 0x0 +#define WAVE5_SEC_AXI_ID 0x0 +#define WAVE5_PRI_AXI_ID 0x0 + +#endif /* _VPU_CONFIG_H_ */ +drivers/staging/media/wave5/vpuapi/vpuerror.h new file +455
-0@@ -0,0 +1,455 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* +* Wave5 series multi-standard codec IP - error values +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ + +#ifndef ERROR_CODE_H_INCLUDED +#define ERROR_CODE_H_INCLUDED + +/* +* WAVE5 +*/ + +/************************************************************************/ +/* WAVE5 COMMON SYSTEM ERROR (FAIL_REASON) */ +/************************************************************************/ +#define WAVE5_SYSERR_QUEUEING_FAIL 0x00000001 +#define WAVE5_SYSERR_ACCESS_VIOLATION_HW 0x00000040 +#define WAVE5_SYSERR_BUS_ERROR 0x00000200 +#define WAVE5_SYSERR_DOUBLE_FAULT 0x00000400 +#define WAVE5_SYSERR_RESULT_NOT_READY 0x00000800 +#define WAVE5_SYSERR_VPU_STILL_RUNNING 0x00001000 +#define WAVE5_SYSERR_UNKNOWN_CMD 0x00002000 +#define WAVE5_SYSERR_UNKNOWN_CODEC_STD 0x00004000 +#define WAVE5_SYSERR_UNKNOWN_QUERY_OPTION 0x00008000 +#define WAVE5_SYSERR_VLC_BUF_FULL 0x00010000 +#define WAVE5_SYSERR_WATCHDOG_TIMEOUT 0x00020000 +#define WAVE5_SYSERR_VCPU_TIMEOUT 0x00080000 +#define WAVE5_SYSERR_TEMP_SEC_BUF_OVERFLOW 0x00200000 +#define WAVE5_SYSERR_NEED_MORE_TASK_BUF 0x00400000 +#define WAVE5_SYSERR_PRESCAN_ERR 0x00800000 +#define WAVE5_SYSERR_ENC_GBIN_OVERCONSUME 0x01000000 +#define WAVE5_SYSERR_ENC_MAX_ZERO_DETECT 0x02000000 +#define WAVE5_SYSERR_ENC_LVL_FIRST_ERROR 0x04000000 +#define WAVE5_SYSERR_ENC_EG_RANGE_OVER 0x08000000 +#define WAVE5_SYSERR_ENC_IRB_FRAME_DROP 0x10000000 +#define WAVE5_SYSERR_INPLACE_V 0x20000000 +#define WAVE5_SYSERR_FATAL_VPU_HANGUP 0xf0000000 + +/************************************************************************/ +/* WAVE5 COMMAND QUEUE ERROR (FAIL_REASON) */ +/************************************************************************/ +#define WAVE5_CMDQ_ERR_NOT_QUEABLE_CMD 0x00000001 +#define WAVE5_CMDQ_ERR_SKIP_MODE_ENABLE 0x00000002 +#define WAVE5_CMDQ_ERR_INST_FLUSHING 0x00000003 +#define WAVE5_CMDQ_ERR_INST_INACTIVE 0x00000004 +#define WAVE5_CMDQ_ERR_QUEUE_FAIL 0x00000005 +#define WAVE5_CMDQ_ERR_CMD_BUF_FULL 0x00000006 + +/************************************************************************/ +/* WAVE5 ERROR ON DECODER (ERR_INFO) */ +/************************************************************************/ +// HEVC +#define HEVC_SPSERR_SEQ_PARAMETER_SET_ID 0x00001000 +#define HEVC_SPSERR_CHROMA_FORMAT_IDC 0x00001001 +#define HEVC_SPSERR_PIC_WIDTH_IN_LUMA_SAMPLES 0x00001002 +#define HEVC_SPSERR_PIC_HEIGHT_IN_LUMA_SAMPLES 0x00001003 +#define HEVC_SPSERR_CONF_WIN_LEFT_OFFSET 0x00001004 +#define HEVC_SPSERR_CONF_WIN_RIGHT_OFFSET 0x00001005 +#define HEVC_SPSERR_CONF_WIN_TOP_OFFSET 0x00001006 +#define HEVC_SPSERR_CONF_WIN_BOTTOM_OFFSET 0x00001007 +#define HEVC_SPSERR_BIT_DEPTH_LUMA_MINUS8 0x00001008 +#define HEVC_SPSERR_BIT_DEPTH_CHROMA_MINUS8 0x00001009 +#define HEVC_SPSERR_LOG2_MAX_PIC_ORDER_CNT_LSB_MINUS4 0x0000100A +#define HEVC_SPSERR_SPS_MAX_DEC_PIC_BUFFERING 0x0000100B +#define HEVC_SPSERR_SPS_MAX_NUM_REORDER_PICS 0x0000100C +#define HEVC_SPSERR_SPS_MAX_LATENCY_INCREASE 0x0000100D +#define HEVC_SPSERR_LOG2_MIN_LUMA_CODING_BLOCK_SIZE_MINUS3 0x0000100E +#define HEVC_SPSERR_LOG2_DIFF_MAX_MIN_LUMA_CODING_BLOCK_SIZE 0x0000100F +#define HEVC_SPSERR_LOG2_MIN_TRANSFORM_BLOCK_SIZE_MINUS2 0x00001010 +#define HEVC_SPSERR_LOG2_DIFF_MAX_MIN_TRANSFORM_BLOCK_SIZE 0x00001011 +#define HEVC_SPSERR_MAX_TRANSFORM_HIERARCHY_DEPTH_INTER 0x00001012 +#define HEVC_SPSERR_MAX_TRANSFORM_HIERARCHY_DEPTH_INTRA 0x00001013 +#define HEVC_SPSERR_SCALING_LIST 0x00001014 +#define HEVC_SPSERR_LOG2_DIFF_MIN_PCM_LUMA_CODING_BLOCK_SIZE_MINUS3 0x00001015 +#define HEVC_SPSERR_LOG2_DIFF_MAX_MIN_PCM_LUMA_CODING_BLOCK_SIZE 0x00001016 +#define HEVC_SPSERR_NUM_SHORT_TERM_REF_PIC_SETS 0x00001017 +#define HEVC_SPSERR_NUM_LONG_TERM_REF_PICS_SPS 0x00001018 +#define HEVC_SPSERR_GBU_PARSING_ERROR 0x00001019 +#define HEVC_SPSERR_EXTENSION_FLAG 0x0000101A +#define HEVC_SPSERR_VUI_ERROR 0x0000101B +#define HEVC_SPSERR_ACTIVATE_SPS 0x0000101C +#define HEVC_SPSERR_PROFILE_SPACE 0x0000101D +#define HEVC_PPSERR_PPS_PIC_PARAMETER_SET_ID 0x00002000 +#define HEVC_PPSERR_PPS_SEQ_PARAMETER_SET_ID 0x00002001 +#define HEVC_PPSERR_NUM_REF_IDX_L0_DEFAULT_ACTIVE_MINUS1 0x00002002 +#define HEVC_PPSERR_NUM_REF_IDX_L1_DEFAULT_ACTIVE_MINUS1 0x00002003 +#define HEVC_PPSERR_INIT_QP_MINUS26 0x00002004 +#define HEVC_PPSERR_DIFF_CU_QP_DELTA_DEPTH 0x00002005 +#define HEVC_PPSERR_PPS_CB_QP_OFFSET 0x00002006 +#define HEVC_PPSERR_PPS_CR_QP_OFFSET 0x00002007 +#define HEVC_PPSERR_NUM_TILE_COLUMNS_MINUS1 0x00002008 +#define HEVC_PPSERR_NUM_TILE_ROWS_MINUS1 0x00002009 +#define HEVC_PPSERR_COLUMN_WIDTH_MINUS1 0x0000200A +#define HEVC_PPSERR_ROW_HEIGHT_MINUS1 0x0000200B +#define HEVC_PPSERR_PPS_BETA_OFFSET_DIV2 0x0000200C +#define HEVC_PPSERR_PPS_TC_OFFSET_DIV2 0x0000200D +#define HEVC_PPSERR_SCALING_LIST 0x0000200E +#define HEVC_PPSERR_LOG2_PARALLEL_MERGE_LEVEL_MINUS2 0x0000200F +#define HEVC_PPSERR_NUM_TILE_COLUMNS_RANGE_OUT 0x00002010 +#define HEVC_PPSERR_NUM_TILE_ROWS_RANGE_OUT 0x00002011 +#define HEVC_PPSERR_MORE_RBSP_DATA_ERROR 0x00002012 +#define HEVC_PPSERR_PPS_PIC_PARAMETER_SET_ID_RANGE_OUT 0x00002013 +#define HEVC_PPSERR_PPS_SEQ_PARAMETER_SET_ID_RANGE_OUT 0x00002014 +#define HEVC_PPSERR_NUM_REF_IDX_L0_DEFAULT_ACTIVE_MINUS1_RANGE_OUT 0x00002015 +#define HEVC_PPSERR_NUM_REF_IDX_L1_DEFAULT_ACTIVE_MINUS1_RANGE_OUT 0x00002016 +#define HEVC_PPSERR_PPS_CB_QP_OFFSET_RANGE_OUT 0x00002017 +#define HEVC_PPSERR_PPS_CR_QP_OFFSET_RANGE_OUT 0x00002018 +#define HEVC_PPSERR_COLUMN_WIDTH_MINUS1_RANGE_OUT 0x00002019 +#define HEVC_PPSERR_ROW_HEIGHT_MINUS1_RANGE_OUT 0x00002020 +#define HEVC_PPSERR_PPS_BETA_OFFSET_DIV2_RANGE_OUT 0x00002021 +#define HEVC_PPSERR_PPS_TC_OFFSET_DIV2_RANGE_OUT 0x00002022 +#define HEVC_SHERR_SLICE_PIC_PARAMETER_SET_ID 0x00003000 +#define HEVC_SHERR_ACTIVATE_PPS 0x00003001 +#define HEVC_SHERR_ACTIVATE_SPS 0x00003002 +#define HEVC_SHERR_SLICE_TYPE 0x00003003 +#define HEVC_SHERR_FIRST_SLICE_IS_DEPENDENT_SLICE 0x00003004 +#define HEVC_SHERR_SHORT_TERM_REF_PIC_SET_SPS_FLAG 0x00003005 +#define HEVC_SHERR_SHORT_TERM_REF_PIC_SET 0x00003006 +#define HEVC_SHERR_SHORT_TERM_REF_PIC_SET_IDX 0x00003007 +#define HEVC_SHERR_NUM_LONG_TERM_SPS 0x00003008 +#define HEVC_SHERR_NUM_LONG_TERM_PICS 0x00003009 +#define HEVC_SHERR_LT_IDX_SPS_IS_OUT_OF_RANGE 0x0000300A +#define HEVC_SHERR_DELTA_POC_MSB_CYCLE_LT 0x0000300B +#define HEVC_SHERR_NUM_REF_IDX_L0_ACTIVE_MINUS1 0x0000300C +#define HEVC_SHERR_NUM_REF_IDX_L1_ACTIVE_MINUS1 0x0000300D +#define HEVC_SHERR_COLLOCATED_REF_IDX 0x0000300E +#define HEVC_SHERR_PRED_WEIGHT_TABLE 0x0000300F +#define HEVC_SHERR_FIVE_MINUS_MAX_NUM_MERGE_CAND 0x00003010 +#define HEVC_SHERR_SLICE_QP_DELTA 0x00003011 +#define HEVC_SHERR_SLICE_QP_DELTA_IS_OUT_OF_RANGE 0x00003012 +#define HEVC_SHERR_SLICE_CB_QP_OFFSET 0x00003013 +#define HEVC_SHERR_SLICE_CR_QP_OFFSET 0x00003014 +#define HEVC_SHERR_SLICE_BETA_OFFSET_DIV2 0x00003015 +#define HEVC_SHERR_SLICE_TC_OFFSET_DIV2 0x00003016 +#define HEVC_SHERR_NUM_ENTRY_POINT_OFFSETS 0x00003017 +#define HEVC_SHERR_OFFSET_LEN_MINUS1 0x00003018 +#define HEVC_SHERR_SLICE_SEGMENT_HEADER_EXTENSION_LENGTH 0x00003019 +#define HEVC_SHERR_WRONG_POC_IN_STILL_PICTURE_PROFILE 0x0000301A +#define HEVC_SHERR_SLICE_TYPE_ERROR_IN_STILL_PICTURE_PROFILE 0x0000301B +#define HEVC_SHERR_PPS_ID_NOT_EQUAL_PREV_VALUE 0x0000301C +#define HEVC_SPECERR_OVER_PICTURE_WIDTH_SIZE 0x00004000 +#define HEVC_SPECERR_OVER_PICTURE_HEIGHT_SIZE 0x00004001 +#define HEVC_SPECERR_OVER_CHROMA_FORMAT 0x00004002 +#define HEVC_SPECERR_OVER_BIT_DEPTH 0x00004003 +#define HEVC_SPECERR_OVER_BUFFER_OVER_FLOW 0x00004004 +#define HEVC_SPECERR_OVER_WRONG_BUFFER_ACCESS 0x00004005 +#define HEVC_ETCERR_INIT_SEQ_SPS_NOT_FOUND 0x00005000 +#define HEVC_ETCERR_DEC_PIC_VCL_NOT_FOUND 0x00005001 +#define HEVC_ETCERR_NO_VALID_SLICE_IN_AU 0x00005002 +#define HEVC_ETCERR_INPLACE_V 0x0000500F + +// AVC +#define AVC_SPSERR_SEQ_PARAMETER_SET_ID 0x00001000 +#define AVC_SPSERR_CHROMA_FORMAT_IDC 0x00001001 +#define AVC_SPSERR_PIC_WIDTH_IN_LUMA_SAMPLES 0x00001002 +#define AVC_SPSERR_PIC_HEIGHT_IN_LUMA_SAMPLES 0x00001003 +#define AVC_SPSERR_CONF_WIN_LEFT_OFFSET 0x00001004 +#define AVC_SPSERR_CONF_WIN_RIGHT_OFFSET 0x00001005 +#define AVC_SPSERR_CONF_WIN_TOP_OFFSET 0x00001006 +#define AVC_SPSERR_CONF_WIN_BOTTOM_OFFSET 0x00001007 +#define AVC_SPSERR_BIT_DEPTH_LUMA_MINUS8 0x00001008 +#define AVC_SPSERR_BIT_DEPTH_CHROMA_MINUS8 0x00001009 +#define AVC_SPSERR_SPS_MAX_DEC_PIC_BUFFERING 0x0000100B +#define AVC_SPSERR_SPS_MAX_NUM_REORDER_PICS 0x0000100C +#define AVC_SPSERR_SCALING_LIST 0x00001014 +#define AVC_SPSERR_GBU_PARSING_ERROR 0x00001019 +#define AVC_SPSERR_VUI_ERROR 0x0000101B +#define AVC_SPSERR_ACTIVATE_SPS 0x0000101C +#define AVC_PPSERR_PPS_PIC_PARAMETER_SET_ID 0x00002000 +#define AVC_PPSERR_PPS_SEQ_PARAMETER_SET_ID 0x00002001 +#define AVC_PPSERR_NUM_REF_IDX_L0_DEFAULT_ACTIVE_MINUS1 0x00002002 +#define AVC_PPSERR_NUM_REF_IDX_L1_DEFAULT_ACTIVE_MINUS1 0x00002003 +#define AVC_PPSERR_INIT_QP_MINUS26 0x00002004 +#define AVC_PPSERR_PPS_CB_QP_OFFSET 0x00002006 +#define AVC_PPSERR_PPS_CR_QP_OFFSET 0x00002007 +#define AVC_PPSERR_SCALING_LIST 0x0000200E +#define AVC_PPSERR_MORE_RBSP_DATA_ERROR 0x00002012 +#define AVC_PPSERR_PPS_PIC_PARAMETER_SET_ID_RANGE_OUT 0x00002013 +#define AVC_PPSERR_PPS_SEQ_PARAMETER_SET_ID_RANGE_OUT 0x00002014 +#define AVC_PPSERR_NUM_REF_IDX_L0_DEFAULT_ACTIVE_MINUS1_RANGE_OUT 0x00002015 +#define AVC_PPSERR_NUM_REF_IDX_L1_DEFAULT_ACTIVE_MINUS1_RANGE_OUT 0x00002016 +#define AVC_PPSERR_PPS_CB_QP_OFFSET_RANGE_OUT 0x00002017 +#define AVC_PPSERR_PPS_CR_QP_OFFSET_RANGE_OUT 0x00002018 +#define AVC_SHERR_SLICE_PIC_PARAMETER_SET_ID 0x00003000 +#define AVC_SHERR_ACTIVATE_PPS 0x00003001 +#define AVC_SHERR_ACTIVATE_SPS 0x00003002 +#define AVC_SHERR_SLICE_TYPE 0x00003003 +#define AVC_SHERR_FIRST_MB_IN_SLICE 0x00003004 +#define AVC_SHERR_RPLM 0x00003006 +#define AVC_SHERR_LT_IDX_SPS_IS_OUT_OF_RANGE 0x0000300A +#define AVC_SHERR_NUM_REF_IDX_L0_ACTIVE_MINUS1 0x0000300C +#define AVC_SHERR_NUM_REF_IDX_L1_ACTIVE_MINUS1 0x0000300D +#define AVC_SHERR_PRED_WEIGHT_TABLE 0x0000300F +#define AVC_SHERR_SLICE_QP_DELTA 0x00003011 +#define AVC_SHERR_SLICE_BETA_OFFSET_DIV2 0x00003015 +#define AVC_SHERR_SLICE_TC_OFFSET_DIV2 0x00003016 +#define AVC_SHERR_DISABLE_DEBLOCK_FILTER_IDC 0x00003017 +#define AVC_SPECERR_OVER_PICTURE_WIDTH_SIZE 0x00004000 +#define AVC_SPECERR_OVER_PICTURE_HEIGHT_SIZE 0x00004001 +#define AVC_SPECERR_OVER_CHROMA_FORMAT 0x00004002 +#define AVC_SPECERR_OVER_BIT_DEPTH 0x00004003 +#define AVC_SPECERR_OVER_BUFFER_OVER_FLOW 0x00004004 +#define AVC_SPECERR_OVER_WRONG_BUFFER_ACCESS 0x00004005 +#define AVC_ETCERR_INIT_SEQ_SPS_NOT_FOUND 0x00005000 +#define AVC_ETCERR_DEC_PIC_VCL_NOT_FOUND 0x00005001 +#define AVC_ETCERR_NO_VALID_SLICE_IN_AU 0x00005002 +#define AVC_ETCERR_ASO 0x00005004 +#define AVC_ETCERR_FMO 0x00005005 +#define AVC_ETCERR_INPLACE_V 0x0000500F + +// AV1 +#define AV1_SPSERR_MAX_FRAME_WIDTH 0x00001001 +#define AV1_SPSERR_MAX_FRAME_HEIGHT 0x00001002 +#define AV1_SPSERR_ID_LEN_EXCEED_16 0x00001004 +#define AV1_SPSERR_NOT_FOUND_FIRST_SPS 0x0000100A +#define AV1_SPSERR_SEQ_PROFILE 0x0000100B +#define AV1_SPSERR_STILL_PICTURE 0x0000100C +#define AV1_PPSERR_FRAME_SIZE_WIDTH 0x00002001 +#define AV1_PPSERR_FRAME_SIZE_HEIGHT 0x00002002 +#define AV1_PPSERR_SEEN_FRAME_HEADER 0x00002003 +#define AV1_PPSERR_REF_VALID 0x00002007 +#define AV1_PPSERR_LAST_ORDER_HINT 0x0000200B +#define AV1_PPSERR_GOLD_ORDER_HINT 0x0000200C +#define AV1_PPSERR_CODED_LOSSLESS_DELTA_Q 0x0000200E +#define AV1_PPSERR_FILM_GRAIN_PARAM_REF_IDX 0x0000200F +#define AV1_PPSERR_SEQ_CHANGE_BIT_DEPTH 0x00002010 +#define AV1_PPSERR_SEQ_CHANGE_PROFILE 0x00002012 +#define AV1_PPSERR_SEQ_CHANGE_DETECTED_INTER 0x00002013 +#define AV1_PPSERR_NUM_Y_POINTS 0x00002014 +#define AV1_PPSERR_POINT_Y_VALUE 0x00002015 +#define AV1_PPSERR_NUM_CB_POINTS 0x00002016 +#define AV1_PPSERR_POINT_CB_VALUE 0x00002017 +#define AV1_PPSERR_NUM_CR_POINTS 0x00002018 +#define AV1_PPSERR_POINT_CR_VALUE 0x00002019 +#define AV1_PPSERR_SUBSAMPLING_FORMAT 0x0000201A +#define AV1_FRAMEERR_TILE_START_END_PRESENT 0x00003001 +#define AV1_FRAMEERR_SHOW_EXISING_FRAME 0x00003002 +#define AV1_TGERR_NUM_TILES_ZERO 0x00004001 +#define AV1_TGERR_START_NOT_TILE_NUM 0x00004002 +#define AV1_TGERR_END_LESS_THAN_TG_START 0x00004003 +#define AV1_TGERR_TILE_SIZE_GREATER_THAN_32M 0x00004004 +#define AV1_SPECERR_OVER_MAX_H_SIZE 0x00005001 +#define AV1_SPECERR_OVER_MAX_V_SIZE 0x00005002 +#define AV1_SPECERR_OVER_MAX_TILE_COLS 0x00005004 +#define AV1_SPECERR_OVER_MAX_TILE_ROWS 0x00005005 +#define AV1_SPECERR_OVER_TILE_SIZE 0x00005006 +#define AV1_SPECERR_OVER_NUMTILES_GT_MAX_TILES 0x00005007 +#define AV1_ETCERR_OBU_HEADER 0x00006001 +#define AV1_ETCERR_OBU_SIZE 0x00006003 +#define AV1_ETCERR_OVERCONSUME 0x00006004 +#define AV1_ETCERR_NOT_SUPPORTED_FEATURE 0x00006005 +#define AV1_ETCERR_RESILIENCE_FAIL 0x00006006 + +// VP9 +#define VP9_PICERR_FRAME_MARKER 0x00001000 +#define VP9_PICERR_PROFILE 0x00001001 +#define VP9_PICERR_SYNC_CODE 0x00001002 +#define VP9_PICERR_PROFILE_COLOR_SAMPLE 0x00001003 +#define VP9_PICERR_FRAME_SIZE 0x00001004 +#define VP9_PICERR_SEGMENT 0x00001005 +#define VP9_PICERR_TILE 0x00001006 +#define VP9_PICERR_PROFILE_COMP_MISMATCH_WITH_REF 0x00001007 +#define VP9_PICERR_COMP_DAT_OVER_CS 0x00001008 +#define VP9_PICERR_COMP_TRAILING_BIT_ERR 0x00001009 +#define VP9_PICERR_MARKER 0x0000100A +#define VP9_PICERR_NOT_EXIST_REF_FRAME 0x0000100B +#define VP9_PICERR_UNINIT_CTX 0x0000100C +#define VP9_PICERR_FRAME_SIZE_LIMIT_BY_REF 0x0000100D +#define VP9_SPECERR_OVER_PICTURE_WIDTH_SIZE 0x00004000 +#define VP9_SPECERR_OVER_PICTURE_HEIGHT_SIZE 0x00004001 +#define VP9_SPECERR_OVER_CHROMA_FORMAT 0x00004002 +#define VP9_SPECERR_OVER_BIT_DEPTH 0x00004003 +#define VP9_ETCERR_INIT_KEY_FRAME_NOT_FOUND 0x00005000 +#define VP9_ETCERR_FORBIDDEN_BS_MODE 0x00005004 +#define VP9_ETCERR_SPP_OVER_CS_AU 0x00005005 + +// AVS2 +#define AVS2_SPSERR_PROFILE_ID 0x00001000 +#define AVS2_SPSERR_LEVEL_ID 0x00001001 +#define AVS2_SPSERR_HORIZONTAL_SIZE 0x00001002 +#define AVS2_SPSERR_VERTICAL_SIZE 0x00001003 +#define AVS2_SPSERR_CHROMA_FORMAT 0x00001004 +#define AVS2_SPSERR_SAMPLE_PRECISION 0x00001005 +#define AVS2_SPSERR_ENCODING_PRECISION 0x00001006 +#define AVS2_SPSERR_LCU_SIZE 0x00001007 +#define AVS2_SPSERR_WEIGHT_QUANT_MATRIX 0x00001008 +#define AVS2_SPSERR_NUM_OF_RCS 0x00001009 +#define AVS2_SPSERR_REFERENCE_CONFIGURATION_SET 0x0000100A +#define AVS2_SPSERR_OUTPUT_REORDER_DELAY 0x0000100B +#define AVS2_PPSERR_BBV_DELAY 0x00002000 +#define AVS2_PPSERR_TIME_CODE 0x00002001 +#define AVS2_PPSERR_DECODE_ORDER_INDEX 0x00002002 +#define AVS2_PPSERR_TEMPORAL_ID 0x00002003 +#define AVS2_PPSERR_PICTURE_OUTPUT_DELAY 0x00002004 +#define AVS2_PPSERR_RCS_INDEX 0x00002005 +#define AVS2_PPSERR_REFERENCE_CONFIGURATION_SET 0x00002006 +#define AVS2_PPSERR_BBV_CHECK_TIMES 0x00002007 +#define AVS2_PPSERR_PICTURE_QP 0x00002008 +#define AVS2_PPSERR_ALPHA_C_OFFSET 0x00002009 +#define AVS2_PPSERR_BETA_OFFSET 0x0000200A +#define AVS2_PPSERR_CHROMA_QUANT_PARAM_DELTA_CB 0x0000200B +#define AVS2_PPSERR_CHROMA_QUANT_PARAM_DELTA_CR 0x0000200C +#define AVS2_PPSERR_WEIGHT_QUANT_PARAM_DELTA1 0x0000200D +#define AVS2_PPSERR_WEIGHT_QUANT_PARAM_DELTA2 0x0000200E +#define AVS2_PPSERR_PICTURE_CODING_TYPE 0x0000200F +#define AVS2_PPSERR_ALF_FILTER_NUM_MINUS1 0x00002010 +#define AVS2_PPSERR_ALF_REGION_DISTANCE 0x00002011 +#define AVS2_PPSERR_ALF_COEFF_LUMA 0x00002012 +#define AVS2_PPSERR_ALF_COEFF_CHROMA_CB 0x00002013 +#define AVS2_PPSERR_ALF_COEFF_CHROMA_CR 0x00002014 +#define AVS2_SHERR_SLICE_VERTICAL_POSITION 0x00003000 +#define AVS2_SHERR_SLICE_VERTICAL_POSITION_EXTENSION 0x00003001 +#define AVS2_SHERR_SLICE_HORIZONTAL_POSITION 0x00003002 +#define AVS2_SHERR_SLICE_HORIZONTAL_POSITION_EXTENSION 0x00003003 +#define AVS2_SHERR_FIXED_SLICE_QP 0x00003004 +#define AVS2_SHERR_SLICE_QP 0x00003005 +#define AVS2_SHERR_SLICE_SAO_ENABLE_FLAG 0x00003006 +#define AVS2_SHERR_AEC_BYTE_ALIGNMENT_BIT 0x00003007 +#define AVS2_SHERR_STREAM_END 0x00003008 +#define AVS2_SPECERR_OVER_PICTURE_WIDTH_SIZE 0x00004000 +#define AVS2_SPECERR_OVER_PICTURE_HEIGHT_SIZE 0x00004001 +#define AVS2_SPECERR_OVER_CHROMA_FORMAT 0x00004002 +#define AVS2_SPECERR_OVER_BIT_DEPTH 0x00004003 +#define AVS2_SPECERR_OVER_REF_TEMPORAL_ID 0x00004004 +#define AVS2_ETCERR_SPS_NOT_FOUND 0x00005000 +#define AVS2_ETCERR_DEC_PIC_VCL_NOT_FOUND 0x00005001 +#define AVS2_ETCERR_NO_VALID_SLICE_IN_AU 0x00005002 +#define AVS2_ETCERR_PPS_ERROR 0x00005003 +#define AVS2_ETCERR_SLICE_NUM_OVERFLOW 0x00005004 + +/************************************************************************/ +/* WAVE5 WARNING ON DECODER (WARN_INFO) */ +/************************************************************************/ +// HEVC +#define HEVC_SPSWARN_MAX_SUB_LAYERS_MINUS1 0x00000001 +#define HEVC_SPSWARN_GENERAL_RESERVED_ZERO_44BITS 0x00000002 +#define HEVC_SPSWARN_RESERVED_ZERO_2BITS 0x00000004 +#define HEVC_SPSWARN_SUB_LAYER_RESERVED_ZERO_44BITS 0x00000008 +#define HEVC_SPSWARN_GENERAL_LEVEL_IDC 0x00000010 +#define HEVC_SPSWARN_SPS_MAX_DEC_PIC_BUFFERING_VALUE_OVER 0x00000020 +#define HEVC_SPSWARN_RBSP_TRAILING_BITS 0x00000040 +#define HEVC_SPSWARN_ST_RPS_UE_ERROR 0x00000080 +#define HEVC_SPSWARN_EXTENSION_FLAG 0x01000000 +#define HEVC_SPSWARN_REPLACED_WITH_PREV_SPS 0x02000000 +#define HEVC_PPSWARN_RBSP_TRAILING_BITS 0x00000100 +#define HEVC_PPSWARN_REPLACED_WITH_PREV_PPS 0x00000200 +#define HEVC_SHWARN_FIRST_SLICE_SEGMENT_IN_PIC_FLAG 0x00001000 +#define HEVC_SHWARN_NO_OUTPUT_OF_PRIOR_PICS_FLAG 0x00002000 +#define HEVC_SHWARN_PIC_OUTPUT_FLAG 0x00004000 +#define HEVC_SHWARN_DUPLICATED_SLICE_SEGMENT 0x00008000 +#define HEVC_ETCWARN_INIT_SEQ_VCL_NOT_FOUND 0x00010000 +#define HEVC_ETCWARN_MISSING_REFERENCE_PICTURE 0x00020000 +#define HEVC_ETCWARN_WRONG_TEMPORAL_ID 0x00040000 +#define HEVC_ETCWARN_ERROR_PICTURE_IS_REFERENCED 0x00080000 +#define HEVC_SPECWARN_OVER_PROFILE 0x00100000 +#define HEVC_SPECWARN_OVER_LEVEL 0x00200000 +#define HEVC_PRESWARN_PARSING_ERR 0x04000000 +#define HEVC_PRESWARN_MVD_OUT_OF_RANGE 0x08000000 +#define HEVC_PRESWARN_CU_QP_DELTA_VAL_OUT_OF_RANGE 0x09000000 +#define HEVC_PRESWARN_COEFF_LEVEL_REMAINING_OUT_OF_RANGE 0x0A000000 +#define HEVC_PRESWARN_PCM_ERR 0x0B000000 +#define HEVC_PRESWARN_OVERCONSUME 0x0C000000 +#define HEVC_PRESWARN_END_OF_SUBSET_ONE_BIT_ERR 0x10000000 +#define HEVC_PRESWARN_END_OF_SLICE_SEGMENT_FLAG 0x20000000 + +// AVC +#define AVC_SPSWARN_RESERVED_ZERO_2BITS 0x00000004 +#define AVC_SPSWARN_GENERAL_LEVEL_IDC 0x00000010 +#define AVC_SPSWARN_RBSP_TRAILING_BITS 0x00000040 +#define AVC_PPSWARN_RBSP_TRAILING_BITS 0x00000100 +#define AVC_SHWARN_NO_OUTPUT_OF_PRIOR_PICS_FLAG 0x00002000 +#define AVC_ETCWARN_INIT_SEQ_VCL_NOT_FOUND 0x00010000 +#define AVC_ETCWARN_MISSING_REFERENCE_PICTURE 0x00020000 +#define AVC_ETCWARN_ERROR_PICTURE_IS_REFERENCED 0x00080000 +#define AVC_SPECWARN_OVER_PROFILE 0x00100000 +#define AVC_SPECWARN_OVER_LEVEL 0x00200000 +#define AVC_PRESWARN_MVD_RANGE_OUT 0x00400000 +#define AVC_PRESWARN_MB_QPD_RANGE_OUT 0x00500000 +#define AVC_PRESWARN_COEFF_RANGE_OUT 0x00600000 +#define AVC_PRESWARN_MV_RANGE_OUT 0x00700000 +#define AVC_PRESWARN_MB_SKIP_RUN_RANGE_OUT 0x00800000 +#define AVC_PRESWARN_MB_TYPE_RANGE_OUT 0x00900000 +#define AVC_PRESWARN_SUB_MB_TYPE_RANGE_OUT 0x00A00000 +#define AVC_PRESWARN_CBP_RANGE_OUT 0x00B00000 +#define AVC_PRESWARN_INTRA_CHROMA_PRED_MODE_RANGE_OUT 0x00C00000 +#define AVC_PRESWARN_REF_IDX_RANGE_OUT 0x00D00000 +#define AVC_PRESWARN_COEFF_TOKEN_RANGE_OUT 0x00E00000 +#define AVC_PRESWARN_TOTAL_ZERO_RANGE_OUT 0x00F00000 +#define AVC_PRESWARN_RUN_BEFORE_RANGE_OUT 0x01000000 +#define AVC_PRESWARN_OVERCONSUME 0x01100000 +#define AVC_PRESWARN_MISSING_SLICE 0x01200000 + +// AV1 +#define AV1_SPSWARN_OBU_EXTENTION_FLAG_ZERO 0x00001000 +#define AV1_SPSWARN_DUPLICATE_OPERATING_POINT_IDX 0x00001001 +#define AV1_SPSWARN_MC_IDENTIY_SUBSAMPLING_X 0x00001002 +#define AV1_PPSWARN_MC_IDENTIY_SUBSAMPLING_Y 0x00001003 +#define AV1_SPSWARN_NUM_UNITS_IN_DISPLAY_TICK 0x00001004 +#define AV1_SPSWARN_TIME_SCALE_ZERO 0x00001005 +#define AV1_SPSWARN_NUM_TICKS_PER_PICTURE 0x00001006 +#define AV1_PPSWARN_TILE_WIDTH 0x00002001 +#define AV1_PPSWARN_TILE_HEIGHT 0x00002002 +#define AV1_PPSWARN_SHOW_EXISTING_KEY_FRAME_OUTPUT 0x00002004 +#define AV1_PPSWARN_DIFF_FRAME_ID 0x00002008 +#define AV1_PPSWARN_CURRENT_FRAME_ID 0x00002010 +#define AV1_PPSWARN_REFRESH_FRAME_FLAGS 0x00002020 +#define AV1_PPSWARN_DISPALY_ID 0x00002040 +#define AV1_PPSWARN_PREV_FRAME_SHOWABLE_FLAG_ZERO 0x00002080 +#define AV1_PPSWARN_EXPECTED_FRAME_ID 0x00002100 +#define AV1_SPECWARN_OVER_MAX_TILE_AREA_SB 0x00005000 +#define AV1_SPECWARN_OVER_MAX_PIC_SIZE 0x00005001 +#define AV1_ETCWARN_OBU_EXTENTION_FLAG 0x00006000 +#define AV1_TGWARN_TRAIL_BIT_POS 0x00400000 +#define AV1_TGWARN_TRAIL_PAD_BIT 0x00800000 +#define AV1_TGWARN_SYM_MAX_OVER 0x01000000 +#define AV1_TGWARN_EXP_GOLB_OVER 0x02000000 +#define AV1_TGWARN_MV_NOT_VAILD 0x04000000 + +// VP9 +#define VP9_PICWARN_COLOR_SPACE_MISMATCH_WITH_REF 0x00001000 +#define VP9_PRESWARN_OVERCONSUME 0x00400000 +#define VP9_PRESWARN_TRAILING_BITS 0x00800000 +#define VP9_PRESWARN_MARKER 0x01000000 +#define VP9_PRESWARN_MV_RANGE_OVER 0x02000000 +#define VP9_PRESWARN_MISIZE_SEG_LVL_ACTIVE 0x04000000 + +// AVS2 +#define AVS2_ETCWARN_INIT_SEQ_VCL_NOT_FOUND 0x00010000 +#define AVS2_ETCWARN_MISSING_REFERENCE_PICTURE 0x00020000 +#define AVS2_ETCWARN_WRONG_TEMPORAL_ID 0x00040000 +#define AVS2_ETCWARN_ERROR_PICTURE_IS_REFERENCED 0x00080000 +#define AVS2_ETCWARN_REF_WRONG_TEMPORAL_ID 0x00080001 +#define AVS2_ETCWARN_SPS_ERROR 0x00080002 + +/************************************************************************/ +/* WAVE5 ERROR ON ENCODER (ERR_INFO) */ +/************************************************************************/ + +/************************************************************************/ +/* WAVE5 WARNING ON ENCODER (WARN_INFO) */ +/************************************************************************/ +#define WAVE5_ETCWARN_FORCED_SPLIT_BY_CU8X8 0x000000001 + +/************************************************************************/ +/* WAVE5 debug info (PRI_REASON) */ +/************************************************************************/ +#define WAVE5_DEC_VCORE_VCE_HANGUP 0x0001 +#define WAVE5_DEC_VCORE_UNDETECTED_SYNTAX_ERR 0x0002 +#define WAVE5_DEC_VCORE_MIB_BUSY 0x0003 +#define WAVE5_DEC_VCORE_VLC_BUSY 0x0004 + +#endif /* ERROR_CODE_H_INCLUDED */ +drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +9
-0@@ -0,0 +1,3626 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - wave5 backend logic +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ + +#include <linux/iopoll.h> +#include "../../v4l2/vpu.h"
drivers/staging/media/wave5/vpuapi/wave/wave5.c line 19
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +10
-0+#include "wave5.h" +#include "wave5_regdefine.h" + +#define FIO_TIMEOUT 10000000 +#define FIO_CTRL_READY BIT(31) +#define FIO_CTRL_WRITE BIT(16) + +static unsigned int vdi_fio_read_register (struct vpu_device *vpu_dev,unsigned int addr) +{ +u32 ctrl =0 ;
Unused assignment.
drivers/staging/media/wave5/vpuapi/wave/wave5.c line 28
Quoted 9 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +9
-0+int ret; + + ctrl = addr &0xffff ; +vdi_write_register (vpu_dev,W5_VPU_FIO_CTRL_ADDR , ctrl); + ret =read_poll_timeout (vdi_read_register, ctrl, ctrl &FIO_CTRL_READY , +0 ,FIO_TIMEOUT , false, vpu_dev,W5_VPU_FIO_CTRL_ADDR ); +if (ret) +return 0xffffffff ; +else
Delete the else statement.
drivers/staging/media/wave5/vpuapi/wave/wave5.c line 34
Quoted 6 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +6
-0+return vdi_read_register (vpu_dev,W5_VPU_FIO_DATA ); +} + +static void vdi_fio_write_register (struct vpu_device *vpu_dev,unsigned int addr,unsigned int data) +{ +unsigned int ctrl;
Say u32 to be consistent.
Quoted 13 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +13
-0+ +vdi_write_register (vpu_dev,W5_VPU_FIO_DATA , data); + ctrl =FIO_CTRL_WRITE | (addr &0xffff ); +vdi_write_register (vpu_dev,W5_VPU_FIO_CTRL_ADDR , ctrl); +read_poll_timeout (vdi_read_register, ctrl, ctrl &FIO_CTRL_READY , +0 ,FIO_TIMEOUT , false, vpu_dev,W5_VPU_FIO_CTRL_ADDR ); +} + +static int vdi_wait_bus_busy (struct vpu_device *vpu_dev,int timeout,unsigned int addr) +{ +u32 gdi_status_check_value =0x3f ; +u32 data; +int ret;
drivers/staging/media/wave5/vpuapi/wave/wave5.c line 57
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +10
-0+ +if (vpu_dev->product_code ==WAVE521C_CODE || + vpu_dev->product_code ==WAVE521_CODE || + vpu_dev->product_code ==WAVE521E1_CODE ) + gdi_status_check_value =0x00ff1f3f ; + + ret =read_poll_timeout (vdi_read_register, data, data == gdi_status_check_value, +0 , timeout *1000 , false, vpu_dev, addr); +if (ret) +return -1 ;
return read_poll_timeout();
Fix the callers to not expect -1 as an error code.
Quoted 171 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +171
-0+ +return 0 ; +} + +static int vdi_wait_vpu_busy (struct vpu_device *vpu_dev,int timeout,unsigned int addr) +{ +int ret; +u32 data; + + ret =read_poll_timeout (vdi_read_register, data, data ==0 , +0 , timeout *1000 , false, vpu_dev, addr); +if (ret) +return -1 ; + +return 0 ; +} + +static int vdi_wait_vcpu_bus_busy (struct vpu_device *vpu_dev,int timeout,unsigned int addr) +{ +int ret; +u32 data; + + ret =read_poll_timeout (vdi_fio_read_register, data, data ==0 , +0 , timeout *1000 , false, vpu_dev, addr); +if (ret) +return -1 ; + +return 0 ; +} + +uint32_t wave5_vpu_is_init (struct vpu_device *vpu_dev) +{ +u32 pc; + + pc = (uint32_t )vpu_read_reg (vpu_dev,W5_VCPU_CUR_PC ); + +return pc; +} + +static struct vpu_buf *get_sram_memory (struct vpu_device *vpu_dev) +{ +u32 sram_size =0 ; +u32 val =vpu_read_reg (vpu_dev,W5_PRODUCT_NUMBER ); + +if (vpu_dev->sram_buf.size) +return &vpu_dev->sram_buf; + +switch (val) { +case WAVE511_CODE : +/* 10bit profile : 8_kx8_k -> 129024, 4_kx2_k -> 64512 +*/ + sram_size =0x1F800 ; +break ; +case WAVE517_CODE : +/* 10bit profile : 8_kx8_k -> 272384, 4_kx2_k -> 104448 +*/ + sram_size =0x42800 ; +break ; +case WAVE537_CODE : +/* 10bit profile : 8_kx8_k -> 272384, 4_kx2_k -> 104448 +*/ + sram_size =0x42800 ; +break ; +case WAVE521_CODE : +/* 10bit profile : 8_kx8_k -> 126976, 4_kx2_k -> 63488 +*/ + sram_size =0x1F000 ; +break ; +case WAVE521E1_CODE : +/* 10bit profile : 8_kx8_k -> 126976, 4_kx2_k -> 63488 +*/ + sram_size =0x1F000 ; +break ; +case WAVE521C_CODE : +/* 10bit profile : 8_kx8_k -> 129024, 4_kx2_k -> 64512 +* NOTE: decoder > encoder +*/ + sram_size =0x1F800 ; +break ; +case WAVE521C_DUAL_CODE : +/* 10bit profile : 8_kx8_k -> 129024, 4_kx2_k -> 64512 +* NOTE: decoder > encoder +*/ + sram_size =0x1F800 ; +break ; +default : +pr_err ("invalid check product_code(%x)\n" , val); +break ; + } + +// if we can know the sram address directly in vdi layer, we use it first for sdram address + vpu_dev->sram_buf.daddr =0 ; + vpu_dev->sram_buf.size = sram_size; + vpu_dev->sram_buf.vaddr =NULL ; + +return &vpu_dev->sram_buf; +} + +int32_t wave_vpu_get_product_id (struct vpu_device *vpu_dev) +{ +u32 product_id =PRODUCT_ID_NONE ; +u32 val; + + val =vpu_read_reg (vpu_dev,W5_PRODUCT_NUMBER ); + +switch (val) { +case WAVE521_CODE : + product_id =PRODUCT_ID_521 ;break ; +case WAVE521C_CODE : + product_id =PRODUCT_ID_521 ;break ; +case WAVE511_CODE : + product_id =PRODUCT_ID_511 ;break ; +case WAVE521C_DUAL_CODE : + product_id =PRODUCT_ID_521 ;break ; +case WAVE517_CODE : + product_id =PRODUCT_ID_517 ;break ; +case WAVE537_CODE : + product_id =PRODUCT_ID_517 ;break ; +case WAVE521E1_CODE : + product_id =PRODUCT_ID_521 ;break ; +default : +pr_err ("check product_id(%x)\n" , val); +break ; + } +return product_id; +} +Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/staging/media/wave5/vpuapi/wave/wave5.c line 194
Quoted 10 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +10
-0+void wave5_bit_issue_command (struct vpu_instance *vpu_inst,uint32_t cmd) +{ +u32 instance_index =0 ; +u32 codec_mode =0 ; + + instance_index = vpu_inst->id; + codec_mode = vpu_inst->std; + +vpu_write_reg (vpu_inst->dev,W5_CMD_INSTANCE_INFO , (codec_mode <<16 ) | + (instance_index &0xffff ));
Return directly if possible.
return RETCODE_QUERY_FAILURE;
Pull the remaining code in one indent level.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 120 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +120
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Delete this debug code.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 428 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +428
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Never use s32 except when describing hardware. Use int.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 2 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +2
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Change k to int. Iterators should always be int, ulong or u64. u32 iterators are pointless and nonsensical. GCC encourages this garbage because GCC is sometimes stupid.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 6 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +6
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Weird aligned declaration block.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 1 line
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Search for " =" and delete the extra spaces.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 49 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +49
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Delete spaces before ;
for (k = 0; k < mv_count; k++) {Search for " ;" and delete the extra spaces.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 3 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Every function must clean up after itself.
while (--k >= 0) free_whatever(p_dec_info->vb_mv[k]);
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 74 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +74
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Replace 1 << 14 with a define. (magic number).
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 135 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +135
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
This looks to be a new type of boolean value where -1 is false and 0 is true... :P Please don't do that.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 1,399 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +1399
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Search for s32 and change to int.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 9 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +9
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Use "struct vpu_buf vb_mv = { };"
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 16 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +16
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Align the indenting.
if ((p_enc_info->rotation_angle != 0 || p_enc_info->mirror_direction != 0) &&
!(p_enc_info->rotation_angle == 180 &&
p_enc_info->mirror_direction == MIRDIR_HOR_VER)) {drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 5 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +5
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
We've lift the 80 character limit but this would be more readable if it were written as:
if (p_enc_info->rotation_angle == 90 ||
p_enc_info->rotation_angle == 270) {That way your eye immediatly can spot the 90 and the 270.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 52 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +52
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Delete the commented out code. There is more later in the function as well.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 24 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +24
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
This function doesn't clean up after itself.
drivers/staging/media/wave5/vpuapi/wave/wave5.c
Quoted 3 lines
drivers/staging/media/wave5/vpuapi/wave/wave5.c new file +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Anway, there is a lot of code in this driver and hopefully these are ideas on where to start cleaning it up.
regards,
dan carpenter
Part of the diff is not shown here. View the raw message.
PATCH 2/6 staging: media: wave5: Add the vdi layer
In reply to Dafna HirschfeldAdd the vdi directory of the wave5 codec driver. The vdi.h header defines common helper functions such as writing/reading register and handling endianness.
--- drivers/staging/media/wave5/vdi/vdi.c | 325 ++++++++++++++++++++++++++ drivers/staging/media/wave5/vdi/vdi.h | 79 +++++++ 2 files changed, 404 insertions(+) create mode 100644 drivers/staging/media/wave5/vdi/vdi.c create mode 100644 drivers/staging/media/wave5/vdi/vdi.h
drivers/staging/media/wave5/vdi/vdi.c new file +325 -0
@@ -0,0 +1,325 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - low level access functions +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#include <linux/bug.h> +#include "vdi.h" +#include "../v4l2/vpu.h" +#include "../vpuapi/wave/wave5_regdefine.h" +#include <linux/delay.h> +#define VDI_SRAM_BASE_ADDR 0x00 + +#define VDI_SYSTEM_ENDIAN VDI_LITTLE_ENDIAN +#define VDI_128BIT_BUS_SYSTEM_ENDIAN VDI_128BIT_LITTLE_ENDIAN + +static int vdi_allocate_common_memory (struct device *dev) +{ +int ret; +struct vpu_device *vpu_dev =dev_get_drvdata (dev); + +if (!vpu_dev->common_mem.vaddr) { + vpu_dev->common_mem.size =SIZE_COMMON ; + ret =vdi_allocate_dma_memory (vpu_dev, &vpu_dev->common_mem); +if (ret) { +dev_err (dev,"unable to allocate common buffer\n" ); +return ret; + } + } + +dev_dbg (dev,"common_mem: daddr=%pad size=%zu vaddr=0x%p\n" , + &vpu_dev->common_mem.daddr, vpu_dev->common_mem.size, + vpu_dev->common_mem.vaddr); + +return 0 ; +} + +int vdi_init (struct device *dev) +{ +struct vpu_platform_data *pdata =dev_get_platdata (dev); +struct vpu_device *vpu_dev =dev_get_drvdata (dev); +int i; + +if (vdi_allocate_common_memory (dev) <0 ) { +pr_err ("[VDI] fail to get vpu common buffer from driver\n" ); + goto ERR_VDI_INIT; + } + +if (pdata && pdata->reset) + pdata->reset (dev, vpu_dev->vdb_register.vaddr); + +if (pdata && pdata->pre_fw_init) { +if (pdata->pre_fw_init (dev, vpu_dev->vdb_register.vaddr)) + goto ERR_VDI_INIT; + } + +if (PRODUCT_CODE_W_SERIES (vpu_dev->product_code)) { +// if BIT processor is not running. +if (vdi_read_register (vpu_dev,W5_VCPU_CUR_PC ) ==0 ) { +for (i =0 ; i <64 ; i++) +vdi_write_register (vpu_dev, (i *4 ) +0x100 ,0x0 ); + } + }else { +WARN_ONCE (1 ,"unsupported product code 0x%x\n" , vpu_dev->product_code); + } + +pr_info ("[VDI] success to init driver\n" ); + +return 0 ; + +ERR_VDI_INIT: + +vdi_release (dev); +return -1 ; +} +EXPORT_SYMBOL (vdi_init); + +int vdi_release (struct device *dev) +{ +struct vpu_device *vpu_dev =dev_get_drvdata (dev); + +memset (&vpu_dev->vdb_register,0x00 ,sizeof (vpu_dev->vdb_register)); +vdi_free_dma_memory (vpu_dev, &vpu_dev->common_mem); + +return 0 ; +} +EXPORT_SYMBOL (vdi_release); + +void vdi_write_register (struct vpu_device *vpu_dev,unsigned int addr,unsigned int data) +{ +struct vpu_platform_data *pdata; + + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->write_register) +return pdata->write_register (vpu_dev->dev, vpu_dev->vdb_register.vaddr, addr, data); + +writel (data, vpu_dev->vdb_register.vaddr + addr); +} + +unsigned int vdi_read_register (struct vpu_device *vpu_dev,unsigned int addr) +{ +struct vpu_platform_data *pdata; + + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->read_register) +return pdata->read_register (vpu_dev->dev, vpu_dev->vdb_register.vaddr, addr); + +return readl (vpu_dev->vdb_register.vaddr + addr); +} +EXPORT_SYMBOL (vdi_read_register); + +int vdi_buffer_sync (struct device *dev,struct vpu_buf *vb,int dir) +{ +struct vpu_device *vpu_dev =dev_get_drvdata (dev); +struct vpu_platform_data *pdata; + +if (!vb || !vb->vaddr) { +pr_err ("%s(): unable to clear unmapped buffer\n" , __func__); +return -EINVAL ; + } + + pdata =dev_get_platdata (dev); +if (pdata && pdata->buffer_sync) +return pdata->buffer_sync (dev, vpu_dev->vdb_register.vaddr, vb,0 , vb->size, dir); + +return 0 ; +} +EXPORT_SYMBOL (vdi_buffer_sync); + +int vdi_clear_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb) +{ +struct vpu_platform_data *pdata; + +if (!vb || !vb->vaddr) { +pr_err ("%s(): unable to clear unmapped buffer\n" , __func__); +return -EINVAL ; + } + +memset (vb->vaddr,0 , vb->size); + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->buffer_sync) + pdata->buffer_sync (vpu_dev->dev, vpu_dev->vdb_register.vaddr, vb,0 , vb->size,VPU_BUF_SYNC_TO_DEVICE ); + +return vb->size; +} + +static int swap_endian (struct vpu_device *vpu_dev,unsigned char *data,int len,int endian); + +int vdi_write_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb,size_t offset,unsigned char *data,int len,int endian) +{ +struct vpu_platform_data *pdata; + +if (!vb || !vb->vaddr) { +pr_err ("%s(): unable to write to unmapped buffer\n" , __func__); +return -EINVAL ; + } + +if ((offset + len) > vb->size) { +pr_err ("%s(): buffer too small\n" , __func__); +return -ENOSPC ; + } + +swap_endian (vpu_dev, data, len, endian); +memcpy (vb->vaddr + offset, data, len); + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->buffer_sync) + pdata->buffer_sync (vpu_dev->dev, vpu_dev->vdb_register.vaddr, vb, offset, len,VPU_BUF_SYNC_TO_DEVICE ); + +return len; +} + +int vdi_allocate_dma_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb) +{ +void *vaddr; +dma_addr_t daddr; +struct vpu_platform_data *pdata; + +if (!vb->size) { +dev_err (vpu_dev->dev,"%s(): requested size==0\n" , __func__); +return -EINVAL ; + } + + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->buffer_alloc) +return pdata->buffer_alloc (vpu_dev->dev, vb); + + vaddr =dma_alloc_coherent (vpu_dev->dev, vb->size, &daddr,GFP_KERNEL ); +if (!vaddr) +return -ENOMEM ; + vb->vaddr = vaddr; + vb->daddr = daddr; + +return 0 ; +} +EXPORT_SYMBOL (vdi_allocate_dma_memory); + +void vdi_free_dma_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb) +{ +struct vpu_platform_data *pdata; + +if (vb->size ==0 ) +return ; + + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->buffer_free) +return pdata->buffer_free (vpu_dev->dev, vb); + +if (!vb->vaddr) +dev_err (vpu_dev->dev,"%s(): requested free of unmapped buffer\n" , __func__); +else +dma_free_coherent (vpu_dev->dev, vb->size, vb->vaddr, vb->daddr); + +memset (vb,0 ,sizeof (*vb)); +} +EXPORT_SYMBOL (vdi_free_dma_memory); + +int vdi_convert_endian (struct vpu_device *vpu_dev,unsigned int endian) +{ +if (PRODUCT_CODE_W_SERIES (vpu_dev->product_code)) { +switch (endian) { +case VDI_LITTLE_ENDIAN : + endian =0x00 ; +break ; +case VDI_BIG_ENDIAN : + endian =0x0f ; +break ; +case VDI_32BIT_LITTLE_ENDIAN : + endian =0x04 ; +break ; +case VDI_32BIT_BIG_ENDIAN : + endian =0x03 ; +break ; + } + } + +return (endian &0x0f ); +} + +void byte_swap (unsigned char *data,int len) +{ +u8 temp; +s32 i; + +for (i =0 ; i < len; i +=2 ) { + temp = data[i]; + data[i] = data[i +1 ]; + data[i +1 ] = temp; + } +} + +void word_swap (unsigned char *data,int len) +{ +u16 temp; +u16 *ptr = (uint16_t *)data; +s32 i, size = len / (int )sizeof (uint16_t ); + +for (i =0 ; i < size; i +=2 ) { + temp = ptr[i]; + ptr[i] = ptr[i +1 ]; + ptr[i +1 ] = temp; + } +} + +void dword_swap (unsigned char *data,int len) +{ +u32 temp; +u32 *ptr = (uint32_t *)data; +s32 i, size = len / (int )sizeof (uint32_t ); + +for (i =0 ; i < size; i +=2 ) { + temp = ptr[i]; + ptr[i] = ptr[i +1 ]; + ptr[i +1 ] = temp; + } +} + +void lword_swap (unsigned char *data,int len) +{ +u64 temp; +u64 *ptr = (uint64_t *)data; +s32 i, size = len / (int )sizeof (uint64_t ); + +for (i =0 ; i < size; i +=2 ) { + temp = ptr[i]; + ptr[i] = ptr[i +1 ]; + ptr[i +1 ] = temp; + } +} + +static int swap_endian (struct vpu_device *vpu_dev,unsigned char *data,int len,int endian) +{ +int changes; +int sys_endian; +bool byte_change, word_change, dword_change, lword_change; + +if (PRODUCT_CODE_W_SERIES (vpu_dev->product_code)) { + sys_endian =VDI_128BIT_BUS_SYSTEM_ENDIAN ; + }else { +pr_err ("unknown product id : %08x\n" , vpu_dev->product_code); +return -1 ; + } + + endian =vdi_convert_endian (vpu_dev, endian); + sys_endian =vdi_convert_endian (vpu_dev, sys_endian); +if (endian == sys_endian) +return 0 ; + + changes = endian ^ sys_endian; + byte_change = changes &0x01 ; + word_change = ((changes &0x02 ) ==0x02 ); + dword_change = ((changes &0x04 ) ==0x04 ); + lword_change = ((changes &0x08 ) ==0x08 ); + +if (byte_change) +byte_swap (data, len); +if (word_change) +word_swap (data, len); +if (dword_change) +dword_swap (data, len); +if (lword_change) +lword_swap (data, len); + +return 1 ; +} +
drivers/staging/media/wave5/vdi/vdi.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 2/6] staging: media: wave5: Add the vdi layer
Hello,
Quoted 27 lines · Dafna Hirschfeld
Add the vdi directory of the wave5 codec driver. The
vdi.hheader defines common helper functions such as writing/reading register and handling endianness.Signed-off-by Robert Beckett <[email protected]>Signed-off-by Dafna Hirschfeld <[email protected]>--- drivers/staging/media/wave5/vdi/vdi.c | 325 ++++++++++++++++++++++++++ drivers/staging/media/wave5/vdi/vdi.h | 79 +++++++ 2 files changed, 404 insertions(+) create mode 100644 drivers/staging/media/wave5/vdi/vdi.c create mode 100644 drivers/staging/media/wave5/vdi/vdi.hdrivers/staging/media/wave5/vdi/vdi.c new file +7
-0@@ -0,0 +1,325 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - low level access functions +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#include <linux/bug.h>
drivers/staging/media/wave5/vdi/vdi.c line 17
Quoted 10 lines
drivers/staging/media/wave5/vdi/vdi.c new file +10
-0+#include "vdi.h" +#include "../v4l2/vpu.h" +#include "../vpuapi/wave/wave5_regdefine.h" +#include <linux/delay.h> +#define VDI_SRAM_BASE_ADDR 0x00 + +#define VDI_SYSTEM_ENDIAN VDI_LITTLE_ENDIAN +#define VDI_128BIT_BUS_SYSTEM_ENDIAN VDI_128BIT_LITTLE_ENDIAN + +static int vdi_allocate_common_memory (struct device *dev)
I would get rid of this entirely and just use the DMA API allocators.
Quoted 11 lines
drivers/staging/media/wave5/vdi/vdi.c new file +11
-0+{ +int ret; +struct vpu_device *vpu_dev =dev_get_drvdata (dev); + +if (!vpu_dev->common_mem.vaddr) { + vpu_dev->common_mem.size =SIZE_COMMON ; + ret =vdi_allocate_dma_memory (vpu_dev, &vpu_dev->common_mem); +if (ret) { +dev_err (dev,"unable to allocate common buffer\n" ); +return ret; + }
drivers/staging/media/wave5/vdi/vdi.c line 38
Quoted 10 lines
drivers/staging/media/wave5/vdi/vdi.c new file +10
-0+ } + +dev_dbg (dev,"common_mem: daddr=%pad size=%zu vaddr=0x%p\n" , + &vpu_dev->common_mem.daddr, vpu_dev->common_mem.size, + vpu_dev->common_mem.vaddr); + +return 0 ; +} + +int vdi_init (struct device *dev)
As mentioned on patch 3/6, please prefix functions, e.g. "wave5_vdi_init".
drivers/staging/media/wave5/vdi/vdi.c line 45
Quoted 7 lines
drivers/staging/media/wave5/vdi/vdi.c new file +7
-0+{ +struct vpu_platform_data *pdata =dev_get_platdata (dev); +struct vpu_device *vpu_dev =dev_get_drvdata (dev); +int i; + +if (vdi_allocate_common_memory (dev) <0 ) { +pr_err ("[VDI] fail to get vpu common buffer from driver\n" );
As mentioned on patch 3/6, please clean the pr_{} with dev_{}, if possible.
If you need to use pr_{} for some reason, you can use pr_fmt instead of having that "[VDI]". This stuff is even nicely documented Documentation/core-api/printk-basics.rst :-)
Quoted 17 lines
drivers/staging/media/wave5/vdi/vdi.c new file +17
-0+ goto ERR_VDI_INIT; + } + +if (pdata && pdata->reset) + pdata->reset (dev, vpu_dev->vdb_register.vaddr); + +if (pdata && pdata->pre_fw_init) { +if (pdata->pre_fw_init (dev, vpu_dev->vdb_register.vaddr)) + goto ERR_VDI_INIT; + } + +if (PRODUCT_CODE_W_SERIES (vpu_dev->product_code)) { +// if BIT processor is not running. +if (vdi_read_register (vpu_dev,W5_VCPU_CUR_PC ) ==0 ) { +for (i =0 ; i <64 ; i++) +vdi_write_register (vpu_dev, (i *4 ) +0x100 ,0x0 ); + }
drivers/staging/media/wave5/vdi/vdi.c line 72
Quoted 10 lines
drivers/staging/media/wave5/vdi/vdi.c new file +10
-0+ }else { +WARN_ONCE (1 ,"unsupported product code 0x%x\n" , vpu_dev->product_code); + } + +pr_info ("[VDI] success to init driver\n" ); + +return 0 ; + +ERR_VDI_INIT: +
Avoid caps.
drivers/staging/media/wave5/vdi/vdi.c line 77
Quoted 5 lines
drivers/staging/media/wave5/vdi/vdi.c new file +5
-0+vdi_release (dev); +return -1 ; +} +EXPORT_SYMBOL (vdi_init); +
Exported to whom?
Quoted 98 lines
drivers/staging/media/wave5/vdi/vdi.c new file +98
-0+int vdi_release (struct device *dev) +{ +struct vpu_device *vpu_dev =dev_get_drvdata (dev); + +memset (&vpu_dev->vdb_register,0x00 ,sizeof (vpu_dev->vdb_register)); +vdi_free_dma_memory (vpu_dev, &vpu_dev->common_mem); + +return 0 ; +} +EXPORT_SYMBOL (vdi_release); + +void vdi_write_register (struct vpu_device *vpu_dev,unsigned int addr,unsigned int data) +{ +struct vpu_platform_data *pdata; + + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->write_register) +return pdata->write_register (vpu_dev->dev, vpu_dev->vdb_register.vaddr, addr, data); + +writel (data, vpu_dev->vdb_register.vaddr + addr); +} + +unsigned int vdi_read_register (struct vpu_device *vpu_dev,unsigned int addr) +{ +struct vpu_platform_data *pdata; + + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->read_register) +return pdata->read_register (vpu_dev->dev, vpu_dev->vdb_register.vaddr, addr); + +return readl (vpu_dev->vdb_register.vaddr + addr); +} +EXPORT_SYMBOL (vdi_read_register); + +int vdi_buffer_sync (struct device *dev,struct vpu_buf *vb,int dir) +{ +struct vpu_device *vpu_dev =dev_get_drvdata (dev); +struct vpu_platform_data *pdata; + +if (!vb || !vb->vaddr) { +pr_err ("%s(): unable to clear unmapped buffer\n" , __func__); +return -EINVAL ; + } + + pdata =dev_get_platdata (dev); +if (pdata && pdata->buffer_sync) +return pdata->buffer_sync (dev, vpu_dev->vdb_register.vaddr, vb,0 , vb->size, dir); + +return 0 ; +} +EXPORT_SYMBOL (vdi_buffer_sync); + +int vdi_clear_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb) +{ +struct vpu_platform_data *pdata; + +if (!vb || !vb->vaddr) { +pr_err ("%s(): unable to clear unmapped buffer\n" , __func__); +return -EINVAL ; + } + +memset (vb->vaddr,0 , vb->size); + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->buffer_sync) + pdata->buffer_sync (vpu_dev->dev, vpu_dev->vdb_register.vaddr, vb,0 , vb->size,VPU_BUF_SYNC_TO_DEVICE ); + +return vb->size; +} + +static int swap_endian (struct vpu_device *vpu_dev,unsigned char *data,int len,int endian); + +int vdi_write_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb,size_t offset,unsigned char *data,int len,int endian) +{ +struct vpu_platform_data *pdata; + +if (!vb || !vb->vaddr) { +pr_err ("%s(): unable to write to unmapped buffer\n" , __func__); +return -EINVAL ; + } + +if ((offset + len) > vb->size) { +pr_err ("%s(): buffer too small\n" , __func__); +return -ENOSPC ; + } + +swap_endian (vpu_dev, data, len, endian); +memcpy (vb->vaddr + offset, data, len); + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->buffer_sync) + pdata->buffer_sync (vpu_dev->dev, vpu_dev->vdb_register.vaddr, vb, offset, len,VPU_BUF_SYNC_TO_DEVICE ); + +return len; +} + +int vdi_allocate_dma_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb) +{ +void *vaddr; +dma_addr_t daddr;
drivers/staging/media/wave5/vdi/vdi.c line 185
Quoted 10 lines
drivers/staging/media/wave5/vdi/vdi.c new file +10
-0+struct vpu_platform_data *pdata; + +if (!vb->size) { +dev_err (vpu_dev->dev,"%s(): requested size==0\n" , __func__); +return -EINVAL ; + } + + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->buffer_alloc) +return pdata->buffer_alloc (vpu_dev->dev, vb);
I don't see buffer_alloc implemented, but like I said, better to just ditch this ad-hoc allocator and do follow kernel-style, like all drivers.
Quoted 56 lines
drivers/staging/media/wave5/vdi/vdi.c new file +56
-0+ + vaddr =dma_alloc_coherent (vpu_dev->dev, vb->size, &daddr,GFP_KERNEL ); +if (!vaddr) +return -ENOMEM ; + vb->vaddr = vaddr; + vb->daddr = daddr; + +return 0 ; +} +EXPORT_SYMBOL (vdi_allocate_dma_memory); + +void vdi_free_dma_memory (struct vpu_device *vpu_dev,struct vpu_buf *vb) +{ +struct vpu_platform_data *pdata; + +if (vb->size ==0 ) +return ; + + pdata =dev_get_platdata (vpu_dev->dev); +if (pdata && pdata->buffer_free) +return pdata->buffer_free (vpu_dev->dev, vb); + +if (!vb->vaddr) +dev_err (vpu_dev->dev,"%s(): requested free of unmapped buffer\n" , __func__); +else +dma_free_coherent (vpu_dev->dev, vb->size, vb->vaddr, vb->daddr); + +memset (vb,0 ,sizeof (*vb)); +} +EXPORT_SYMBOL (vdi_free_dma_memory); + +int vdi_convert_endian (struct vpu_device *vpu_dev,unsigned int endian) +{ +if (PRODUCT_CODE_W_SERIES (vpu_dev->product_code)) { +switch (endian) { +case VDI_LITTLE_ENDIAN : + endian =0x00 ; +break ; +case VDI_BIG_ENDIAN : + endian =0x0f ; +break ; +case VDI_32BIT_LITTLE_ENDIAN : + endian =0x04 ; +break ; +case VDI_32BIT_BIG_ENDIAN : + endian =0x03 ; +break ; + } + } + +return (endian &0x0f ); +} + +void byte_swap (unsigned char *data,int len) +{ +u8 temp;
drivers/staging/media/wave5/vdi/vdi.c line 251
Quoted 10 lines
drivers/staging/media/wave5/vdi/vdi.c new file +10
-0+s32 i; + +for (i =0 ; i < len; i +=2 ) { + temp = data[i]; + data[i] = data[i +1 ]; + data[i +1 ] = temp; + } +} + +void word_swap (unsigned char *data,int len)
Perhaps there's some library function for all these?
Quoted 160 lines
drivers/staging/media/wave5/vdi/vdi.c new file +74
-0+{ +u16 temp; +u16 *ptr = (uint16_t *)data; +s32 i, size = len / (int )sizeof (uint16_t ); + +for (i =0 ; i < size; i +=2 ) { + temp = ptr[i]; + ptr[i] = ptr[i +1 ]; + ptr[i +1 ] = temp; + } +} + +void dword_swap (unsigned char *data,int len) +{ +u32 temp; +u32 *ptr = (uint32_t *)data; +s32 i, size = len / (int )sizeof (uint32_t ); + +for (i =0 ; i < size; i +=2 ) { + temp = ptr[i]; + ptr[i] = ptr[i +1 ]; + ptr[i +1 ] = temp; + } +} + +void lword_swap (unsigned char *data,int len) +{ +u64 temp; +u64 *ptr = (uint64_t *)data; +s32 i, size = len / (int )sizeof (uint64_t ); + +for (i =0 ; i < size; i +=2 ) { + temp = ptr[i]; + ptr[i] = ptr[i +1 ]; + ptr[i +1 ] = temp; + } +} + +static int swap_endian (struct vpu_device *vpu_dev,unsigned char *data,int len,int endian) +{ +int changes; +int sys_endian; +bool byte_change, word_change, dword_change, lword_change; + +if (PRODUCT_CODE_W_SERIES (vpu_dev->product_code)) { + sys_endian =VDI_128BIT_BUS_SYSTEM_ENDIAN ; + }else { +pr_err ("unknown product id : %08x\n" , vpu_dev->product_code); +return -1 ; + } + + endian =vdi_convert_endian (vpu_dev, endian); + sys_endian =vdi_convert_endian (vpu_dev, sys_endian); +if (endian == sys_endian) +return 0 ; + + changes = endian ^ sys_endian; + byte_change = changes &0x01 ; + word_change = ((changes &0x02 ) ==0x02 ); + dword_change = ((changes &0x04 ) ==0x04 ); + lword_change = ((changes &0x08 ) ==0x08 ); + +if (byte_change) +byte_swap (data, len); +if (word_change) +word_swap (data, len); +if (dword_change) +dword_swap (data, len); +if (lword_change) +lword_swap (data, len); + +return 1 ; +} +drivers/staging/media/wave5/vdi/vdi.h new file +79
-1@@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* +* Wave5 series multi-standard codec IP - low level access functions +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ + +#ifndef _VDI_H_ +#define _VDI_H_ + +#include "../vpuapi/vpuconfig.h" +#include <linux/string.h> +#include <linux/slab.h> +#include <linux/device.h> + +/************************************************************************/ +/* COMMON REGISTERS */ +/************************************************************************/ +#define VPU_PRODUCT_CODE_REGISTER 0x1044 + +/* system register write */ +#define vpu_write_reg (VPU_INST ,ADDR ,DATA ) vdi_write_register(VPU_INST, ADDR, DATA) +// system register read +#define vpu_read_reg (CORE ,ADDR ) vdi_read_register(CORE, ADDR) +// system memory write +#define vpu_write_mem (CORE ,VB ,OFFSET ,DATA ,LEN ,ENDIAN ) \ + vdi_write_memory(CORE, VB, OFFSET, DATA, LEN, ENDIAN) + +struct vpu_buf { +size_t size; +dma_addr_t daddr; +void __iomem *vaddr; +}; + +enum endian_mode { +VDI_LITTLE_ENDIAN =0 ,/* 64bit LE */ +VDI_BIG_ENDIAN ,/* 64bit BE */ +VDI_32BIT_LITTLE_ENDIAN , +VDI_32BIT_BIG_ENDIAN , +/* WAVE PRODUCTS */ +VDI_128BIT_LITTLE_ENDIAN =16 , +VDI_128BIT_LE_BYTE_SWAP , +VDI_128BIT_LE_WORD_SWAP , +VDI_128BIT_LE_WORD_BYTE_SWAP , +VDI_128BIT_LE_DWORD_SWAP , +VDI_128BIT_LE_DWORD_BYTE_SWAP , +VDI_128BIT_LE_DWORD_WORD_SWAP , +VDI_128BIT_LE_DWORD_WORD_BYTE_SWAP , +VDI_128BIT_BE_DWORD_WORD_BYTE_SWAP , +VDI_128BIT_BE_DWORD_WORD_SWAP , +VDI_128BIT_BE_DWORD_BYTE_SWAP , +VDI_128BIT_BE_DWORD_SWAP , +VDI_128BIT_BE_WORD_BYTE_SWAP , +VDI_128BIT_BE_WORD_SWAP , +VDI_128BIT_BE_BYTE_SWAP , +VDI_128BIT_BIG_ENDIAN =31 , +VDI_ENDIAN_MAX +}; + +#define VDI_128BIT_ENDIAN_MASK 0xf + +int vdi_init (struct device *dev); +int vdi_release (struct device *dev);//this function may be called only at system off. + +/** +* @brief make clock stable before changing clock frequency +* @detail before inoking vdi_set_clock_freg caller MUST invoke vdi_ready_change_clock +* function. +* after changing clock frequency caller also invoke vdi_done_change_clock() function. +* @return 0 failure +* 1 success +*/ +int vdi_ready_change_clock (unsigned long core_idx); +int vdi_set_change_clock (unsigned long core_idx,unsigned long clock_mask); +int vdi_done_change_clock (unsigned long core_idx); +int vdi_buffer_sync (struct device *dev,struct vpu_buf *vb,int dir); + +#endif //#ifndef _VDI_H_ + --
Quoted 2 lines
2.17.1
Regards,
Ezequiel
PATCH 3/6 staging: media: wave5: Add the v4l2 layer
In reply to Dafna HirschfeldAdd the decoder and encoder implementing the v4l2
API. This patch also adds the Makefile and the VIDEO_WAVE_VPU config
--- drivers/staging/media/Kconfig | 2 + drivers/staging/media/Makefile | 1 + drivers/staging/media/wave5/Kconfig | 10 + drivers/staging/media/wave5/Makefile | 10 + drivers/staging/media/wave5/v4l2/vpu.c | 386 +++++ drivers/staging/media/wave5/v4l2/vpu.h | 76 + drivers/staging/media/wave5/v4l2/vpu_dec.c | 1393 +++++++++++++++++ drivers/staging/media/wave5/v4l2/vpu_dec.h | 20 + drivers/staging/media/wave5/v4l2/vpu_enc.c | 1580 ++++++++++++++++++++ drivers/staging/media/wave5/v4l2/vpu_enc.h | 18 + 10 files changed, 3496 insertions(+) create mode 100644 drivers/staging/media/wave5/Kconfig create mode 100644 drivers/staging/media/wave5/Makefile create mode 100644 drivers/staging/media/wave5/v4l2/vpu.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu.h create mode 100644 drivers/staging/media/wave5/v4l2/vpu_dec.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu_dec.h create mode 100644 drivers/staging/media/wave5/v4l2/vpu_enc.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu_enc.h
drivers/staging/media/Kconfig +2 -0
@@ -44,4 +44,6 @@ source "drivers/staging/media/ipu3/Kconfig" source "drivers/staging/media/av7110/Kconfig" +source "drivers/staging/media/wave5/Kconfig" + endif
drivers/staging/media/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_VIDEO_HANTRO) += hantro/ obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3/ obj-$(CONFIG_VIDEO_ZORAN) += zoran/ obj-$(CONFIG_DVB_AV7110) += av7110/ +obj-$(CONFIG_VIDEO_WAVE_VPU) += wave5/
drivers/staging/media/wave5/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +config VIDEO_WAVE_VPU + tristate "Chips&Media Wave Codec Driver" + depends on VIDEO_DEV && VIDEO_V4L2 && OF + select VIDEOBUF2_DMA_CONTIG + select VIDEOBUF2_VMALLOC + select V4L2_MEM2MEM_DEV + select GENERIC_ALLOCATOR + help + Chips&Media codec driver
drivers/staging/media/wave5/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_VIDEO_WAVE_VPU) += wave5.o +wave5-objs += vpuapi/wave/wave5.o \ + vpuapi/vpuapi.o \ + vdi/vdi.o \ + v4l2/vpu_dec.o \ + v4l2/vpu.o \ + v4l2/vpu_enc.o +
drivers/staging/media/wave5/v4l2/vpu.c new file +386 -0
386 lines not on this page · raw message
drivers/staging/media/wave5/v4l2/vpu.h new file +76 -0
76 lines not on this page · raw message
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +1393 -0
1,393 lines not on this page · raw message
drivers/staging/media/wave5/v4l2/vpu_dec.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* +* Wave5 series multi-standard codec IP - decoder interface +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#ifndef __VPU_DEC_DRV_H__ +#define __VPU_DEC_DRV_H__ + +#include "vpu.h" + +#define VPU_DEC_DEV_NAME "C&M VPU decoder" +#define VPU_DEC_DRV_NAME "vpu-dec" + +#define V4L2_CID_VPU_THUMBNAIL_MODE (V4L2_CID_USER_BASE + 0x1001) + +int vpu_dec_register_device (struct vpu_device *dev); +void vpu_dec_unregister_device (struct vpu_device *dev); +#endif +
drivers/staging/media/wave5/v4l2/vpu_enc.c new file +1580 -0
1,095 lines not on this page · raw message
drivers/staging/media/wave5/v4l2/vpu_enc.h new file +18 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH 3/6] staging: media: wave5: Add the v4l2 layer
Hello Dafna, Nas and Robert:
I am quite happy to see a Chips and Media driver.
However, given it was announced that BeagleV™-Starlight prototype is not going to production [1], I'm curious about the plan for the driver. Is there an expectation to support silicon in the medium term (2021/2022)?
For instance, are you aware of any an effort to fix the cache coherency issues on the Starlight SoC?
In general, the driver is a good start, but it looks like it needs a big broom and a ton of cleanup work. See below for some comments, but keep in mind I may have missed more things.
[1] https://beaglev.org/blog/2021-07-30-the-future-of-beaglev-community
Quoted 53 lines · Dafna Hirschfeld
Add the decoder and encoder implementing the v4l2
API. This patch also adds theMakefileand theVIDEO_WAVE_VPUconfigSigned-off-by Robert Beckett <[email protected]>Signed-off-by Dafna Hirschfeld <[email protected]>--- drivers/staging/media/Kconfig | 2 + drivers/staging/media/Makefile | 1 + drivers/staging/media/wave5/Kconfig | 10 + drivers/staging/media/wave5/Makefile | 10 + drivers/staging/media/wave5/v4l2/vpu.c | 386 +++++ drivers/staging/media/wave5/v4l2/vpu.h | 76 + drivers/staging/media/wave5/v4l2/vpu_dec.c | 1393 +++++++++++++++++ drivers/staging/media/wave5/v4l2/vpu_dec.h | 20 + drivers/staging/media/wave5/v4l2/vpu_enc.c | 1580 ++++++++++++++++++++ drivers/staging/media/wave5/v4l2/vpu_enc.h | 18 + 10 files changed, 3496 insertions(+) create mode 100644 drivers/staging/media/wave5/Kconfig create mode 100644 drivers/staging/media/wave5/Makefile create mode 100644 drivers/staging/media/wave5/v4l2/vpu.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu.h create mode 100644 drivers/staging/media/wave5/v4l2/vpu_dec.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu_dec.h create mode 100644 drivers/staging/media/wave5/v4l2/vpu_enc.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu_enc.hdrivers/staging/media/Kconfig +2
-0@@ -44,4 +44,6 @@ source "drivers/staging/media/ipu3/Kconfig" source "drivers/staging/media/av7110/Kconfig" +source "drivers/staging/media/wave5/Kconfig" + endifdrivers/staging/media/Makefile +1
-0@@ -11,3 +11,4 @@ obj-$(CONFIG_VIDEO_HANTRO) += hantro/ obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3/ obj-$(CONFIG_VIDEO_ZORAN) += zoran/ obj-$(CONFIG_DVB_AV7110) += av7110/ +obj-$(CONFIG_VIDEO_WAVE_VPU) += wave5/drivers/staging/media/wave5/Kconfig new file +0
-0
drivers/staging/media/wave5/Kconfig line 4
Quoted 4 lines
drivers/staging/media/wave5/Kconfig new file +4
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +config VIDEO_WAVE_VPU + tristate "Chips&Media Wave Codec Driver" + depends on VIDEO_DEV && VIDEO_V4L2 && OF
The driver has some ifdef CONFIG_OF. Either drop this or drop the ifdefs.
drivers/staging/media/wave5/Kconfig line 8
Quoted 4 lines
drivers/staging/media/wave5/Kconfig new file +4
-0+ select VIDEOBUF2_DMA_CONTIG + select VIDEOBUF2_VMALLOC + select V4L2_MEM2MEM_DEV + select GENERIC_ALLOCATOR
I can't see why this is GENERIC_ALLOCATOR is here. Where is the API used?
Quoted 8 lines
drivers/staging/media/wave5/Kconfig new file +2
-0+ help + Chips&Media codec driverdrivers/staging/media/wave5/Makefile new file +0
-0
drivers/staging/media/wave5/Makefile line 10
Quoted 10 lines
drivers/staging/media/wave5/Makefile new file +10
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_VIDEO_WAVE_VPU) += wave5.o +wave5-objs += vpuapi/wave/wave5.o \ + vpuapi/vpuapi.o \ + vdi/vdi.o \ + v4l2/vpu_dec.o \ + v4l2/vpu.o \ + v4l2/vpu_enc.o +
It seems like an overkill to have a directory hierarchy for just these few files. How about you collapse them under a single wave5 directory?
It will be easier to read and maintain.
Quoted 18 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +12
-0@@ -0,0 +1,386 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - platform driver +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/clk.h> +#include <linux/firmware.h> +#include <linux/interrupt.h>
drivers/staging/media/wave5/v4l2/vpu.c line 22
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+#include "vpu.h" +#include "vpu_dec.h" +#include "vpu_enc.h" +#include "../vpuapi/wave/wave5_regdefine.h" +#include "../vpuapi/vpuconfig.h" +#include "../vpuapi/wave/wave5.h" + +#define VPU_PLATFORM_DEVICE_NAME "vdec" +#define VPU_CLK_NAME "vcodec" +
IIUC, given there's only just one clock, it's better to avoid requiring a name. Maybe you can double check that with some device tree experts.
drivers/staging/media/wave5/v4l2/vpu.c line 27
Quoted 5 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +5
-0+/* if the platform driver knows this driver */ +/* the definition of VPU_REG_BASE_ADDR and VPU_REG_SIZE are not meaningful */ +#define VPU_REG_BASE_ADDR 0x75000000 +#define VPU_REG_SIZE 0x4000 +
REG_ macros unused.
drivers/staging/media/wave5/v4l2/vpu.c line 30
Quoted 3 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +3
-0+struct wave5_match_data { +bool decoder; +bool encoder;
Nitpick, maybe a bit mask for functions?
drivers/staging/media/wave5/v4l2/vpu.c line 42
Quoted 12 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +12
-0+const char *fw_name; +}; + +const struct wave5_match_data default_match_data = { + .decoder = true, + .encoder = true, + .fw_name ="chagall.bin" , +}; + +unsigned int vpu_debug =1 ; +module_param (vpu_debug, uint,0644 ); +
I would rename this to just "debug".
Quoted 38 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +38
-0+int vpu_wait_interrupt (struct vpu_instance *inst,unsigned int timeout) +{ +int ret; + + ret =wait_for_completion_timeout (&inst->dev->irq_done, +msecs_to_jiffies (timeout)); +if (!ret) +return -ETIMEDOUT ; + +reinit_completion (&inst->dev->irq_done); + +return 0 ; +} + +static irqreturn_t vpu_irq (int irq,void *dev_id) +{ +struct vpu_device *dev = (struct vpu_device *)dev_id; +unsigned int irq_status; + +if (vdi_read_register (dev,W5_VPU_VPU_INT_STS )) { + irq_status =vdi_read_register (dev,W5_VPU_VINT_REASON ); +vdi_write_register (dev,W5_VPU_VINT_REASON_CLR , irq_status); +vdi_write_register (dev,W5_VPU_VINT_CLEAR ,0x1 ); + +kfifo_in (&dev->irq_status, &irq_status,sizeof (int )); + +return IRQ_WAKE_THREAD ; + } + +return IRQ_HANDLED ; +} + +static irqreturn_t vpu_irq_thread (int irq,void *dev_id) +{ +struct vpu_device *dev = (struct vpu_device *)dev_id; +struct vpu_instance *inst; +unsigned int irq_status, val; +int ret;
drivers/staging/media/wave5/v4l2/vpu.c line 90
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+ +while (kfifo_len (&dev->irq_status)) { + inst =v4l2_m2m_get_curr_priv (dev->v4l2_m2m_dev); +if (inst) { + inst->ops->finish_process (inst); + }else { + ret =kfifo_out (&dev->irq_status, &irq_status,sizeof (int )); +if (!ret) +break ; +DPRINTK (dev,1 ,"irq_status: 0x%x\n" , irq_status);
If you explore other drivers you will see that it's preferred to use dprintk instead of DPRINTK. Or just use dev_dbg which is probably better?
Also, the driver only seems to use debug level "1", so you can drop the parameter.
Again, I believe dev_dbg may be more flexible and powerful.
Quoted 54 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +54
-0+ val =vdi_read_register (dev,W5_VPU_VINT_REASON_USR ); + val &= ~irq_status; +vdi_write_register (dev,W5_VPU_VINT_REASON_USR , val); +complete (&dev->irq_done); + } + } + +return IRQ_HANDLED ; +} + +static void vpu_device_run (void *priv) +{ +struct vpu_instance *inst = priv; + +DPRINTK (inst->dev,1 ,"inst type=%d state=%d\n" , + inst->type, inst->state); + + inst->ops->start_process (inst); +} + +static int vpu_job_ready (void *priv) +{ +struct vpu_instance *inst = priv; + +DPRINTK (inst->dev,1 ,"inst type=%d state=%d\n" , + inst->type, inst->state); + +if (inst->state ==VPU_INST_STATE_STOP ) +return 0 ; + +return 1 ; +} + +static void vpu_job_abort (void *priv) +{ +struct vpu_instance *inst = priv; + +DPRINTK (inst->dev,1 ,"inst type=%d state=%d\n" , + inst->type, inst->state); + + inst->ops->stop_process (inst); +} + +static const struct v4l2_m2m_ops vpu_m2m_ops = { + .device_run = vpu_device_run, + .job_ready = vpu_job_ready, + .job_abort = vpu_job_abort, +}; + +static int vpu_load_firmware (struct device *dev,const char *fw_name) +{ +const struct firmware *fw; +enum ret_code ret =RETCODE_SUCCESS ; +u32 version;
drivers/staging/media/wave5/v4l2/vpu.c line 154
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+u32 revision; +u32 product_id; + +if (request_firmware (&fw, fw_name, dev)) { +pr_err ("request_firmware fail\n" ); +return -1 ; + } + + ret =vpu_init_with_bitcode (dev, (unsigned short *)fw->data, fw->size /2 ); +if (ret !=RETCODE_SUCCESS ) {
Get rid of enum ret_code and instead use 0 or errno.
drivers/staging/media/wave5/v4l2/vpu.c line 156
Quoted 2 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +2
-0+pr_err ("vpu_init_with_bitcode fail\n" ); +return -1 ;
Have you noticed this -1 is returned to the caller of vpu_probe? Just propagate the errno (after getting rid of enum ret_code). Same may apply to the rest of the driver.
drivers/staging/media/wave5/v4l2/vpu.c line 168
Quoted 12 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +12
-0+ } +release_firmware (fw); + + ret =vpu_get_version_info (dev, &version, &revision, &product_id); +if (ret !=RETCODE_SUCCESS ) { +pr_err ("vpu_get_version_info fail\n" ); +return -1 ; + } + +pr_err ("enum product_id : %08x\n" , product_id); +pr_err ("fw_version : %08x(r%d)\n" , version, revision); +
Avoid pr_{} and instead go with dev_{} / v4l2_{}.
Same may apply to the rest of the driver.
Quoted 25 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +25
-0+return 0 ; +} + +static int vpu_probe (struct platform_device *pdev) +{ +int err =0 ; +struct vpu_device *dev; +struct resource *res =NULL ; +const struct wave5_match_data *match_data; + + match_data =device_get_match_data (&pdev->dev); +if (!match_data) + match_data = &default_match_data; + +/* physical addresses limited to 32 bits */ +dma_set_mask (&pdev->dev,DMA_BIT_MASK (32 )); +dma_set_coherent_mask (&pdev->dev,DMA_BIT_MASK (32 )); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"unable to get mem resource\n" ); +return -EINVAL ; + } + dev =devm_kzalloc (&pdev->dev,sizeof (*dev),GFP_KERNEL ); +if (!dev)
drivers/staging/media/wave5/v4l2/vpu.c line 203
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+return -ENOMEM ; + + dev->vdb_register.daddr = res->start; + dev->vdb_register.size =resource_size (res); + dev->vdb_register.vaddr =devm_ioremap (&pdev->dev, dev->vdb_register.daddr, dev->vdb_register.size); +ida_init (&dev->inst_ida); + +dev_dbg (&pdev->dev,"REGISTER BASE daddr=%pad vaddr=%p size=%zu\n" , + &dev->vdb_register.daddr, dev->vdb_register.vaddr, dev->vdb_register.size); +
This dev_dbg makes little sense.
Quoted 39 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +39
-0+mutex_init (&dev->dev_lock); +mutex_init (&dev->hw_lock); +init_completion (&dev->irq_done); +dev_set_drvdata (&pdev->dev, dev); + dev->dev = &pdev->dev; + dev->product_code =vdi_read_register (dev,VPU_PRODUCT_CODE_REGISTER ); + err =vdi_init (&pdev->dev); +if (err <0 ) { +dev_err (&pdev->dev,"failed to init vdi: %d\n" , err); +return err; + } + dev->product =wave_vpu_get_product_id (dev); + + err =v4l2_device_register (&pdev->dev, &dev->v4l2_dev); +if (err) { +dev_err (&pdev->dev,"v4l2_device_register fail: %d\n" , err); + goto err_v4l2_dev_reg; + } + + dev->v4l2_m2m_dev =v4l2_m2m_init (&vpu_m2m_ops); +if (IS_ERR (dev->v4l2_m2m_dev)) { +dev_err (&pdev->dev,"v4l2_m2m_init fail: %ld\n" ,PTR_ERR (dev->v4l2_m2m_dev)); + err =PTR_ERR (dev->v4l2_m2m_dev); + goto err_m2m_init; + } + +if (match_data->decoder) { + err =vpu_dec_register_device (dev); +if (err) { +dev_err (&pdev->dev,"vpu_dec_register_device fail: %d\n" , err); + goto err_dec_reg; + } + } +if (match_data->encoder) { + err =vpu_enc_register_device (dev); +if (err) { +dev_err (&pdev->dev,"vpu_enc_register_device fail: %d\n" , err); + goto err_enc_reg; + }
drivers/staging/media/wave5/v4l2/vpu.c line 252
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+ } + + dev->clk =devm_clk_get (&pdev->dev,VPU_CLK_NAME ); +if (IS_ERR (dev->clk)) { +dev_warn (&pdev->dev,"unable to get clock: %ld\n" ,PTR_ERR (dev->clk)); +/* continue wihtout clock, assume externally managed */ + dev->clk =NULL ; + } + + err =clk_prepare_enable (dev->clk);
Are you sure you actually need to enable the clock in probe()?
Quoted 77 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +77
-0+if (err) { +dev_err (&pdev->dev,"failed to enable clock: %d\n" , err); + goto err_clk_prep_en; + } + + res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!res) { +dev_err (&pdev->dev,"failed to get irq resource\n" ); + err = -ENXIO ; + goto err_get_irq; + } + dev->irq = res->start; + +if (kfifo_alloc (&dev->irq_status,16 *sizeof (int ),GFP_KERNEL )) { +dev_err (&pdev->dev,"failed to allocate fifo\n" ); + goto err_kfifo_alloc; + } + + err =devm_request_threaded_irq (&pdev->dev, dev->irq, vpu_irq, vpu_irq_thread,0 ,"vpu_irq" , dev); +if (err) { +dev_err (&pdev->dev,"fail to register interrupt handler: %d\n" , err); + goto err_request_irq; + } + + err =vpu_load_firmware (&pdev->dev, match_data->fw_name); +if (err) { +dev_err (&pdev->dev,"failed to vpu_load_firmware: %d\n" , err); + goto err_load_fw; + } + +return 0 ; + +err_load_fw: +err_request_irq: +kfifo_free (&dev->irq_status); +err_kfifo_alloc: +err_get_irq: +clk_disable_unprepare (dev->clk); +err_clk_prep_en: +if (match_data->encoder) +vpu_enc_unregister_device (dev); +err_enc_reg: +if (match_data->decoder) +vpu_dec_unregister_device (dev); +err_dec_reg: +v4l2_m2m_release (dev->v4l2_m2m_dev); +err_m2m_init: +v4l2_device_unregister (&dev->v4l2_dev); +err_v4l2_dev_reg: +vdi_release (&pdev->dev); + +return err; +} + +static int vpu_remove (struct platform_device *pdev) +{ +struct vpu_device *dev =dev_get_drvdata (&pdev->dev); + +clk_disable_unprepare (dev->clk); +vpu_enc_unregister_device (dev); +vpu_dec_unregister_device (dev); +v4l2_m2m_release (dev->v4l2_m2m_dev); +v4l2_device_unregister (&dev->v4l2_dev); +kfifo_free (&dev->irq_status); +vdi_release (&pdev->dev); + +return 0 ; +} + +#ifdef CONFIG_OF +const struct wave5_match_data wave511_data = { + .decoder = true, + .encoder = false, + .fw_name ="wave511_dec_fw.bin" , +}; + +const struct wave5_match_data wave521_data = {
drivers/staging/media/wave5/v4l2/vpu.c line 339
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+ .decoder = false, + .encoder = true, + .fw_name = "wave521_enc_fw.bin", +}; + +const struct wave5_match_data wave521c_data = { + .decoder = true, + .encoder = true, + .fw_name ="wave521c_codec_fw.bin" , +};
Can you move default_match_data here?
Quoted 18 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +18
-0+ +// TODO: move this file to wave5 layer and convert runtime paramer filling to +// predefined structure used as data here. +static const struct of_device_id wave5_dt_ids[] = { + { .compatible ="cnm,cm511-vpu" , .data = &wave511_data }, + { .compatible ="cnm,cm517-vpu" , .data = &default_match_data }, + { .compatible ="cnm,cm521-vpu" , .data = &wave521_data }, + { .compatible ="cnm,cm521c-vpu" , .data = &wave521c_data }, + { .compatible ="cnm,cm521c-dual-vpu" , .data = &wave521c_data }, + { .compatible ="cnm,cm521e1-vpu" , .data = &default_match_data }, + { .compatible ="cnm,cm537-vpu" , .data = &default_match_data }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, wave5_dt_ids); +#endif + +static struct platform_driver vpu_driver = { + .driver = {
drivers/staging/media/wave5/v4l2/vpu.c line 367
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+ .name = VPU_PLATFORM_DEVICE_NAME, + .of_match_table = of_match_ptr(wave5_dt_ids), + }, + .probe = vpu_probe, + .remove = vpu_remove, + //.suspend = vpu_suspend, + //.resume = vpu_resume, +}; + +static int __init vpu_init (void )
So through all these files, I'd like to see a wave5_ prefix for all the functions. This is important even for static functions.
I'm aware it may seem not strongly enforced, but you can imagine how hard it would be for any code navigation tool to work if every driver would have functions named as vpu_probe, vpu_init, set_default_format, just to name a few.
Quoted 5 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +5
-0+{ +int ret; + + ret =platform_driver_register (&vpu_driver); +
drivers/staging/media/wave5/v4l2/vpu.c line 382
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+return ret; +} + +static void __exit vpu_exit(void) +{ +platform_driver_unregister (&vpu_driver); +} + +MODULE_DESCRIPTION ("chips&media VPU V4L2 driver" ); +MODULE_LICENSE ("GPL" );
This file says GPL-2 or BSD-3-Clause in the header. Is it OK to have "GPL" here?
drivers/staging/media/wave5/v4l2/vpu.c line 385
Quoted 3 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +3
-0+ +module_init (vpu_init); +module_exit (vpu_exit);
Use module_platform_driver.
Quoted 118 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +1
-0+drivers/staging/media/wave5/v4l2/vpu.h new file +76
-0@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* +* Wave5 series multi-standard codec IP - basic types +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#ifndef __VPU_DRV_H__ +#define __VPU_DRV_H__ + +#include <media/v4l2-ctrls.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-event.h> +#include <media/v4l2-fh.h> +#include <media/videobuf2-v4l2.h> +#include <media/videobuf2-dma-contig.h> +#include <media/videobuf2-vmalloc.h> +#include "../vpuapi/vpuconfig.h" +#include "../vpuapi/vpuapi.h" + +#define DPRINTK(dev, level, fmt, args...) \ + v4l2_dbg(level, vpu_debug, &(dev)->v4l2_dev, "[%s]" fmt, __func__, ##args) + +#define VPU_BUF_SYNC_TO_DEVICE 0 +#define VPU_BUF_SYNC_FROM_DEVICE 1 +struct vpu_platform_data { +struct vb2_mem_ops *mem_ops; +int (*pre_fw_init)(struct device *dev,void __iomem *base); +uint32_t (*read_register)(struct device *dev,void __iomem *base,uint32_t reg); +void (*write_register)(struct device *dev,void __iomem *base,uint32_t reg,uint32_t data); +int (*buffer_sync)(struct device *dev,void __iomem *base,struct vpu_buf *vb,size_t offset,uint32_t len,int dir); +int (*buffer_alloc)(struct device *dev,struct vpu_buf *vb); +void (*buffer_free)(struct device *dev,struct vpu_buf *vb); +int (*reset)(struct device *dev,void __iomem *base); +uint32_t (*get_hwoption)(struct device *dev); +}; + +struct vpu_buffer { +struct v4l2_m2m_buffer v4l2_m2m_buf; +bool consumed; +}; + +enum vpu_format_type { +VPU_FMT_TYPE_CODEC =0 , +VPU_FMT_TYPE_RAW =1 +}; + +struct vpu_format { +unsigned int v4l2_pix_fmt; +unsigned int num_planes; +unsigned int max_width; +unsigned int min_width; +unsigned int max_height; +unsigned int min_height; +}; + +extern unsigned int vpu_debug; + +static inline struct vpu_instance *to_vpu_inst (struct v4l2_fh *vfh) +{ + return container_of(vfh, struct vpu_instance, v4l2_fh); +} + +static inline struct vpu_instance *ctrl_to_vpu_inst (struct v4l2_ctrl *vctrl) +{ + return container_of(vctrl->handler, struct vpu_instance, v4l2_ctrl_hdl); +} + +static inline struct vpu_buffer *to_vpu_buf (struct vb2_v4l2_buffer *vbuf) +{ + return container_of(vbuf, struct vpu_buffer, v4l2_m2m_buf.vb); +} + +int vpu_wait_interrupt (struct vpu_instance *inst,unsigned int timeout); + +#endif +drivers/staging/media/wave5/v4l2/vpu_dec.c new file +29
-0@@ -0,0 +1,1393 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - decoder interface +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#include "vpu_dec.h" + +static const struct vpu_format vpu_dec_fmt_list[2 ][6 ] = { + [VPU_FMT_TYPE_CODEC ] = { + { + .v4l2_pix_fmt =V4L2_PIX_FMT_HEVC , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_H264 , + .num_planes =1 , + .max_width =8192 , + .min_width =32 , + .max_height =8192 , + .min_height =32 , + }, + }, + [VPU_FMT_TYPE_RAW ] = { + {
drivers/staging/media/wave5/v4l2/vpu_dec.c line 39
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +10
-0+ .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420, + .num_planes = 1, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV12, + .num_planes = 1,
You shouldn't need num_planes here, you normally can get all that stuff using the v4l2_fill_pixfmt_ helpers.
Quoted 83 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +83
-0+ .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV21, + .num_planes = 1, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420M, + .num_planes = 3, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV12M, + .num_planes = 2, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, + .num_planes = 2, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + } +}; + +static enum wave_std to_vpu_codstd(unsigned int v4l2_pix_fmt) +{ + switch (v4l2_pix_fmt) { + case V4L2_PIX_FMT_H264: + return W_AVC_DEC; + case V4L2_PIX_FMT_HEVC: + return W_HEVC_DEC; + default: + return STD_UNKNOWN; + } +} + +static const struct vpu_format *find_vpu_format(unsigned int v4l2_pix_fmt, enum vpu_format_type type) +{ + unsigned int index; + + for (index = 0; index < ARRAY_SIZE(vpu_dec_fmt_list[type]); index++) { + if (vpu_dec_fmt_list[type][index].v4l2_pix_fmt == v4l2_pix_fmt) + return &vpu_dec_fmt_list[type][index]; + } + + return NULL; +} + +static const struct vpu_format *find_vpu_format_by_index(unsigned int index, enum vpu_format_type type) +{ + if (index >= ARRAY_SIZE(vpu_dec_fmt_list[type])) + return NULL; + + if (vpu_dec_fmt_list[type][index].v4l2_pix_fmt == 0) + return NULL; + + return &vpu_dec_fmt_list[type][index]; +} + +static void handle_bitstream_buffer(struct vpu_instance *inst) +{ + struct v4l2_m2m_buffer *v4l2_m2m_buf = NULL; + + unsigned long flags; + + spin_lock_irqsave(&inst->bitstream_lock, flags); +
drivers/staging/media/wave5/v4l2/vpu_dec.c line 132
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +10
-0+v4l2_m2m_for_each_src_buf (inst->v4l2_fh.m2m_ctx, v4l2_m2m_buf) { +enum ret_code ret_code =RETCODE_SUCCESS ; +struct vb2_v4l2_buffer *vbuf = &v4l2_m2m_buf->vb; +struct vpu_buffer *vpu_buf =to_vpu_buf (vbuf); +u32 src_size =vb2_get_plane_payload (&vbuf->vb2_buf,0 ); +void *src_buf =vb2_plane_vaddr (&vbuf->vb2_buf,0 ); +dma_addr_t bs_rd_ptr =0 ; +dma_addr_t bs_wr_ptr =0 ; +u32 bs_remain_size =0 ; +size_t offset;
Fix indentation.
Quoted 88 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +88
-0+ +if (vpu_buf->consumed) { +DPRINTK (inst->dev,1 ,"already consumed buffer\n" ); +continue ; + } + +vpu_dec_get_bitstream_buffer (inst, &bs_rd_ptr, &bs_wr_ptr, &bs_remain_size); + +if (bs_remain_size < src_size) { +DPRINTK (inst->dev,1 ,"fill next time : remained size < source size.\n" ); +continue ; + } + + offset = bs_wr_ptr - inst->bitstream_vbuf.daddr; +if (bs_wr_ptr + src_size > inst->bitstream_vbuf.daddr + inst->bitstream_vbuf.size) { +int temp_size; + + temp_size = inst->bitstream_vbuf.daddr + inst->bitstream_vbuf.size - bs_wr_ptr; +vdi_write_memory (inst->dev, &inst->bitstream_vbuf, offset, src_buf, + temp_size,VDI_128BIT_LITTLE_ENDIAN ); +vdi_write_memory (inst->dev, &inst->bitstream_vbuf,0 , + src_buf + temp_size, src_size - temp_size,VDI_128BIT_LITTLE_ENDIAN ); + }else { +vdi_write_memory (inst->dev, &inst->bitstream_vbuf, offset, src_buf, + src_size,VDI_128BIT_LITTLE_ENDIAN ); + } + + ret_code =vpu_dec_update_bitstream_buffer (inst, src_size); +if (ret_code !=RETCODE_SUCCESS ) { +DPRINTK (inst->dev,1 ,"failed to call vpu_dec_update_bitstream_buffer() : %d\n" , ret_code); +continue ; + } + + vpu_buf->consumed = TRUE; + +if (inst->state ==VPU_INST_STATE_WAIT_BUF ) + inst->state =VPU_INST_STATE_PIC_RUN ; + } + +spin_unlock_irqrestore (&inst->bitstream_lock, flags); +} + +static void handle_src_buffer (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *src_buf; + +unsigned long flags; + +spin_lock_irqsave (&inst->bitstream_lock, flags); + + src_buf =v4l2_m2m_next_src_buf (inst->v4l2_fh.m2m_ctx); +if (src_buf) { +struct vpu_buffer *vpu_buf =to_vpu_buf (src_buf); + +if (vpu_buf->consumed) { +u32 remain_num =0 ; + +DPRINTK (inst->dev,1 ,"already consumed buffer\n" ); + remain_num =v4l2_m2m_num_src_bufs_ready (inst->v4l2_fh.m2m_ctx); +DPRINTK (inst->dev,1 ,"remain buffer : %d\n" , remain_num); +if (remain_num >1 ) { + src_buf =v4l2_m2m_src_buf_remove (inst->v4l2_fh.m2m_ctx); + inst->timestamp = src_buf->vb2_buf.timestamp; +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_DONE ); + } + } + } +spin_unlock_irqrestore (&inst->bitstream_lock, flags); +} + +static void update_resolution_info (struct v4l2_pix_format_mplane *pix_mp,unsigned int width,unsigned int height) +{ +switch (pix_mp->pixelformat) { +case V4L2_PIX_FMT_YUV420 : +case V4L2_PIX_FMT_NV12 : +case V4L2_PIX_FMT_NV21 : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage = width * height *3 /2 ; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); +break ; +case V4L2_PIX_FMT_YUV420M : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage = width * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved));
drivers/staging/media/wave5/v4l2/vpu_dec.c line 230
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +10
-0+ pix_mp->plane_fmt[1 ].bytesperline =round_up (width,32 ) /2 ; + pix_mp->plane_fmt[1 ].sizeimage = width * height /4 ; +memset (&pix_mp->plane_fmt[1 ].reserved,0 ,sizeof (pix_mp->plane_fmt[1 ].reserved)); + pix_mp->plane_fmt[2 ].bytesperline =round_up (width,32 ) /2 ; + pix_mp->plane_fmt[2 ].sizeimage = width * height /4 ; +memset (&pix_mp->plane_fmt[2 ].reserved,0 ,sizeof (pix_mp->plane_fmt[2 ].reserved)); +break ; +case V4L2_PIX_FMT_NV12M : +case V4L2_PIX_FMT_NV21M : + pix_mp->width =round_up (width,32 );
Yet more indentation issues.
Quoted 22 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +22
-0+ pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage = width * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); + pix_mp->plane_fmt[1 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[1 ].sizeimage = width * height /2 ; +memset (&pix_mp->plane_fmt[1 ].reserved,0 ,sizeof (pix_mp->plane_fmt[1 ].reserved)); +break ; +default : + pix_mp->width = width; + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =0 ; + pix_mp->plane_fmt[0 ].sizeimage = width * height /2 ; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); +break ; + } +} + +static void vpu_dec_start_decode (struct vpu_instance *inst) +{ +struct dec_param pic_param; +struct queue_status_info q_status;
drivers/staging/media/wave5/v4l2/vpu_dec.c line 262
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +10
-0+u32 remain_cmd_q, max_cmd_q =0 ; + +memset (&pic_param,0 ,sizeof (struct dec_param )); + +vpu_dec_give_command (inst,DEC_GET_QUEUE_STATUS , &q_status); +DPRINTK (inst->dev,1 ,"min_src_buf_cnt : %d | default : %d | qcount : %d | report_q : %d\n" , + inst->min_src_frame_buf_count,COMMAND_QUEUE_DEPTH , q_status.instance_queue_count, + q_status.report_queue_count); + + max_cmd_q = (inst->min_src_frame_buf_count < COMMAND_QUEUE_DEPTH) ?
Indentation issues all over the place :-) Please fix.
Quoted 2,722 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +1131
-0+ inst->min_src_frame_buf_count : COMMAND_QUEUE_DEPTH; + remain_cmd_q = max_cmd_q - q_status.instance_queue_count; + +while (remain_cmd_q) { +enum ret_code ret_code; + + ret_code =vpu_dec_start_one_frame (inst, &pic_param); +if (ret_code !=RETCODE_SUCCESS ) { +if (ret_code !=RETCODE_QUEUEING_FAILURE ) { +struct vb2_v4l2_buffer *src_buf = +v4l2_m2m_src_buf_remove (inst->v4l2_fh.m2m_ctx); + + inst->state =VPU_INST_STATE_STOP ; +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); +break ; + } + }else { +DPRINTK (inst->dev,1 ,"vpu_dec_start_one_frame success %d\n" , ret_code); + } + + remain_cmd_q--; + } +} + +static void vpu_dec_stop_decode (struct vpu_instance *inst) +{ +u32 i; +unsigned long flags; + + inst->state =VPU_INST_STATE_STOP ; + +spin_lock_irqsave (&inst->bitstream_lock, flags); +vpu_dec_update_bitstream_buffer (inst,0 ); +spin_unlock_irqrestore (&inst->bitstream_lock, flags); + +for (i =0 ; i < inst->min_dst_frame_buf_count; i++) { +vpu_dec_clr_disp_flag (inst, i); +DPRINTK (inst->dev,1 ,"clear display flag : %d\n" , i); + } +} + +static void vpu_dec_finish_decode (struct vpu_instance *inst) +{ +struct dec_output_info dec_output_info; +enum ret_code ret_code; +int irq_status; + +if (kfifo_out (&inst->dev->irq_status, &irq_status,sizeof (int ))) +vpu_clear_interrupt_ex (inst, irq_status); + +if (irq_status & (1 <<INT_WAVE5_BSBUF_EMPTY )) { +DPRINTK (inst->dev,1 ,"bitstream EMPTY!!!!\n" ); + inst->state =VPU_INST_STATE_WAIT_BUF ; +handle_src_buffer (inst); +handle_bitstream_buffer (inst); + } + +if (irq_status & (1 <<INT_WAVE5_DEC_PIC )) { + ret_code =vpu_dec_get_output_info (inst, &dec_output_info); +if (ret_code !=RETCODE_SUCCESS ) { +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); + }else { +if (inst->state ==VPU_INST_STATE_STOP ) { +struct queue_status_info q_status; + +if (dec_output_info.index_frame_display >=0 ) +vpu_dec_clr_disp_flag (inst, dec_output_info.index_frame_display); + +vpu_dec_give_command (inst,DEC_GET_QUEUE_STATUS , &q_status); + +if (q_status.report_queue_count + q_status.instance_queue_count ==0 ) +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); + }else if (dec_output_info.index_frame_decoded ==DECODED_IDX_FLAG_NO_FB && + dec_output_info.index_frame_display ==DISPLAY_IDX_FLAG_NO_FB ) { +DPRINTK (inst->dev,1 ,"no more frame buffer\n" ); + inst->state =VPU_INST_STATE_WAIT_BUF ; + }else { +handle_src_buffer (inst); + +if (dec_output_info.index_frame_display >=0 ) { +struct vb2_v4l2_buffer *dst_buf = +v4l2_m2m_dst_buf_remove_by_idx (inst->v4l2_fh.m2m_ctx, + dec_output_info.index_frame_display); +int stride = dec_output_info.disp_frame.stride; +int height = dec_output_info.disp_pic_height; + +if (inst->dst_fmt.num_planes ==1 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , + (stride * height *3 /2 )); + }else if (inst->dst_fmt.num_planes ==2 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , + (stride * height)); +vb2_set_plane_payload (&dst_buf->vb2_buf,1 , + ((stride /2 ) * height)); + }else if (inst->dst_fmt.num_planes ==3 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , + (stride * height)); +vb2_set_plane_payload (&dst_buf->vb2_buf,1 , + ((stride /2 ) * (height /2 ))); +vb2_set_plane_payload (&dst_buf->vb2_buf,2 , + ((stride /2 ) * (height /2 ))); + } + + dst_buf->vb2_buf.timestamp = inst->timestamp; + dst_buf->field =V4L2_FIELD_NONE ; +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_DONE ); + }else if (dec_output_info.index_frame_display ==DISPLAY_IDX_FLAG_SEQ_END ) { +static const struct v4l2_event vpu_event_eos = { + .type =V4L2_EVENT_EOS + }; + +DPRINTK (inst->dev,1 ,"stream end\n" ); + inst->state =VPU_INST_STATE_STOP ; +v4l2_event_queue_fh (&inst->v4l2_fh, &vpu_event_eos); + } + +if (!kfifo_len (&inst->dev->irq_status)) +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, + inst->v4l2_fh.m2m_ctx); + } + } + } +} + +static int vpu_dec_querycap (struct file *file,void *fh,struct v4l2_capability *cap) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"\n" ); + +strscpy (cap->driver,VPU_DEC_DRV_NAME ,sizeof (cap->driver)); +strscpy (cap->card,VPU_DEC_DRV_NAME ,sizeof (cap->card)); +strscpy (cap->bus_info,"platform:" VPU_DEC_DRV_NAME ,sizeof (cap->bus_info)); + +return 0 ; +} + +static int vpu_dec_enum_framesizes (struct file *file,void *fh,struct v4l2_frmsizeenum *fsize) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"\n" ); + +if (fsize->index) +return -EINVAL ; + + vpu_fmt =find_vpu_format (fsize->pixel_format,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + vpu_fmt =find_vpu_format (fsize->pixel_format,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + } + + fsize->type =V4L2_FRMSIZE_TYPE_CONTINUOUS ; + fsize->stepwise.min_width = vpu_fmt->min_width; + fsize->stepwise.max_width = vpu_fmt->max_width; + fsize->stepwise.step_width =1 ; + fsize->stepwise.min_height = vpu_fmt->min_height; + fsize->stepwise.max_height = vpu_fmt->max_height; + fsize->stepwise.step_height =1 ; + +return 0 ; +} + +static int vpu_dec_enum_fmt_cap (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"index : %d\n" , f->index); + + vpu_fmt =find_vpu_format_by_index (f->index,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + +return 0 ; +} + +static int vpu_dec_try_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d colorspace %d field : %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.colorspace, f->fmt.pix_mp.field); + +if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) +return -EINVAL ; + + vpu_fmt =find_vpu_format (f->fmt.pix_mp.pixelformat,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) { + f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; + f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; +update_resolution_info (&f->fmt.pix_mp, inst->dst_fmt.width, inst->dst_fmt.height); + }else { + f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; + f->fmt.pix_mp.num_planes = vpu_fmt->num_planes; +update_resolution_info (&f->fmt.pix_mp,clamp (f->fmt.pix_mp.width, + vpu_fmt->min_width, vpu_fmt->max_width), +clamp (f->fmt.pix_mp.height, vpu_fmt->min_height, + vpu_fmt->max_height)); + } + + f->fmt.pix_mp.flags =0 ; + f->fmt.pix_mp.field =V4L2_FIELD_NONE ; + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; +memset (&f->fmt.pix_mp.reserved,0 ,sizeof (f->fmt.pix_mp.reserved)); + +return 0 ; +} + +static int vpu_dec_s_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i, ret; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d colorspace %d field %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.colorspace, f->fmt.pix_mp.field); + + ret =vpu_dec_try_fmt_cap (file, fh, f); +if (ret) +return ret; + + inst->dst_fmt.width = f->fmt.pix_mp.width; + inst->dst_fmt.height = f->fmt.pix_mp.height; + inst->dst_fmt.pixelformat = f->fmt.pix_mp.pixelformat; + inst->dst_fmt.field = f->fmt.pix_mp.field; + inst->dst_fmt.flags = f->fmt.pix_mp.flags; + inst->dst_fmt.num_planes = f->fmt.pix_mp.num_planes; +for (i =0 ; i < inst->dst_fmt.num_planes; i++) { + inst->dst_fmt.plane_fmt[i].bytesperline = f->fmt.pix_mp.plane_fmt[i].bytesperline; + inst->dst_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; + } + +return 0 ; +} + +static int vpu_dec_g_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i; + +DPRINTK (inst->dev,1 ,"\n" ); + + f->fmt.pix_mp.width = inst->dst_fmt.width; + f->fmt.pix_mp.height = inst->dst_fmt.height; + f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; + f->fmt.pix_mp.field = inst->dst_fmt.field; + f->fmt.pix_mp.flags = inst->dst_fmt.flags; + f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; +for (i =0 ; i < f->fmt.pix_mp.num_planes; i++) { + f->fmt.pix_mp.plane_fmt[i].bytesperline = inst->dst_fmt.plane_fmt[i].bytesperline; + f->fmt.pix_mp.plane_fmt[i].sizeimage = inst->dst_fmt.plane_fmt[i].sizeimage; + } + + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; + +return 0 ; +} + +static int vpu_dec_enum_fmt_out (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"index : %d\n" , f->index); + + vpu_fmt =find_vpu_format_by_index (f->index,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + +return 0 ; +} + +static int vpu_dec_try_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d colorspace %d field %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.colorspace, f->fmt.pix_mp.field); + +if (f->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) +return -EINVAL ; + + vpu_fmt =find_vpu_format (f->fmt.pix_mp.pixelformat,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; + f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; +update_resolution_info (&f->fmt.pix_mp, inst->src_fmt.width, inst->src_fmt.height); + }else { + f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; + f->fmt.pix_mp.num_planes = vpu_fmt->num_planes; +update_resolution_info (&f->fmt.pix_mp,clamp (f->fmt.pix_mp.width, + vpu_fmt->min_width, vpu_fmt->max_width), +clamp (f->fmt.pix_mp.height, vpu_fmt->min_height, + vpu_fmt->max_height)); + } + + f->fmt.pix_mp.flags =0 ; + f->fmt.pix_mp.field =V4L2_FIELD_NONE ; +memset (&f->fmt.pix_mp.reserved,0 ,sizeof (f->fmt.pix_mp.reserved)); + +return 0 ; +} + +static int vpu_dec_s_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i, ret; + +DPRINTK (inst->dev,1 ,"pixelformat %d width %d height %d num_planes %d field : %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + + ret =vpu_dec_try_fmt_out (file, fh, f); +if (ret) +return ret; + + inst->src_fmt.width = f->fmt.pix_mp.width; + inst->src_fmt.height = f->fmt.pix_mp.height; + inst->src_fmt.pixelformat = f->fmt.pix_mp.pixelformat; + inst->src_fmt.field = f->fmt.pix_mp.field; + inst->src_fmt.flags = f->fmt.pix_mp.flags; + inst->src_fmt.num_planes = f->fmt.pix_mp.num_planes; +for (i =0 ; i < inst->src_fmt.num_planes; i++) { + inst->src_fmt.plane_fmt[i].bytesperline = f->fmt.pix_mp.plane_fmt[i].bytesperline; + inst->src_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; + } + + inst->colorspace = f->fmt.pix_mp.colorspace; + inst->ycbcr_enc = f->fmt.pix_mp.ycbcr_enc; + inst->hsv_enc = f->fmt.pix_mp.hsv_enc; + inst->quantization = f->fmt.pix_mp.quantization; + inst->xfer_func = f->fmt.pix_mp.xfer_func; + +update_resolution_info (&inst->dst_fmt, f->fmt.pix_mp.width, f->fmt.pix_mp.height); + +return 0 ; +} + +static int vpu_dec_g_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i; + +DPRINTK (inst->dev,1 ,"\n" ); + + f->fmt.pix_mp.width = inst->src_fmt.width; + f->fmt.pix_mp.height = inst->src_fmt.height; + f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; + f->fmt.pix_mp.field = inst->src_fmt.field; + f->fmt.pix_mp.flags = inst->src_fmt.flags; + f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; +for (i =0 ; i < f->fmt.pix_mp.num_planes; i++) { + f->fmt.pix_mp.plane_fmt[i].bytesperline = inst->src_fmt.plane_fmt[i].bytesperline; + f->fmt.pix_mp.plane_fmt[i].sizeimage = inst->src_fmt.plane_fmt[i].sizeimage; + } + + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; + +return 0 ; +} + +static int vpu_dec_g_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | target : %d\n" , s->type, s->target); + +if (s->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE ) { +switch (s->target) { +case V4L2_SEL_TGT_COMPOSE_BOUNDS : +case V4L2_SEL_TGT_COMPOSE_PADDED : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->dst_fmt.width; + s->r.height = inst->dst_fmt.height; +break ; +case V4L2_SEL_TGT_COMPOSE : +case V4L2_SEL_TGT_COMPOSE_DEFAULT : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->src_fmt.width; + s->r.height = inst->src_fmt.height; +break ; +default : +return -EINVAL ; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_dec_s_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | target : %d\n" , s->type, s->target); + +if (s->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE ) { +switch (s->target) { +case V4L2_SEL_TGT_COMPOSE : +DPRINTK (inst->dev,1 ,"V4L2_SEL_TGT_COMPOSE width : %d | height : %d\n" , + s->r.width, s->r.height); + inst->dst_fmt.width = s->r.width; + inst->dst_fmt.height = s->r.height; +break ; +default : +return -EINVAL ; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_dec_try_decoder_cmd (struct file *file,void *fh,struct v4l2_decoder_cmd *dc) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"decoder command : %d\n" , dc->cmd); + +if (dc->cmd !=V4L2_DEC_CMD_STOP && dc->cmd !=V4L2_DEC_CMD_START ) +return -EINVAL ; + + dc->flags =0 ; + +if (dc->cmd ==V4L2_DEC_CMD_STOP ) { + dc->stop.pts =0 ; + }else if (dc->cmd ==V4L2_DEC_CMD_START ) { + dc->start.speed =0 ; + dc->start.format =V4L2_DEC_START_FMT_NONE ; + } + +return 0 ; +} + +static int vpu_dec_decoder_cmd (struct file *file,void *fh,struct v4l2_decoder_cmd *dc) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int ret; + +DPRINTK (inst->dev,1 ,"decoder command : %d\n" , dc->cmd); + + ret =vpu_dec_try_decoder_cmd (file, fh, dc); +if (ret <0 ) +return ret; + +if (!vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE )) || + !vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ))) +return 0 ; + +switch (dc->cmd) { +case V4L2_DEC_CMD_STOP : +vpu_dec_stop_decode (inst); +break ; +case V4L2_DEC_CMD_START : +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_dec_subscribe_event (struct v4l2_fh *fh,const struct v4l2_event_subscription *sub) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | id : %d | flags : %d\n" , sub->type, sub->id, sub->flags); + +switch (sub->type) { +case V4L2_EVENT_EOS : +return v4l2_event_subscribe (fh, sub,0 ,NULL ); +case V4L2_EVENT_SOURCE_CHANGE : +return v4l2_src_change_event_subscribe (fh, sub); +case V4L2_EVENT_CTRL : +return v4l2_ctrl_subscribe_event (fh, sub); +default : +return -EINVAL ; + } +} + +static const struct v4l2_ioctl_ops vpu_dec_ioctl_ops = { + .vidioc_querycap = vpu_dec_querycap, + .vidioc_enum_framesizes = vpu_dec_enum_framesizes, + + .vidioc_enum_fmt_vid_cap = vpu_dec_enum_fmt_cap, + .vidioc_s_fmt_vid_cap_mplane = vpu_dec_s_fmt_cap, + .vidioc_g_fmt_vid_cap_mplane = vpu_dec_g_fmt_cap, + .vidioc_try_fmt_vid_cap_mplane = vpu_dec_try_fmt_cap, + + .vidioc_enum_fmt_vid_out = vpu_dec_enum_fmt_out, + .vidioc_s_fmt_vid_out_mplane = vpu_dec_s_fmt_out, + .vidioc_g_fmt_vid_out_mplane = vpu_dec_g_fmt_out, + .vidioc_try_fmt_vid_out_mplane = vpu_dec_try_fmt_out, + + .vidioc_g_selection = vpu_dec_g_selection, + .vidioc_s_selection = vpu_dec_s_selection, + + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, + .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, + .vidioc_streamon = v4l2_m2m_ioctl_streamon, + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, + + .vidioc_try_decoder_cmd = vpu_dec_try_decoder_cmd, + .vidioc_decoder_cmd = vpu_dec_decoder_cmd, + + .vidioc_subscribe_event = vpu_dec_subscribe_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, +}; + +static int vpu_dec_g_volatile_ctrl (struct v4l2_ctrl *ctrl) +{ +struct vpu_instance *inst =ctrl_to_vpu_inst (ctrl); + +DPRINTK (inst->dev,1 ,"name : %s\n" , ctrl->name); + +switch (ctrl->id) { +case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE : +if (inst->state !=VPU_INST_STATE_NONE && inst->state !=VPU_INST_STATE_OPEN ) + ctrl->val = inst->min_dst_frame_buf_count; +break ; +default : +return -EINVAL ; + } + +DPRINTK (inst->dev,1 ,"value : %d\n" , ctrl->val); + +return 0 ; +} + +static int vpu_dec_s_ctrl (struct v4l2_ctrl *ctrl) +{ +struct vpu_instance *inst =ctrl_to_vpu_inst (ctrl); + +DPRINTK (inst->dev,1 ,"name : %s | value : %d\n" , ctrl->name, ctrl->val); + +switch (ctrl->id) { +case V4L2_CID_VPU_THUMBNAIL_MODE : + inst->thumbnail_mode = ctrl->val; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct v4l2_ctrl_ops vpu_dec_ctrl_ops = { + .g_volatile_ctrl = vpu_dec_g_volatile_ctrl, + .s_ctrl = vpu_dec_s_ctrl, +}; + +static const struct v4l2_ctrl_config vpu_thumbnail_mode = { + .ops = &vpu_dec_ctrl_ops, + .id =V4L2_CID_VPU_THUMBNAIL_MODE , + .name ="thumbnail mode" , + .type =V4L2_CTRL_TYPE_BOOLEAN , + .def =0 , + .min =0 , + .max =1 , + .step =1 , + .flags =V4L2_CTRL_FLAG_WRITE_ONLY , +}; + +static void set_default_dec_openparam (struct dec_open_param *open_param) +{ + open_param->bitstream_mode =BS_MODE_INTERRUPT ; + open_param->stream_endian =VPU_STREAM_ENDIAN ; + open_param->frame_endian =VPU_FRAME_ENDIAN ; + open_param->cbcr_interleave = FALSE; + open_param->nv21 = FALSE; +} + +static int vpu_dec_queue_setup (struct vb2_queue *q,unsigned int *num_buffers, +unsigned int *num_planes,unsigned int sizes[], +struct device *alloc_devs[]) +{ +struct vpu_instance *inst =vb2_get_drv_priv (q); +struct v4l2_pix_format_mplane inst_format = + (q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) ? inst->src_fmt : inst->dst_fmt; +unsigned int i; + +DPRINTK (inst->dev,1 ,"num_buffers : %d | num_planes : %d | type : %d\n" , *num_buffers, + *num_planes, q->type); + +if (*num_planes) { +if (inst_format.num_planes != *num_planes) +return -EINVAL ; + +for (i =0 ; i < *num_planes; i++) { +if (sizes[i] < inst_format.plane_fmt[i].sizeimage) +return -EINVAL ; + } + }else { + *num_planes = inst_format.num_planes; + +if (*num_planes ==1 ) { + sizes[0 ] = inst_format.width * inst_format.height *3 /2 ; +if (q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) + sizes[0 ] = inst_format.plane_fmt[0 ].sizeimage; +DPRINTK (inst->dev,1 ,"size[0] : %d\n" , sizes[0 ]); + }else if (*num_planes ==2 ) { + sizes[0 ] = inst_format.width * inst_format.height; + sizes[1 ] = inst_format.width * inst_format.height /2 ; +DPRINTK (inst->dev,1 ,"size[0] : %d | size[1] : %d\n" , sizes[0 ], sizes[1 ]); + }else if (*num_planes ==3 ) { + sizes[0 ] = inst_format.width * inst_format.height; + sizes[1 ] = inst_format.width * inst_format.height /4 ; + sizes[2 ] = inst_format.width * inst_format.height /4 ; +DPRINTK (inst->dev,1 ,"size[0] : %d | size[1] : %d | size[2] : %d\n" , + sizes[0 ], sizes[1 ], sizes[2 ]); + } + } + +if (inst->state ==VPU_INST_STATE_NONE && q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { +enum ret_code ret_code; +struct dec_open_param open_param; + +memset (&open_param,0 ,sizeof (struct dec_open_param )); +set_default_dec_openparam (&open_param); + + inst->bitstream_vbuf.size =ALIGN (inst->src_fmt.plane_fmt[0 ].sizeimage,1024 ) *4 ; +if (vdi_allocate_dma_memory (inst->dev, &inst->bitstream_vbuf) <0 ) +DPRINTK (inst->dev,1 ,"alloc bitstream fail: %zu\n" , inst->bitstream_vbuf.size); + + inst->std =to_vpu_codstd (inst->src_fmt.pixelformat); +if (inst->std ==STD_UNKNOWN ) { +dev_warn (inst->dev->dev,"unsupported pixelformat: %.4s\n" , + (char *)&inst->src_fmt.pixelformat); +return -EINVAL ; + } + open_param.bitstream_buffer = inst->bitstream_vbuf.daddr; + open_param.bitstream_buffer_size = inst->bitstream_vbuf.size; + + ret_code =vpu_dec_open_api (inst, &open_param); +if (ret_code !=RETCODE_SUCCESS ) { +DPRINTK (inst->dev,1 ,"failed to call vpu_dec_open_api() : %d\n" , ret_code); +return -EINVAL ; + } + + inst->state =VPU_INST_STATE_OPEN ; + +//vpu_dec_give_command(inst, ENABLE_LOGGING, 0); + +if (inst->thumbnail_mode) +vpu_dec_give_command (inst,ENABLE_DEC_THUMBNAIL_MODE ,0 ); + + inst->min_src_frame_buf_count = *num_buffers; + } + +if (inst->state !=VPU_INST_STATE_NONE && inst->state !=VPU_INST_STATE_OPEN && q->type == +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { + *num_buffers = inst->min_dst_frame_buf_count; + +if (inst->state ==VPU_INST_STATE_INIT_SEQ ) { +s32 non_linear_num = inst->min_dst_frame_buf_count; +s32 fb_stride, fb_height; +s32 luma_size, chroma_size; + +for (i =0 ; i < non_linear_num; i++) { + fb_stride = inst->dst_fmt.width; + fb_height =ALIGN (inst->dst_fmt.height,32 ); + luma_size = fb_stride * fb_height; + chroma_size =ALIGN (fb_stride /2 ,16 ) * fb_height; + + inst->frame_vbuf[i].size = luma_size + chroma_size; +if (vdi_allocate_dma_memory (inst->dev, &inst->frame_vbuf[i]) <0 ) +DPRINTK (inst->dev,1 ,"failed to alloc FBC buffer : %zu\n" , + inst->frame_vbuf[i].size); + + inst->frame_buf[i].buf_y = inst->frame_vbuf[i].daddr; + inst->frame_buf[i].buf_cb = inst->frame_vbuf[i].daddr + luma_size; + inst->frame_buf[i].buf_cr = (dma_addr_t)-1 ; + inst->frame_buf[i].size = inst->frame_vbuf[i].size; + inst->frame_buf[i].width = inst->src_fmt.width; + inst->frame_buf[i].stride = fb_stride; + inst->frame_buf[i].map_type =COMPRESSED_FRAME_MAP ; + inst->frame_buf[i].update_fb_info = TRUE; + } + } + } + +return 0 ; +} + +static int vpu_dec_buf_init (struct vb2_buffer *vb) +{ +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); + +DPRINTK (inst->dev,1 ,"type : %4d index %4d size[0] %4ld size[1] %4ld size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); +return 0 ; +} + +static int vpu_dec_buf_prepare (struct vb2_buffer *vb) +{ +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); + +DPRINTK (inst->dev,1 ,"type : %4d index %4d size[0] %4ld size[1] %4ld size[2] %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); + +return 0 ; +} + +static void vpu_dec_buf_queue (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vpu_buffer *vpu_buf =to_vpu_buf (vbuf); + +DPRINTK (inst->dev,1 ,"type %4d index %4d size[0] %4ld size[1] : %4ld | size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); + +v4l2_m2m_buf_queue (inst->v4l2_fh.m2m_ctx, vbuf); + +if (vb->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { + vpu_buf->consumed = FALSE; +handle_bitstream_buffer (inst); + vbuf->sequence = inst->queued_src_buf_num++; + } + +if (vb->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { +if (inst->state ==VPU_INST_STATE_INIT_SEQ ) { +dma_addr_t buf_addr_y =0 , buf_addr_cb =0 , buf_addr_cr =0 ; +s32 buf_size =0 ; +s32 non_linear_num = inst->min_dst_frame_buf_count; +s32 fb_stride = inst->dst_fmt.width; +s32 luma_size = fb_stride * inst->dst_fmt.height; +s32 chroma_size = (fb_stride /2 ) * (inst->dst_fmt.height /2 ); + +if (inst->dst_fmt.num_planes ==1 ) { + buf_size =vb2_plane_size (&vbuf->vb2_buf,0 ); + buf_addr_y =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,0 ); + buf_addr_cb = buf_addr_y + luma_size; + buf_addr_cr = buf_addr_cb + chroma_size; + }else if (inst->dst_fmt.num_planes ==2 ) { + buf_size =vb2_plane_size (&vbuf->vb2_buf,0 ) + +vb2_plane_size (&vbuf->vb2_buf,1 ); + buf_addr_y =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,0 ); + buf_addr_cb =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,1 ); + buf_addr_cr = buf_addr_cb + chroma_size; + }else if (inst->dst_fmt.num_planes ==3 ) { + buf_size =vb2_plane_size (&vbuf->vb2_buf,0 ) + +vb2_plane_size (&vbuf->vb2_buf,1 ) + +vb2_plane_size (&vbuf->vb2_buf,2 ); + buf_addr_y =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,0 ); + buf_addr_cb =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,1 ); + buf_addr_cr =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,2 ); + } + inst->frame_buf[vb->index + non_linear_num].buf_y = buf_addr_y; + inst->frame_buf[vb->index + non_linear_num].buf_cb = buf_addr_cb; + inst->frame_buf[vb->index + non_linear_num].buf_cr = buf_addr_cr; + inst->frame_buf[vb->index + non_linear_num].size = buf_size; + inst->frame_buf[vb->index + non_linear_num].width = inst->src_fmt.width; + inst->frame_buf[vb->index + non_linear_num].stride = fb_stride; + inst->frame_buf[vb->index + non_linear_num].map_type =LINEAR_FRAME_MAP ; + inst->frame_buf[vb->index + non_linear_num].update_fb_info = TRUE; + } + +if (inst->state ==VPU_INST_STATE_PIC_RUN || inst->state ==VPU_INST_STATE_STOP || + inst->state ==VPU_INST_STATE_WAIT_BUF ) { +vpu_dec_clr_disp_flag (inst, vb->index); +if (inst->state ==VPU_INST_STATE_WAIT_BUF ) + inst->state =VPU_INST_STATE_PIC_RUN ; + } + vbuf->sequence = inst->queued_dst_buf_num++; + } +} + +static void vpu_dec_buf_finish (struct vb2_buffer *vb) +{ +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); + +DPRINTK (inst->dev,1 ,"type %4d index : %4d size[0] %4ld size[1] %4ld | size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); +} + +static void vpu_dec_buf_cleanup (struct vb2_buffer *vb) +{ +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); + +DPRINTK (inst->dev,1 ,"type %4d index %4d size[0] %4ld size[1] : %4ld | size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); +} + +static int vpu_dec_start_streaming (struct vb2_queue *q,unsigned int count) +{ +struct vpu_instance *inst =vb2_get_drv_priv (q); + +DPRINTK (inst->dev,1 ,"type : %d\n" , q->type); + +if (inst->state ==VPU_INST_STATE_OPEN ) { +struct dec_initial_info initial_info; +enum ret_code ret_code; + + ret_code =vpu_dec_issue_seq_init (inst); +if (ret_code !=RETCODE_SUCCESS ) +DPRINTK (inst->dev,1 ,"failed vpu_dec_issue_seq_init() : %d\n" , ret_code); + +if (vpu_wait_interrupt (inst,VPU_DEC_TIMEOUT ) <0 ) +DPRINTK (inst->dev,1 ,"failed to call vpu_wait_interrupt()\n" ); + + ret_code =vpu_dec_complete_seq_init (inst, &initial_info); +if (ret_code !=RETCODE_SUCCESS ) { +DPRINTK (inst->dev,1 ,"vpu_dec_complete_seq_init: %d, reason : %d\n" , + ret_code, initial_info.seq_init_err_reason); + }else { +static const struct v4l2_event vpu_event_src_ch = { + .type =V4L2_EVENT_SOURCE_CHANGE , + .u.src_change.changes =V4L2_EVENT_SRC_CH_RESOLUTION , + }; + +DPRINTK (inst->dev,1 ,"width %d height %d profile %d | minbuffer : %d\n" , + initial_info.pic_width, initial_info.pic_height, + initial_info.profile, initial_info.min_frame_buffer_count); + + inst->state =VPU_INST_STATE_INIT_SEQ ; + inst->min_dst_frame_buf_count = initial_info.min_frame_buffer_count +1 ; + +if (initial_info.pic_width != inst->src_fmt.width || + initial_info.pic_height != inst->src_fmt.height) { +update_resolution_info (&inst->src_fmt, initial_info.pic_width, + initial_info.pic_height); +update_resolution_info (&inst->dst_fmt, initial_info.pic_width, + initial_info.pic_height); + } + +v4l2_event_queue_fh (&inst->v4l2_fh, &vpu_event_src_ch); + } + } + +if (inst->state ==VPU_INST_STATE_INIT_SEQ && q->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { +enum ret_code ret_code; +s32 non_linear_num = inst->min_dst_frame_buf_count; +s32 linear_num = inst->min_dst_frame_buf_count; +s32 fb_stride = inst->dst_fmt.width; + +DPRINTK (inst->dev,1 ,"fb_stride %d | inst->dst_fmt.height %d\n" , fb_stride, inst->dst_fmt.height); + ret_code =vpu_dec_register_frame_buffer_ex (inst, non_linear_num, linear_num, + fb_stride, inst->dst_fmt.height,COMPRESSED_FRAME_MAP ); +if (ret_code !=RETCODE_SUCCESS ) +DPRINTK (inst->dev,1 ,"fail vpu_dec_register_frame_buffer_ex %d" , ret_code); + + inst->state =VPU_INST_STATE_PIC_RUN ; + } + +return 0 ; +} + +static void vpu_dec_stop_streaming (struct vb2_queue *q) +{ +struct vpu_instance *inst =vb2_get_drv_priv (q); +struct vb2_v4l2_buffer *buf; + +DPRINTK (inst->dev,1 ,"type : %d\n" , q->type); + +if (vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE )) && +vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ))) + inst->state =VPU_INST_STATE_STOP ; + +if (q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { +while ((buf =v4l2_m2m_src_buf_remove (inst->v4l2_fh.m2m_ctx))) { +DPRINTK (inst->dev,1 ,"buf type : %4d | index : %4d\n" , buf->vb2_buf.type, + buf->vb2_buf.index); +v4l2_m2m_buf_done (buf,VB2_BUF_STATE_ERROR ); + } + }else { +while ((buf =v4l2_m2m_dst_buf_remove (inst->v4l2_fh.m2m_ctx))) { +u32 plane =0 ; + +DPRINTK (inst->dev,1 ,"buf type : %4d | index : %4d\n" , buf->vb2_buf.type, + buf->vb2_buf.index); + +for (plane =0 ; plane < inst->dst_fmt.num_planes; plane++) +vb2_set_plane_payload (&buf->vb2_buf, plane,0 ); + +v4l2_m2m_buf_done (buf,VB2_BUF_STATE_ERROR ); + } + } +} + +static const struct vb2_ops vpu_dec_vb2_ops = { + .queue_setup = vpu_dec_queue_setup, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .buf_init = vpu_dec_buf_init, + .buf_prepare = vpu_dec_buf_prepare, + .buf_queue = vpu_dec_buf_queue, + .buf_finish = vpu_dec_buf_finish, + .buf_cleanup = vpu_dec_buf_cleanup, + .start_streaming = vpu_dec_start_streaming, + .stop_streaming = vpu_dec_stop_streaming, +}; + +static void set_default_format (struct v4l2_pix_format_mplane *src_fmt, +struct v4l2_pix_format_mplane *dst_fmt) +{ + src_fmt->pixelformat = vpu_dec_fmt_list[VPU_FMT_TYPE_CODEC ][0 ].v4l2_pix_fmt; + src_fmt->field =V4L2_FIELD_NONE ; + src_fmt->flags =0 ; + src_fmt->num_planes = vpu_dec_fmt_list[VPU_FMT_TYPE_CODEC ][0 ].num_planes; +update_resolution_info (src_fmt,720 ,480 ); + + dst_fmt->pixelformat = vpu_dec_fmt_list[VPU_FMT_TYPE_RAW ][0 ].v4l2_pix_fmt; + dst_fmt->field =V4L2_FIELD_NONE ; + dst_fmt->flags =0 ; + dst_fmt->num_planes = vpu_dec_fmt_list[VPU_FMT_TYPE_RAW ][0 ].num_planes; +update_resolution_info (dst_fmt,736 ,480 ); +} + +static int vpu_dec_queue_init (void *priv,struct vb2_queue *src_vq,struct vb2_queue *dst_vq) +{ +struct vpu_instance *inst = priv; +struct vpu_platform_data *pdata =dev_get_platdata (inst->dev->v4l2_dev.dev); +int ret; + +DPRINTK (inst->dev,1 ,"\n" ); + + src_vq->type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ; + src_vq->io_modes =VB2_MMAP |VB2_USERPTR |VB2_DMABUF ; +if (pdata && pdata->mem_ops) + src_vq->mem_ops = pdata->mem_ops; +else + src_vq->mem_ops = &vb2_dma_contig_memops; + src_vq->ops = &vpu_dec_vb2_ops; + src_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + src_vq->buf_struct_size =sizeof (struct vpu_buffer ); + src_vq->allow_zero_bytesused =1 ; + src_vq->min_buffers_needed =0 ; + src_vq->drv_priv = inst; + src_vq->lock = &inst->dev->dev_lock; + src_vq->dev = inst->dev->v4l2_dev.dev; + ret =vb2_queue_init (src_vq); +if (ret) +return ret; + + dst_vq->type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ; + dst_vq->io_modes =VB2_MMAP |VB2_USERPTR |VB2_DMABUF ; +if (pdata && pdata->mem_ops) + dst_vq->mem_ops = pdata->mem_ops; +else + dst_vq->mem_ops = &vb2_dma_contig_memops; + dst_vq->ops = &vpu_dec_vb2_ops; + dst_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + dst_vq->buf_struct_size =sizeof (struct vpu_buffer ); + dst_vq->allow_zero_bytesused =1 ; + dst_vq->min_buffers_needed =0 ; + dst_vq->drv_priv = inst; + dst_vq->lock = &inst->dev->dev_lock; + dst_vq->dev = inst->dev->v4l2_dev.dev; + ret =vb2_queue_init (dst_vq); +if (ret) +return ret; + +return 0 ; +} + +static const struct vpu_instance_ops vpu_dec_inst_ops = { + .start_process = vpu_dec_start_decode, + .stop_process = vpu_dec_stop_decode, + .finish_process = vpu_dec_finish_decode, +}; + +static int vpu_dec_open (struct file *filp) +{ +struct video_device *vdev =video_devdata (filp); +struct vpu_device *dev =video_drvdata (filp); +struct vpu_instance *inst =NULL ; +struct v4l2_ctrl *ctrl; + + inst =kzalloc (sizeof (*inst),GFP_KERNEL ); +if (!inst) +return -ENOMEM ; + + inst->dev = dev; + inst->type =VPU_INST_TYPE_DEC ; + inst->ops = &vpu_dec_inst_ops; + +spin_lock_init (&inst->bitstream_lock); + +v4l2_fh_init (&inst->v4l2_fh, vdev); + filp->private_data = &inst->v4l2_fh; +v4l2_fh_add (&inst->v4l2_fh); + + inst->v4l2_fh.m2m_ctx =v4l2_m2m_ctx_init (dev->v4l2_m2m_dev, inst, vpu_dec_queue_init); +if (IS_ERR (inst->v4l2_fh.m2m_ctx)) +return -ENODEV ; + +v4l2_ctrl_handler_init (&inst->v4l2_ctrl_hdl,10 ); +v4l2_ctrl_new_custom (&inst->v4l2_ctrl_hdl, &vpu_thumbnail_mode,NULL ); + ctrl =v4l2_ctrl_new_std (&inst->v4l2_ctrl_hdl, &vpu_dec_ctrl_ops, +V4L2_CID_MIN_BUFFERS_FOR_CAPTURE ,1 ,32 ,1 ,1 ); +if (ctrl) + ctrl->flags |=V4L2_CTRL_FLAG_VOLATILE ; + +if (inst->v4l2_ctrl_hdl.error) +return -ENODEV ; + + inst->v4l2_fh.ctrl_handler = &inst->v4l2_ctrl_hdl; +v4l2_ctrl_handler_setup (&inst->v4l2_ctrl_hdl); + +set_default_format (&inst->src_fmt, &inst->dst_fmt); + inst->colorspace =V4L2_COLORSPACE_REC709 ; + inst->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; + inst->hsv_enc =0 ; + inst->quantization =V4L2_QUANTIZATION_DEFAULT ; + inst->xfer_func =V4L2_XFER_FUNC_DEFAULT ; + +return 0 ; +} + +static int vpu_dec_release (struct file *filp) +{ +int i; +struct vpu_instance *inst =to_vpu_inst (filp->private_data); +unsigned int loop_count =0 ; + +v4l2_m2m_ctx_release (inst->v4l2_fh.m2m_ctx); +if (inst->state !=VPU_INST_STATE_NONE ) { +while (vpu_dec_close (inst) ==RETCODE_VPU_STILL_RUNNING ) { +if (vpu_wait_interrupt (inst,VPU_DEC_TIMEOUT ) <0 ) { +DPRINTK (inst->dev,1 ,"failed to call vpu_wait_interrupt()\n" ); +if (loop_count <10 ) { + loop_count++; +continue ; + }else { +DPRINTK (inst->dev,1 ,"failed to call vpu_dec_close()\n" ); +break ; + } + }else { +break ; + } + } + } +for (i =0 ; i < inst->min_dst_frame_buf_count; i++) { +if (inst->frame_vbuf[i].size !=0 ) +vdi_free_dma_memory (inst->dev, &inst->frame_vbuf[i]); + } +if (inst->bitstream_vbuf.size !=0 ) +vdi_free_dma_memory (inst->dev, &inst->bitstream_vbuf); +v4l2_ctrl_handler_free (&inst->v4l2_ctrl_hdl); +v4l2_fh_del (&inst->v4l2_fh); +v4l2_fh_exit (&inst->v4l2_fh); +kfree (inst); + +return 0 ; +} + +static const struct v4l2_file_operations vpu_dec_fops = { + .owner =THIS_MODULE , + .open = vpu_dec_open, + .release = vpu_dec_release, + .unlocked_ioctl = video_ioctl2, + .poll = v4l2_m2m_fop_poll, + .mmap = v4l2_m2m_fop_mmap, +}; + +int vpu_dec_register_device (struct vpu_device *dev) +{ +struct video_device *vdev_dec; + + vdev_dec =devm_kzalloc (dev->v4l2_dev.dev,sizeof (*vdev_dec),GFP_KERNEL ); +if (!vdev_dec) +return -ENOMEM ; + + dev->video_dev_dec = vdev_dec; + +strscpy (vdev_dec->name,VPU_DEC_DEV_NAME ,sizeof (vdev_dec->name)); + vdev_dec->fops = &vpu_dec_fops; + vdev_dec->ioctl_ops = &vpu_dec_ioctl_ops; + vdev_dec->release = video_device_release_empty; + vdev_dec->v4l2_dev = &dev->v4l2_dev; + vdev_dec->vfl_dir =VFL_DIR_M2M ; + vdev_dec->device_caps =V4L2_CAP_VIDEO_M2M_MPLANE |V4L2_CAP_STREAMING ; + vdev_dec->lock = &dev->dev_lock; + +if (video_register_device (vdev_dec,VFL_TYPE_VIDEO ,-1 )) +return -1 ; + +video_set_drvdata (vdev_dec, dev); + +return 0 ; +} + +void vpu_dec_unregister_device (struct vpu_device *dev) +{ +video_unregister_device (dev->video_dev_dec); +} +drivers/staging/media/wave5/v4l2/vpu_dec.h new file +20
-0@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* +* Wave5 series multi-standard codec IP - decoder interface +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#ifndef __VPU_DEC_DRV_H__ +#define __VPU_DEC_DRV_H__ + +#include "vpu.h" + +#define VPU_DEC_DEV_NAME "C&M VPU decoder" +#define VPU_DEC_DRV_NAME "vpu-dec" + +#define V4L2_CID_VPU_THUMBNAIL_MODE (V4L2_CID_USER_BASE + 0x1001) + +int vpu_dec_register_device (struct vpu_device *dev); +void vpu_dec_unregister_device (struct vpu_device *dev); +#endif +drivers/staging/media/wave5/v4l2/vpu_enc.c new file +1559
-0@@ -0,0 +1,1580 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - encoder interface +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#include "vpu_enc.h" + +static const struct vpu_format vpu_enc_fmt_list[2 ][6 ] = { + [VPU_FMT_TYPE_CODEC ] = { + { + .v4l2_pix_fmt =V4L2_PIX_FMT_HEVC , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_H264 , + .num_planes =1 , + .max_width =8192 , + .min_width =32 , + .max_height =8192 , + .min_height =32 , + }, + }, + [VPU_FMT_TYPE_RAW ] = { + { + .v4l2_pix_fmt =V4L2_PIX_FMT_YUV420 , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV12 , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV21 , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_YUV420M , + .num_planes =3 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV12M , + .num_planes =2 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV21M , + .num_planes =2 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + } +}; + +static enum cod_std to_vpu_codstd (unsigned int v4l2_pix_fmt) +{ +switch (v4l2_pix_fmt) { +case V4L2_PIX_FMT_H264 : +return W_AVC_ENC ; +case V4L2_PIX_FMT_HEVC : +return W_HEVC_ENC ; +default : +return STD_UNKNOWN ; + } +} + +static const struct vpu_format *find_vpu_format (unsigned int v4l2_pix_fmt,enum vpu_format_type type) +{ +unsigned int index; + +for (index =0 ; index <ARRAY_SIZE (vpu_enc_fmt_list[type]); index++) { +if (vpu_enc_fmt_list[type][index].v4l2_pix_fmt == v4l2_pix_fmt) +return &vpu_enc_fmt_list[type][index]; + } + +return NULL ; +} + +static const struct vpu_format *find_vpu_format_by_index (unsigned int index,enum vpu_format_type type) +{ +if (index >=ARRAY_SIZE (vpu_enc_fmt_list[type])) +return NULL ; + +if (vpu_enc_fmt_list[type][index].v4l2_pix_fmt ==0 ) +return NULL ; + +return &vpu_enc_fmt_list[type][index]; +} + +static struct vb2_v4l2_buffer *get_valid_src_buf (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *vb2_v4l2_buf =NULL ; +struct v4l2_m2m_buffer *v4l2_m2m_buf =NULL ; +struct vpu_buffer *vpu_buf =NULL ; +bool no_src_buf = TRUE; + +v4l2_m2m_for_each_src_buf (inst->v4l2_fh.m2m_ctx, v4l2_m2m_buf) { + vb2_v4l2_buf = &v4l2_m2m_buf->vb; + vpu_buf =to_vpu_buf (vb2_v4l2_buf); + +if (!vpu_buf->consumed) { +DPRINTK (inst->dev,1 ,"no consumed src idx : %d\n" , + vb2_v4l2_buf->vb2_buf.index); + no_src_buf = FALSE; +break ; + } + } + +if (no_src_buf) + vb2_v4l2_buf =NULL ; + +return vb2_v4l2_buf; +} + +static struct vb2_v4l2_buffer *get_valid_dst_buf (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *vb2_v4l2_buf =NULL ; +struct v4l2_m2m_buffer *v4l2_m2m_buf =NULL ; +struct vpu_buffer *vpu_buf =NULL ; +bool no_dst_buf = TRUE; + +v4l2_m2m_for_each_dst_buf (inst->v4l2_fh.m2m_ctx, v4l2_m2m_buf) { + vb2_v4l2_buf = &v4l2_m2m_buf->vb; + vpu_buf =to_vpu_buf (vb2_v4l2_buf); + +if (!vpu_buf->consumed) { +DPRINTK (inst->dev,1 ,"no consumed dst idx : %d\n" , + vb2_v4l2_buf->vb2_buf.index); + no_dst_buf = FALSE; +break ; + } + } + +if (no_dst_buf) + vb2_v4l2_buf =NULL ; + +return vb2_v4l2_buf; +} + +static void update_resolution_info (struct v4l2_pix_format_mplane *pix_mp,unsigned int width, +unsigned int height) +{ +switch (pix_mp->pixelformat) { +case V4L2_PIX_FMT_YUV420 : +case V4L2_PIX_FMT_NV12 : +case V4L2_PIX_FMT_NV21 : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage =round_up (width,32 ) * height *3 /2 ; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); +break ; +case V4L2_PIX_FMT_YUV420M : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage =round_up (width,32 ) * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); + pix_mp->plane_fmt[1 ].bytesperline =round_up (width,32 ) /2 ; + pix_mp->plane_fmt[1 ].sizeimage =round_up (width,32 ) * height /4 ; +memset (&pix_mp->plane_fmt[1 ].reserved,0 ,sizeof (pix_mp->plane_fmt[1 ].reserved)); + pix_mp->plane_fmt[2 ].bytesperline =round_up (width,32 ) /2 ; + pix_mp->plane_fmt[2 ].sizeimage =round_up (width,32 ) * height /4 ; +memset (&pix_mp->plane_fmt[2 ].reserved,0 ,sizeof (pix_mp->plane_fmt[2 ].reserved)); +break ; +case V4L2_PIX_FMT_NV12M : +case V4L2_PIX_FMT_NV21M : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage =round_up (width,32 ) * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); + pix_mp->plane_fmt[1 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[1 ].sizeimage =round_up (width,32 ) * height /2 ; +memset (&pix_mp->plane_fmt[1 ].reserved,0 ,sizeof (pix_mp->plane_fmt[1 ].reserved)); +break ; +default : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =0 ; + pix_mp->plane_fmt[0 ].sizeimage =round_up (width,32 ) * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); +break ; + } +} + +static void vpu_enc_start_encode (struct vpu_instance *inst) +{ +enum ret_code ret_code; +struct queue_status_info q_status; +u32 remain_cmd_q, max_cmd_q =0 ; + +vpu_enc_give_command (inst,ENC_GET_QUEUE_STATUS , &q_status); +DPRINTK (inst->dev,1 ,"min_src_buf_cnt : %d | default : %d | qcount : %d | report_q : %d\n" , + inst->min_src_frame_buf_count,COMMAND_QUEUE_DEPTH , q_status.instance_queue_count, + q_status.report_queue_count); + + max_cmd_q = (inst->min_src_frame_buf_count <COMMAND_QUEUE_DEPTH ) ? + inst->min_src_frame_buf_count :COMMAND_QUEUE_DEPTH ; + remain_cmd_q = max_cmd_q - q_status.instance_queue_count; + +while (remain_cmd_q) { +struct vb2_v4l2_buffer *src_buf; +struct vb2_v4l2_buffer *dst_buf; +struct vpu_buffer *src_vbuf; +struct vpu_buffer *dst_vbuf; +struct frame_buffer frame_buf; +struct enc_param pic_param; +s32 luma_size = (inst->dst_fmt.width * inst->dst_fmt.height); +s32 chroma_size = ((inst->dst_fmt.width /2 ) * (inst->dst_fmt.height /2 )); + +memset (&pic_param,0 ,sizeof (struct enc_param )); + + src_buf =get_valid_src_buf (inst); + dst_buf =get_valid_dst_buf (inst); + +if (!src_buf || !dst_buf) { +DPRINTK (inst->dev,1 ,"no valid src/dst buf\n" ); +break ; + } + + src_vbuf =to_vpu_buf (src_buf); + dst_vbuf =to_vpu_buf (dst_buf); + +if (inst->src_fmt.num_planes ==1 ) { + frame_buf.buf_y =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); + frame_buf.buf_cb = frame_buf.buf_y + luma_size; + frame_buf.buf_cr = frame_buf.buf_cb + chroma_size; + }else if (inst->src_fmt.num_planes ==2 ) { + frame_buf.buf_y =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); + frame_buf.buf_cb =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,1 ); + frame_buf.buf_cr = frame_buf.buf_cb + chroma_size; + }else if (inst->src_fmt.num_planes ==3 ) { + frame_buf.buf_y =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); + frame_buf.buf_cb =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,1 ); + frame_buf.buf_cr =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,2 ); + } + frame_buf.stride = inst->dst_fmt.width; + frame_buf.cbcr_interleave =0 ; + +DPRINTK (inst->dev,1 ,"encoding src sequence : %d | dst sequence : %d\n" , + src_buf->sequence, dst_buf->sequence); + + pic_param.src_idx = src_buf->vb2_buf.index; + pic_param.source_frame = &frame_buf; + pic_param.pic_stream_buffer_addr =vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 ); + pic_param.pic_stream_buffer_size =vb2_plane_size (&dst_buf->vb2_buf,0 ); + pic_param.code_option.implicit_header_encode =1 ; + + ret_code =vpu_enc_start_one_frame (inst, &pic_param); +if (ret_code !=RETCODE_SUCCESS ) { +if (ret_code !=RETCODE_QUEUEING_FAILURE ) { + src_buf =v4l2_m2m_src_buf_remove (inst->v4l2_fh.m2m_ctx); + dst_buf =v4l2_m2m_dst_buf_remove (inst->v4l2_fh.m2m_ctx); +DPRINTK (inst->dev,1 ,"fail to call vpu_enc_start_one_frame() %d\n" , + ret_code); + inst->state =VPU_INST_STATE_STOP ; +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_ERROR ); + } + }else { +DPRINTK (inst->dev,1 ,"success to call vpu_enc_start_one_frame() %d\n" , + ret_code); + src_vbuf->consumed = TRUE; + dst_vbuf->consumed = TRUE; + } + + remain_cmd_q--; + } +} + +static void vpu_enc_stop_encode (struct vpu_instance *inst) +{ +struct queue_status_info q_status; + + inst->state =VPU_INST_STATE_STOP ; + +vpu_enc_give_command (inst,ENC_GET_QUEUE_STATUS , &q_status); + +if (q_status.report_queue_count + q_status.instance_queue_count ==0 ) +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); +} + +static void vpu_enc_finish_encode (struct vpu_instance *inst) +{ +enum ret_code ret_code; +struct enc_output_info enc_output_info; +int irq_status; + +if (kfifo_out (&inst->dev->irq_status, &irq_status,sizeof (int ))) +vpu_clear_interrupt_ex (inst, irq_status); + + ret_code =vpu_enc_get_output_info (inst, &enc_output_info); +if (ret_code !=RETCODE_SUCCESS ) { +DPRINTK (inst->dev,1 ,"vpu_enc_get_output_info fail %d | reason: %d | info : %d\n" , + ret_code, enc_output_info.error_reason, enc_output_info.warn_info); + }else { +struct vb2_v4l2_buffer *dst_buf =NULL ; +struct v4l2_m2m_buffer *v4l2_m2m_buf =NULL ; + + v4l2_m2m_buf =NULL ; +v4l2_m2m_for_each_dst_buf (inst->v4l2_fh.m2m_ctx, v4l2_m2m_buf) { + dst_buf = &v4l2_m2m_buf->vb; +if (enc_output_info.bitstream_buffer ==vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 )) +break ; + } + +if (enc_output_info.enc_src_idx >=0 ) { +struct vb2_v4l2_buffer *src_buf = +v4l2_m2m_src_buf_remove_by_idx (inst->v4l2_fh.m2m_ctx, + enc_output_info.enc_src_idx); + + inst->timestamp = src_buf->vb2_buf.timestamp; +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_DONE ); + } + +if (enc_output_info.recon_frame_index ==RECON_IDX_FLAG_ENC_END ) { +static const struct v4l2_event vpu_event_eos = { + .type =V4L2_EVENT_EOS + }; + + dst_buf->flags |=V4L2_BUF_FLAG_LAST ; +vb2_set_plane_payload (&dst_buf->vb2_buf,0 ,0 ); + + inst->state =VPU_INST_STATE_STOP ; +v4l2_event_queue_fh (&inst->v4l2_fh, &vpu_event_eos); + }else { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , enc_output_info.bitstream_size); + + dst_buf->vb2_buf.timestamp = inst->timestamp; + dst_buf->field =V4L2_FIELD_NONE ; +if (enc_output_info.pic_type ==PIC_TYPE_I ) { +if (enc_output_info.enc_vcl_nut ==19 || enc_output_info.enc_vcl_nut ==20 ) + dst_buf->flags |=V4L2_BUF_FLAG_KEYFRAME ; +else + dst_buf->flags |=V4L2_BUF_FLAG_PFRAME ; + }else if (enc_output_info.pic_type ==PIC_TYPE_P ) { + dst_buf->flags |=V4L2_BUF_FLAG_PFRAME ; + }else if (enc_output_info.pic_type ==PIC_TYPE_B ) { + dst_buf->flags |=V4L2_BUF_FLAG_BFRAME ; + } + } + +v4l2_m2m_dst_buf_remove_by_buf (inst->v4l2_fh.m2m_ctx, dst_buf); +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_DONE ); + } + +if (inst->state ==VPU_INST_STATE_STOP ) { +struct queue_status_info q_status; + +vpu_enc_give_command (inst,ENC_GET_QUEUE_STATUS , &q_status); +DPRINTK (inst->dev,1 ,"default : %d | qcount : %d | report_q : %d\n" , +COMMAND_QUEUE_DEPTH , q_status.instance_queue_count, + q_status.report_queue_count); + +if (q_status.report_queue_count + q_status.instance_queue_count ==0 ) +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); + }else { +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); + } +} + +static int vpu_enc_querycap (struct file *file,void *fh,struct v4l2_capability *cap) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"\n" ); + +strscpy (cap->driver,VPU_ENC_DRV_NAME ,sizeof (cap->driver)); +strscpy (cap->card,VPU_ENC_DRV_NAME ,sizeof (cap->card)); +strscpy (cap->bus_info,"platform:" VPU_ENC_DRV_NAME ,sizeof (cap->bus_info)); + +return 0 ; +} + +static int vpu_enc_enum_framesizes (struct file *file,void *fh,struct v4l2_frmsizeenum *fsize) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"\n" ); + +if (fsize->index) +return -EINVAL ; + + vpu_fmt =find_vpu_format (fsize->pixel_format,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + vpu_fmt =find_vpu_format (fsize->pixel_format,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + } + + fsize->type =V4L2_FRMSIZE_TYPE_CONTINUOUS ; + fsize->stepwise.min_width = vpu_fmt->min_width; + fsize->stepwise.max_width = vpu_fmt->max_width; + fsize->stepwise.step_width =1 ; + fsize->stepwise.min_height = vpu_fmt->min_height; + fsize->stepwise.max_height = vpu_fmt->max_height; + fsize->stepwise.step_height =1 ; + +return 0 ; +} + +static int vpu_enc_enum_fmt_cap (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"index : %d\n" , f->index); + + vpu_fmt =find_vpu_format_by_index (f->index,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + +return 0 ; +} + +static int vpu_enc_try_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"fourcc: %d width %d height %d num_planes %d field : %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + +if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) +return -EINVAL ; + + vpu_fmt =find_vpu_format (f->fmt.pix_mp.pixelformat,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; + f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; +update_resolution_info (&f->fmt.pix_mp, inst->dst_fmt.width, inst->dst_fmt.height); + }else { + f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; + f->fmt.pix_mp.num_planes = vpu_fmt->num_planes; +update_resolution_info (&f->fmt.pix_mp,clamp (f->fmt.pix_mp.width, + vpu_fmt->min_width, vpu_fmt->max_width), +clamp (f->fmt.pix_mp.height, vpu_fmt->min_height, + vpu_fmt->max_height)); + } + + f->fmt.pix_mp.flags =0 ; + f->fmt.pix_mp.field =V4L2_FIELD_NONE ; + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; +memset (&f->fmt.pix_mp.reserved,0 ,sizeof (f->fmt.pix_mp.reserved)); + +return 0 ; +} + +static int vpu_enc_s_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i, ret; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d field %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + + ret =vpu_enc_try_fmt_cap (file, fh, f); +if (ret) +return ret; + + inst->dst_fmt.width = f->fmt.pix_mp.width; + inst->dst_fmt.height = f->fmt.pix_mp.height; + inst->dst_fmt.pixelformat = f->fmt.pix_mp.pixelformat; + inst->dst_fmt.field = f->fmt.pix_mp.field; + inst->dst_fmt.flags = f->fmt.pix_mp.flags; + inst->dst_fmt.num_planes = f->fmt.pix_mp.num_planes; +for (i =0 ; i < inst->dst_fmt.num_planes; i++) { + inst->dst_fmt.plane_fmt[i].bytesperline = f->fmt.pix_mp.plane_fmt[i].bytesperline; + inst->dst_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; + } + +return 0 ; +} + +static int vpu_enc_g_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i; + +DPRINTK (inst->dev,1 ,"\n" ); + + f->fmt.pix_mp.width = inst->dst_fmt.width; + f->fmt.pix_mp.height = inst->dst_fmt.height; + f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; + f->fmt.pix_mp.field = inst->dst_fmt.field; + f->fmt.pix_mp.flags = inst->dst_fmt.flags; + f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; +for (i =0 ; i < f->fmt.pix_mp.num_planes; i++) { + f->fmt.pix_mp.plane_fmt[i].bytesperline = inst->dst_fmt.plane_fmt[i].bytesperline; + f->fmt.pix_mp.plane_fmt[i].sizeimage = inst->dst_fmt.plane_fmt[i].sizeimage; + } + + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; + +return 0 ; +} + +static int vpu_enc_enum_fmt_out (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"index : %d\n" , f->index); + + vpu_fmt =find_vpu_format_by_index (f->index,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + +return 0 ; +} + +static int vpu_enc_try_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d field %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + +if (f->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) +return -EINVAL ; + + vpu_fmt =find_vpu_format (f->fmt.pix_mp.pixelformat,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) { + f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; + f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; +update_resolution_info (&f->fmt.pix_mp, inst->src_fmt.width, inst->src_fmt.height); + }else { + f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; + f->fmt.pix_mp.num_planes = vpu_fmt->num_planes; +update_resolution_info (&f->fmt.pix_mp,clamp (f->fmt.pix_mp.width, + vpu_fmt->min_width, vpu_fmt->max_width), +clamp (f->fmt.pix_mp.height, vpu_fmt->min_height, + vpu_fmt->max_height)); + } + + f->fmt.pix_mp.flags =0 ; + f->fmt.pix_mp.field =V4L2_FIELD_NONE ; +memset (&f->fmt.pix_mp.reserved,0 ,sizeof (f->fmt.pix_mp.reserved)); + +return 0 ; +} + +static int vpu_enc_s_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i, ret; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d field : %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + + ret =vpu_enc_try_fmt_out (file, fh, f); +if (ret) +return ret; + + inst->src_fmt.width = f->fmt.pix_mp.width; + inst->src_fmt.height = f->fmt.pix_mp.height; + inst->src_fmt.pixelformat = f->fmt.pix_mp.pixelformat; + inst->src_fmt.field = f->fmt.pix_mp.field; + inst->src_fmt.flags = f->fmt.pix_mp.flags; + inst->src_fmt.num_planes = f->fmt.pix_mp.num_planes; +for (i =0 ; i < inst->src_fmt.num_planes; i++) { + inst->src_fmt.plane_fmt[i].bytesperline = f->fmt.pix_mp.plane_fmt[i].bytesperline; + inst->src_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; + } + + inst->colorspace = f->fmt.pix_mp.colorspace; + inst->ycbcr_enc = f->fmt.pix_mp.ycbcr_enc; + inst->hsv_enc = f->fmt.pix_mp.hsv_enc; + inst->quantization = f->fmt.pix_mp.quantization; + inst->xfer_func = f->fmt.pix_mp.xfer_func; + +update_resolution_info (&inst->dst_fmt, f->fmt.pix_mp.width, f->fmt.pix_mp.height); + +return 0 ; +} + +static int vpu_enc_g_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i; + +DPRINTK (inst->dev,1 ,"\n" ); + + f->fmt.pix_mp.width = inst->src_fmt.width; + f->fmt.pix_mp.height = inst->src_fmt.height; + f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; + f->fmt.pix_mp.field = inst->src_fmt.field; + f->fmt.pix_mp.flags = inst->src_fmt.flags; + f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; +for (i =0 ; i < f->fmt.pix_mp.num_planes; i++) { + f->fmt.pix_mp.plane_fmt[i].bytesperline = inst->src_fmt.plane_fmt[i].bytesperline; + f->fmt.pix_mp.plane_fmt[i].sizeimage = inst->src_fmt.plane_fmt[i].sizeimage; + } + + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; + +return 0 ; +} + +static int vpu_enc_g_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | target : %d\n" , s->type, s->target); + +if (s->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT ) { +switch (s->target) { +case V4L2_SEL_TGT_CROP_DEFAULT : +case V4L2_SEL_TGT_CROP_BOUNDS : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->src_fmt.width; + s->r.height = inst->src_fmt.height; +break ; +case V4L2_SEL_TGT_CROP : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->dst_fmt.width; + s->r.height = inst->dst_fmt.height; +DPRINTK (inst->dev,1 ,"V4L2_SEL_TGT_CROP width : %d | height : %d\n" , + s->r.width, s->r.height); +break ; +default : +return -EINVAL ; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_enc_s_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | target : %d\n" , s->type, s->target); + +if (s->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT ) { +switch (s->target) { +case V4L2_SEL_TGT_CROP : +DPRINTK (inst->dev,1 ,"V4L2_SEL_TGT_CROP width : %d | height : %d\n" , + s->r.width, s->r.height); + inst->dst_fmt.width = s->r.width; + inst->dst_fmt.height = s->r.height; +break ; +default : +return -EINVAL ; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_enc_try_encoder_cmd (struct file *file,void *fh,struct v4l2_encoder_cmd *ec) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"\n" ); + +if (ec->cmd !=V4L2_ENC_CMD_STOP && ec->cmd !=V4L2_ENC_CMD_START ) +return -EINVAL ; + + ec->flags =0 ; +return 0 ; +} + +static int vpu_enc_encoder_cmd (struct file *file,void *fh,struct v4l2_encoder_cmd *ec) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int ret; + +DPRINTK (inst->dev,1 ,"\n" ); + + ret =vpu_enc_try_encoder_cmd (file, fh, ec); +if (ret <0 ) +return ret; + +if (!vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE )) || + !vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ))) +return 0 ; + +switch (ec->cmd) { +case V4L2_ENC_CMD_STOP : +vpu_enc_stop_encode (inst); +break ; +case V4L2_ENC_CMD_START : +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_enc_subscribe_event (struct v4l2_fh *fh,const struct v4l2_event_subscription *sub) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | id : %d | flags : %d\n" , sub->type, sub->id, sub->flags); + +switch (sub->type) { +case V4L2_EVENT_EOS : +return v4l2_event_subscribe (fh, sub,0 ,NULL ); +case V4L2_EVENT_CTRL : +return v4l2_ctrl_subscribe_event (fh, sub); +default : +return -EINVAL ; + } +} + +static int vpu_enc_g_parm (struct file *file,void *fh,struct v4l2_streamparm *a) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d\n" , a->type); + +if (a->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT && a->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) +return -EINVAL ; + + a->parm.output.capability =V4L2_CAP_TIMEPERFRAME ; + a->parm.output.timeperframe.numerator =1 ; + a->parm.output.timeperframe.denominator = inst->frame_rate; + +DPRINTK (inst->dev,1 ,"numerator : %d | denominator : %d\n" , + a->parm.output.timeperframe.numerator, + a->parm.output.timeperframe.denominator); + +return 0 ; +} + +static int vpu_enc_s_parm (struct file *file,void *fh,struct v4l2_streamparm *a) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d\n" , a->type); + +if (a->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT && a->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) +return -EINVAL ; + + a->parm.output.capability =V4L2_CAP_TIMEPERFRAME ; +if (a->parm.output.timeperframe.denominator !=0 && a->parm.output.timeperframe.numerator !=0 ) { + inst->frame_rate = a->parm.output.timeperframe.denominator / a->parm.output.timeperframe.numerator; + }else { + a->parm.output.timeperframe.numerator =1 ; + a->parm.output.timeperframe.denominator = inst->frame_rate; + } + +DPRINTK (inst->dev,1 ,"numerator : %d | denominator : %d\n" , + a->parm.output.timeperframe.numerator, + a->parm.output.timeperframe.denominator); + +return 0 ; +} + +static const struct v4l2_ioctl_ops vpu_enc_ioctl_ops = { + .vidioc_querycap = vpu_enc_querycap, + .vidioc_enum_framesizes = vpu_enc_enum_framesizes, + + .vidioc_enum_fmt_vid_cap = vpu_enc_enum_fmt_cap, + .vidioc_s_fmt_vid_cap_mplane = vpu_enc_s_fmt_cap, + .vidioc_g_fmt_vid_cap_mplane = vpu_enc_g_fmt_cap, + .vidioc_try_fmt_vid_cap_mplane = vpu_enc_try_fmt_cap, + + .vidioc_enum_fmt_vid_out = vpu_enc_enum_fmt_out, + .vidioc_s_fmt_vid_out_mplane = vpu_enc_s_fmt_out, + .vidioc_g_fmt_vid_out_mplane = vpu_enc_g_fmt_out, + .vidioc_try_fmt_vid_out_mplane = vpu_enc_try_fmt_out, + + .vidioc_g_selection = vpu_enc_g_selection, + .vidioc_s_selection = vpu_enc_s_selection, + + .vidioc_g_parm = vpu_enc_g_parm, + .vidioc_s_parm = vpu_enc_s_parm, + + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, + .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, + .vidioc_streamon = v4l2_m2m_ioctl_streamon, + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, + + .vidioc_try_encoder_cmd = vpu_enc_try_encoder_cmd, + .vidioc_encoder_cmd = vpu_enc_encoder_cmd, + + .vidioc_subscribe_event = vpu_enc_subscribe_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, +}; + +static int vpu_enc_g_volatile_ctrl (struct v4l2_ctrl *ctrl) +{ +struct vpu_instance *inst =ctrl_to_vpu_inst (ctrl); + +DPRINTK (inst->dev,1 ,"name : %s\n" , ctrl->name); + +switch (ctrl->id) { +case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT : +if (inst->state !=VPU_INST_STATE_NONE && inst->state !=VPU_INST_STATE_OPEN ) + ctrl->val = inst->min_src_frame_buf_count; +break ; +default : +return -EINVAL ; + } + +DPRINTK (inst->dev,1 ,"value : %d\n" , ctrl->val); + +return 0 ; +} + +static int vpu_enc_s_ctrl (struct v4l2_ctrl *ctrl) +{ +struct vpu_instance *inst =ctrl_to_vpu_inst (ctrl); + +DPRINTK (inst->dev,1 ,"name : %s | value : %d\n" , ctrl->name, ctrl->val); + +switch (ctrl->id) { +case V4L2_CID_HFLIP : + inst->mirror_direction |= (ctrl->val <<1 ); +break ; +case V4L2_CID_VFLIP : + inst->mirror_direction |= ctrl->val; +break ; +case V4L2_CID_ROTATE : + inst->rot_angle = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_VBV_SIZE : + inst->vbv_buf_size = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE : +switch (ctrl->val) { +case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN : + inst->profile =HEVC_PROFILE_MAIN ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE : + inst->profile =HEVC_PROFILE_STILLPICTURE ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10 : + inst->profile =HEVC_PROFILE_MAIN10 ; + inst->bit_depth =10 ; +break ; +default : + inst->profile =0 ; + inst->bit_depth =0 ; +break ; + } +break ; +case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL : +switch (ctrl->val) { +case V4L2_MPEG_VIDEO_HEVC_LEVEL_1 : + inst->level =10 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_2 : + inst->level =20 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_2_1 : + inst->level =21 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_3 : + inst->level =30 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_3_1 : + inst->level =31 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_4 : + inst->level =40 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_4_1 : + inst->level =41 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_5 : + inst->level =50 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1 : + inst->level =51 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_5_2 : + inst->level =52 *3 ; +break ; +default : + inst->level =0 ; +break ; + } +break ; +case V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP : + inst->min_qp_i = ctrl->val; + inst->min_qp_p = ctrl->val; + inst->min_qp_b = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP : + inst->max_qp_i = ctrl->val; + inst->max_qp_p = ctrl->val; + inst->max_qp_b = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_H264_PROFILE : +switch (ctrl->val) { +case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE : +case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE : + inst->profile =H264_PROFILE_BP ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN : + inst->profile =H264_PROFILE_MP ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED : + inst->profile =H264_PROFILE_EXTENDED ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH : + inst->profile =H264_PROFILE_HP ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10 : + inst->profile =H264_PROFILE_HIGH10 ; + inst->bit_depth =10 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422 : + inst->profile =H264_PROFILE_HIGH422 ; + inst->bit_depth =10 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_PREDICTIVE : + inst->profile =H264_PROFILE_HIGH444 ; + inst->bit_depth =10 ; +break ; +default : + inst->profile =0 ; + inst->bit_depth =0 ; +break ; + } +break ; +case V4L2_CID_MPEG_VIDEO_H264_LEVEL : +switch (ctrl->val) { +case V4L2_MPEG_VIDEO_H264_LEVEL_1_0 : + inst->level =10 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_1B : + inst->level =9 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_1_1 : + inst->level =11 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_1_2 : + inst->level =12 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_1_3 : + inst->level =13 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_2_0 : + inst->level =20 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_2_1 : + inst->level =21 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_2_2 : + inst->level =22 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_3_0 : + inst->level =30 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_3_1 : + inst->level =31 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_3_2 : + inst->level =32 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_4_0 : + inst->level =40 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_4_1 : + inst->level =41 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_4_2 : + inst->level =42 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_5_0 : + inst->level =50 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_5_1 : + inst->level =51 ; +break ; +default : + inst->level =0 ; +break ; + } +break ; +case V4L2_CID_MPEG_VIDEO_H264_MIN_QP : + inst->min_qp_i = ctrl->val; + inst->min_qp_p = ctrl->val; + inst->min_qp_b = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_H264_MAX_QP : + inst->max_qp_i = ctrl->val; + inst->max_qp_p = ctrl->val; + inst->max_qp_b = ctrl->val; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct v4l2_ctrl_ops vpu_enc_ctrl_ops = { + .g_volatile_ctrl = vpu_enc_g_volatile_ctrl, + .s_ctrl = vpu_enc_s_ctrl, +}; + +static void set_default_enc_openparam (struct enc_open_param *open_param) +{ +unsigned int i; + + open_param->stream_endian =VPU_STREAM_ENDIAN ; + open_param->source_endian =VPU_SOURCE_ENDIAN ; + open_param->line_buf_int_en = TRUE; + + open_param->wave_param.gop_preset_idx =PRESET_IDX_IPP_SINGLE ; + open_param->wave_param.decoding_refresh_type =1 ; + open_param->wave_param.intra_qp =30 ; + open_param->wave_param.tmvp_enable =1 ; + open_param->wave_param.max_num_merge =2 ; + open_param->wave_param.lf_cross_slice_boundary_enable =1 ; + open_param->wave_param.skip_intra_trans =1 ; + open_param->wave_param.sao_enable =1 ; + open_param->wave_param.transform8x8_enable =1 ; + open_param->wave_param.intra_nx_n_enable =1 ; +for (i =0 ; i <MAX_GOP_NUM ; i++) + open_param->wave_param.fixed_bit_ratio[i] =1 ; + open_param->wave_param.cu_level_rc_enable =1 ;Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/staging/media/wave5/v4l2/vpu_enc.c line 1095
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_enc.c new file +10
-0+ open_param->wave_param.hvs_qp_enable =1 ; + open_param->wave_param.hvs_qp_scale =2 ; + open_param->wave_param.hvs_max_delta_qp =10 ; + open_param->wave_param.gop_param.custom_gop_size =1 ; + open_param->wave_param.initial_rc_qp =-1 ; + open_param->wave_param.nr_intra_weight_y =7 ; + open_param->wave_param.nr_intra_weight_cb =7 ; + open_param->wave_param.nr_intra_weight_cr =7 ; + open_param->wave_param.nr_inter_weight_y =4 ; + open_param->wave_param.nr_inter_weight_cb =4 ;
Make sure you replace all of these with proper errnos.
Quoted 36 lines
drivers/staging/media/wave5/v4l2/vpu_enc.c new file +11
-0Lines of this file are not shown. View the raw message.
drivers/staging/media/wave5/v4l2/vpu_enc.h new file +18
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 2 lines
2.17.1
Regards,
Ezequiel
Part of the diff is not shown here. View the raw message.
Re: [PATCH 3/6] staging: media: wave5: Add the v4l2 layer
Hi Ezequiel,
Le jeudi 16 septembre 2021 à 01:50 -0300, Ezequiel Garcia a écrit :
Quoted 10 lines
Hello Dafna, Nas and Robert:
I am quite happy to see a Chips and Media driver.
However, given it was announced that BeagleV™-Starlight prototype is not going to production [1], I'm curious about the plan for the driver. Is there an expectation to support silicon in the medium term (2021/2022)?
For instance, are you aware of any an effort to fix the cache coherency issues on the Starlight SoC?
Thanks for asking, yes of course, we will provide further information when this is released to the public. I'm kindly copying from the cover letter here, this is the information we can provide for now. Perhaps adding some clarity, we are not affiliated with StarFive, it was simply convenient that this community board had the same chip we are working on.
From cover letter:
Quoted 3,695 lines
Until we can test and resolve any issues on final silicon (due 2H 2021) this driver should remain in staging.
In general, the driver is a good start, but it looks like it needs a big broom and a ton of cleanup work. See below for some comments, but keep in mind I may have missed more things.
[1] https://beaglev.org/blog/2021-07-30-the-future-of-beaglev-community
Quoted 53 lines · Dafna Hirschfeld
Add the decoder and encoder implementing the v4l2
API. This patch also adds theMakefileand theVIDEO_WAVE_VPUconfigSigned-off-by Robert Beckett <[email protected]>Signed-off-by Dafna Hirschfeld <[email protected]>--- drivers/staging/media/Kconfig | 2 + drivers/staging/media/Makefile | 1 + drivers/staging/media/wave5/Kconfig | 10 + drivers/staging/media/wave5/Makefile | 10 + drivers/staging/media/wave5/v4l2/vpu.c | 386 +++++ drivers/staging/media/wave5/v4l2/vpu.h | 76 + drivers/staging/media/wave5/v4l2/vpu_dec.c | 1393 +++++++++++++++++ drivers/staging/media/wave5/v4l2/vpu_dec.h | 20 + drivers/staging/media/wave5/v4l2/vpu_enc.c | 1580 ++++++++++++++++++++ drivers/staging/media/wave5/v4l2/vpu_enc.h | 18 + 10 files changed, 3496 insertions(+) create mode 100644 drivers/staging/media/wave5/Kconfig create mode 100644 drivers/staging/media/wave5/Makefile create mode 100644 drivers/staging/media/wave5/v4l2/vpu.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu.h create mode 100644 drivers/staging/media/wave5/v4l2/vpu_dec.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu_dec.h create mode 100644 drivers/staging/media/wave5/v4l2/vpu_enc.c create mode 100644 drivers/staging/media/wave5/v4l2/vpu_enc.hdrivers/staging/media/Kconfig +2
-0@@ -44,4 +44,6 @@ source "drivers/staging/media/ipu3/Kconfig" source "drivers/staging/media/av7110/Kconfig" +source "drivers/staging/media/wave5/Kconfig" + endifdrivers/staging/media/Makefile +1
-0@@ -11,3 +11,4 @@ obj-$(CONFIG_VIDEO_HANTRO) += hantro/ obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3/ obj-$(CONFIG_VIDEO_ZORAN) += zoran/ obj-$(CONFIG_DVB_AV7110) += av7110/ +obj-$(CONFIG_VIDEO_WAVE_VPU) += wave5/drivers/staging/media/wave5/Kconfig new file +0
-0drivers/staging/media/wave5/Kconfig line 4
Quoted 4 lines
drivers/staging/media/wave5/Kconfig new file +4
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +config VIDEO_WAVE_VPU + tristate "Chips&Media Wave Codec Driver" + depends on VIDEO_DEV && VIDEO_V4L2 && OFThe driver has some ifdef
CONFIG_OF. Either drop this or drop the ifdefs.drivers/staging/media/wave5/Kconfig line 8
Quoted 4 lines
drivers/staging/media/wave5/Kconfig new file +4
-0+ select VIDEOBUF2_DMA_CONTIG + select VIDEOBUF2_VMALLOC + select V4L2_MEM2MEM_DEV + select GENERIC_ALLOCATORI can't see why this is
GENERIC_ALLOCATORis here. Where is the API used?Quoted 8 lines
drivers/staging/media/wave5/Kconfig new file +2
-0+ help + Chips&Media codec driverdrivers/staging/media/wave5/Makefile new file +0
-0drivers/staging/media/wave5/Makefile line 10
Quoted 10 lines
drivers/staging/media/wave5/Makefile new file +10
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_VIDEO_WAVE_VPU) += wave5.o +wave5-objs += vpuapi/wave/wave5.o \ + vpuapi/vpuapi.o \ + vdi/vdi.o \ + v4l2/vpu_dec.o \ + v4l2/vpu.o \ + v4l2/vpu_enc.o +It seems like an overkill to have a directory hierarchy for just these few files. How about you collapse them under a single wave5 directory?
It will be easier to read and maintain.
Quoted 18 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +12
-0@@ -0,0 +1,386 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - platform driver +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/clk.h> +#include <linux/firmware.h> +#include <linux/interrupt.h> drivers/staging/media/wave5/v4l2/vpu.c line 22
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+#include "vpu.h" +#include "vpu_dec.h" +#include "vpu_enc.h" +#include "../vpuapi/wave/wave5_regdefine.h" +#include "../vpuapi/vpuconfig.h" +#include "../vpuapi/wave/wave5.h" + +#define VPU_PLATFORM_DEVICE_NAME "vdec" +#define VPU_CLK_NAME "vcodec" +IIUC, given there's only just one clock, it's better to avoid requiring a name. Maybe you can double check that with some device tree experts.
drivers/staging/media/wave5/v4l2/vpu.c line 27
Quoted 5 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +5
-0+/* if the platform driver knows this driver */ +/* the definition of VPU_REG_BASE_ADDR and VPU_REG_SIZE are not meaningful */ +#define VPU_REG_BASE_ADDR 0x75000000 +#define VPU_REG_SIZE 0x4000 +
REG_macros unused.drivers/staging/media/wave5/v4l2/vpu.c line 30
Quoted 3 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +3
-0+struct wave5_match_data { +bool decoder; +bool encoder;Nitpick, maybe a bit mask for functions?
drivers/staging/media/wave5/v4l2/vpu.c line 42
Quoted 12 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +12
-0+const char *fw_name; +}; + +const struct wave5_match_data default_match_data = { + .decoder = true, + .encoder = true, + .fw_name ="chagall.bin" , +}; + +unsigned int vpu_debug =1 ; +module_param (vpu_debug, uint,0644 ); +I would rename this to just "debug".
Quoted 38 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +38
-0+int vpu_wait_interrupt (struct vpu_instance *inst,unsigned int timeout) +{ +int ret; + + ret =wait_for_completion_timeout (&inst->dev->irq_done, +msecs_to_jiffies (timeout)); +if (!ret) +return -ETIMEDOUT ; + +reinit_completion (&inst->dev->irq_done); + +return 0 ; +} + +static irqreturn_t vpu_irq (int irq,void *dev_id) +{ +struct vpu_device *dev = (struct vpu_device *)dev_id; +unsigned int irq_status; + +if (vdi_read_register (dev,W5_VPU_VPU_INT_STS )) { + irq_status =vdi_read_register (dev,W5_VPU_VINT_REASON ); +vdi_write_register (dev,W5_VPU_VINT_REASON_CLR , irq_status); +vdi_write_register (dev,W5_VPU_VINT_CLEAR ,0x1 ); + +kfifo_in (&dev->irq_status, &irq_status,sizeof (int )); + +return IRQ_WAKE_THREAD ; + } + +return IRQ_HANDLED ; +} + +static irqreturn_t vpu_irq_thread (int irq,void *dev_id) +{ +struct vpu_device *dev = (struct vpu_device *)dev_id; +struct vpu_instance *inst; +unsigned int irq_status, val; +int ret;drivers/staging/media/wave5/v4l2/vpu.c line 90
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+ +while (kfifo_len (&dev->irq_status)) { + inst =v4l2_m2m_get_curr_priv (dev->v4l2_m2m_dev); +if (inst) { + inst->ops->finish_process (inst); + }else { + ret =kfifo_out (&dev->irq_status, &irq_status,sizeof (int )); +if (!ret) +break ; +DPRINTK (dev,1 ,"irq_status: 0x%x\n" , irq_status);If you explore other drivers you will see that it's preferred to use dprintk instead of DPRINTK. Or just use
dev_dbgwhich is probably better?Also, the driver only seems to use debug level "1", so you can drop the parameter.
Again, I believe
dev_dbgmay be more flexible and powerful.Quoted 54 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +54
-0+ val =vdi_read_register (dev,W5_VPU_VINT_REASON_USR ); + val &= ~irq_status; +vdi_write_register (dev,W5_VPU_VINT_REASON_USR , val); +complete (&dev->irq_done); + } + } + +return IRQ_HANDLED ; +} + +static void vpu_device_run (void *priv) +{ +struct vpu_instance *inst = priv; + +DPRINTK (inst->dev,1 ,"inst type=%d state=%d\n" , + inst->type, inst->state); + + inst->ops->start_process (inst); +} + +static int vpu_job_ready (void *priv) +{ +struct vpu_instance *inst = priv; + +DPRINTK (inst->dev,1 ,"inst type=%d state=%d\n" , + inst->type, inst->state); + +if (inst->state ==VPU_INST_STATE_STOP ) +return 0 ; + +return 1 ; +} + +static void vpu_job_abort (void *priv) +{ +struct vpu_instance *inst = priv; + +DPRINTK (inst->dev,1 ,"inst type=%d state=%d\n" , + inst->type, inst->state); + + inst->ops->stop_process (inst); +} + +static const struct v4l2_m2m_ops vpu_m2m_ops = { + .device_run = vpu_device_run, + .job_ready = vpu_job_ready, + .job_abort = vpu_job_abort, +}; + +static int vpu_load_firmware (struct device *dev,const char *fw_name) +{ +const struct firmware *fw; +enum ret_code ret =RETCODE_SUCCESS ; +u32 version;drivers/staging/media/wave5/v4l2/vpu.c line 154
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+u32 revision; +u32 product_id; + +if (request_firmware (&fw, fw_name, dev)) { +pr_err ("request_firmware fail\n" ); +return -1 ; + } + + ret =vpu_init_with_bitcode (dev, (unsigned short *)fw->data, fw->size /2 ); +if (ret !=RETCODE_SUCCESS ) {Get rid of enum
ret_codeand instead use 0 or errno.drivers/staging/media/wave5/v4l2/vpu.c line 156
Quoted 2 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +2
-0+pr_err ("vpu_init_with_bitcode fail\n" ); +return -1 ;Have you noticed this -1 is returned to the caller of
vpu_probe? Just propagate the errno (after getting rid of enumret_code). Same may apply to the rest of the driver.drivers/staging/media/wave5/v4l2/vpu.c line 168
Quoted 12 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +12
-0+ } +release_firmware (fw); + + ret =vpu_get_version_info (dev, &version, &revision, &product_id); +if (ret !=RETCODE_SUCCESS ) { +pr_err ("vpu_get_version_info fail\n" ); +return -1 ; + } + +pr_err ("enum product_id : %08x\n" , product_id); +pr_err ("fw_version : %08x(r%d)\n" , version, revision); +Avoid pr_{} and instead go with dev_{} / v4l2_{}.
Same may apply to the rest of the driver.Quoted 25 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +25
-0+return 0 ; +} + +static int vpu_probe (struct platform_device *pdev) +{ +int err =0 ; +struct vpu_device *dev; +struct resource *res =NULL ; +const struct wave5_match_data *match_data; + + match_data =device_get_match_data (&pdev->dev); +if (!match_data) + match_data = &default_match_data; + +/* physical addresses limited to 32 bits */ +dma_set_mask (&pdev->dev,DMA_BIT_MASK (32 )); +dma_set_coherent_mask (&pdev->dev,DMA_BIT_MASK (32 )); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"unable to get mem resource\n" ); +return -EINVAL ; + } + dev =devm_kzalloc (&pdev->dev,sizeof (*dev),GFP_KERNEL ); +if (!dev)drivers/staging/media/wave5/v4l2/vpu.c line 203
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+return -ENOMEM ; + + dev->vdb_register.daddr = res->start; + dev->vdb_register.size =resource_size (res); + dev->vdb_register.vaddr =devm_ioremap (&pdev->dev, dev->vdb_register.daddr, dev->vdb_register.size); +ida_init (&dev->inst_ida); + +dev_dbg (&pdev->dev,"REGISTER BASE daddr=%pad vaddr=%p size=%zu\n" , + &dev->vdb_register.daddr, dev->vdb_register.vaddr, dev->vdb_register.size); +This
dev_dbgmakes little sense.Quoted 39 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +39
-0+mutex_init (&dev->dev_lock); +mutex_init (&dev->hw_lock); +init_completion (&dev->irq_done); +dev_set_drvdata (&pdev->dev, dev); + dev->dev = &pdev->dev; + dev->product_code =vdi_read_register (dev,VPU_PRODUCT_CODE_REGISTER ); + err =vdi_init (&pdev->dev); +if (err <0 ) { +dev_err (&pdev->dev,"failed to init vdi: %d\n" , err); +return err; + } + dev->product =wave_vpu_get_product_id (dev); + + err =v4l2_device_register (&pdev->dev, &dev->v4l2_dev); +if (err) { +dev_err (&pdev->dev,"v4l2_device_register fail: %d\n" , err); + goto err_v4l2_dev_reg; + } + + dev->v4l2_m2m_dev =v4l2_m2m_init (&vpu_m2m_ops); +if (IS_ERR (dev->v4l2_m2m_dev)) { +dev_err (&pdev->dev,"v4l2_m2m_init fail: %ld\n" ,PTR_ERR (dev->v4l2_m2m_dev)); + err =PTR_ERR (dev->v4l2_m2m_dev); + goto err_m2m_init; + } + +if (match_data->decoder) { + err =vpu_dec_register_device (dev); +if (err) { +dev_err (&pdev->dev,"vpu_dec_register_device fail: %d\n" , err); + goto err_dec_reg; + } + } +if (match_data->encoder) { + err =vpu_enc_register_device (dev); +if (err) { +dev_err (&pdev->dev,"vpu_enc_register_device fail: %d\n" , err); + goto err_enc_reg; + }drivers/staging/media/wave5/v4l2/vpu.c line 252
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+ } + + dev->clk =devm_clk_get (&pdev->dev,VPU_CLK_NAME ); +if (IS_ERR (dev->clk)) { +dev_warn (&pdev->dev,"unable to get clock: %ld\n" ,PTR_ERR (dev->clk)); +/* continue wihtout clock, assume externally managed */ + dev->clk =NULL ; + } + + err =clk_prepare_enable (dev->clk);Are you sure you actually need to enable the clock in
probe()?Quoted 77 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +77
-0+if (err) { +dev_err (&pdev->dev,"failed to enable clock: %d\n" , err); + goto err_clk_prep_en; + } + + res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!res) { +dev_err (&pdev->dev,"failed to get irq resource\n" ); + err = -ENXIO ; + goto err_get_irq; + } + dev->irq = res->start; + +if (kfifo_alloc (&dev->irq_status,16 *sizeof (int ),GFP_KERNEL )) { +dev_err (&pdev->dev,"failed to allocate fifo\n" ); + goto err_kfifo_alloc; + } + + err =devm_request_threaded_irq (&pdev->dev, dev->irq, vpu_irq, vpu_irq_thread,0 ,"vpu_irq" , dev); +if (err) { +dev_err (&pdev->dev,"fail to register interrupt handler: %d\n" , err); + goto err_request_irq; + } + + err =vpu_load_firmware (&pdev->dev, match_data->fw_name); +if (err) { +dev_err (&pdev->dev,"failed to vpu_load_firmware: %d\n" , err); + goto err_load_fw; + } + +return 0 ; + +err_load_fw: +err_request_irq: +kfifo_free (&dev->irq_status); +err_kfifo_alloc: +err_get_irq: +clk_disable_unprepare (dev->clk); +err_clk_prep_en: +if (match_data->encoder) +vpu_enc_unregister_device (dev); +err_enc_reg: +if (match_data->decoder) +vpu_dec_unregister_device (dev); +err_dec_reg: +v4l2_m2m_release (dev->v4l2_m2m_dev); +err_m2m_init: +v4l2_device_unregister (&dev->v4l2_dev); +err_v4l2_dev_reg: +vdi_release (&pdev->dev); + +return err; +} + +static int vpu_remove (struct platform_device *pdev) +{ +struct vpu_device *dev =dev_get_drvdata (&pdev->dev); + +clk_disable_unprepare (dev->clk); +vpu_enc_unregister_device (dev); +vpu_dec_unregister_device (dev); +v4l2_m2m_release (dev->v4l2_m2m_dev); +v4l2_device_unregister (&dev->v4l2_dev); +kfifo_free (&dev->irq_status); +vdi_release (&pdev->dev); + +return 0 ; +} + +#ifdef CONFIG_OF +const struct wave5_match_data wave511_data = { + .decoder = true, + .encoder = false, + .fw_name ="wave511_dec_fw.bin" , +}; + +const struct wave5_match_data wave521_data = {drivers/staging/media/wave5/v4l2/vpu.c line 339
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+ .decoder = false, + .encoder = true, + .fw_name = "wave521_enc_fw.bin", +}; + +const struct wave5_match_data wave521c_data = { + .decoder = true, + .encoder = true, + .fw_name ="wave521c_codec_fw.bin" , +};Can you move
default_match_datahere?Quoted 18 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +18
-0+ +// TODO: move this file to wave5 layer and convert runtime paramer filling to +// predefined structure used as data here. +static const struct of_device_id wave5_dt_ids[] = { + { .compatible ="cnm,cm511-vpu" , .data = &wave511_data }, + { .compatible ="cnm,cm517-vpu" , .data = &default_match_data }, + { .compatible ="cnm,cm521-vpu" , .data = &wave521_data }, + { .compatible ="cnm,cm521c-vpu" , .data = &wave521c_data }, + { .compatible ="cnm,cm521c-dual-vpu" , .data = &wave521c_data }, + { .compatible ="cnm,cm521e1-vpu" , .data = &default_match_data }, + { .compatible ="cnm,cm537-vpu" , .data = &default_match_data }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, wave5_dt_ids); +#endif + +static struct platform_driver vpu_driver = { + .driver = {drivers/staging/media/wave5/v4l2/vpu.c line 367
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+ .name = VPU_PLATFORM_DEVICE_NAME, + .of_match_table = of_match_ptr(wave5_dt_ids), + }, + .probe = vpu_probe, + .remove = vpu_remove, + //.suspend = vpu_suspend, + //.resume = vpu_resume, +}; + +static int __init vpu_init (void )So through all these files, I'd like to see a
wave5_prefix for all the functions. This is important even for static functions.I'm aware it may seem not strongly enforced, but you can imagine how hard it would be for any code navigation tool to work if every driver would have functions named as
vpu_probe,vpu_init,set_default_format, just to name a few.Quoted 5 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +5
-0+{ +int ret; + + ret =platform_driver_register (&vpu_driver); +drivers/staging/media/wave5/v4l2/vpu.c line 382
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +10
-0+return ret; +} + +static void __exit vpu_exit(void) +{ +platform_driver_unregister (&vpu_driver); +} + +MODULE_DESCRIPTION ("chips&media VPU V4L2 driver" ); +MODULE_LICENSE ("GPL" );This file says GPL-2 or BSD-3-Clause in the header. Is it OK to have "GPL" here?
drivers/staging/media/wave5/v4l2/vpu.c line 385
Quoted 3 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +3
-0+ +module_init (vpu_init); +module_exit (vpu_exit);Use
module_platform_driver.Quoted 118 lines
drivers/staging/media/wave5/v4l2/vpu.c new file +1
-0+drivers/staging/media/wave5/v4l2/vpu.h new file +76
-0@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* +* Wave5 series multi-standard codec IP - basic types +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#ifndef __VPU_DRV_H__ +#define __VPU_DRV_H__ + +#include <media/v4l2-ctrls.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-event.h> +#include <media/v4l2-fh.h> +#include <media/videobuf2-v4l2.h> +#include <media/videobuf2-dma-contig.h> +#include <media/videobuf2-vmalloc.h> +#include "../vpuapi/vpuconfig.h" +#include "../vpuapi/vpuapi.h" + +#define DPRINTK(dev, level, fmt, args...) \ + v4l2_dbg(level, vpu_debug, &(dev)->v4l2_dev, "[%s]" fmt, __func__, ##args) + +#define VPU_BUF_SYNC_TO_DEVICE 0 +#define VPU_BUF_SYNC_FROM_DEVICE 1 +struct vpu_platform_data { +struct vb2_mem_ops *mem_ops; +int (*pre_fw_init)(struct device *dev,void __iomem *base); +uint32_t (*read_register)(struct device *dev,void __iomem *base,uint32_t reg); +void (*write_register)(struct device *dev,void __iomem *base,uint32_t reg,uint32_t data); +int (*buffer_sync)(struct device *dev,void __iomem *base,struct vpu_buf *vb,size_t offset,uint32_t len,int dir); +int (*buffer_alloc)(struct device *dev,struct vpu_buf *vb); +void (*buffer_free)(struct device *dev,struct vpu_buf *vb); +int (*reset)(struct device *dev,void __iomem *base); +uint32_t (*get_hwoption)(struct device *dev); +}; + +struct vpu_buffer { +struct v4l2_m2m_buffer v4l2_m2m_buf; +bool consumed; +}; + +enum vpu_format_type { +VPU_FMT_TYPE_CODEC =0 , +VPU_FMT_TYPE_RAW =1 +}; + +struct vpu_format { +unsigned int v4l2_pix_fmt; +unsigned int num_planes; +unsigned int max_width; +unsigned int min_width; +unsigned int max_height; +unsigned int min_height; +}; + +extern unsigned int vpu_debug; + +static inline struct vpu_instance *to_vpu_inst (struct v4l2_fh *vfh) +{ + return container_of(vfh, struct vpu_instance, v4l2_fh); +} + +static inline struct vpu_instance *ctrl_to_vpu_inst (struct v4l2_ctrl *vctrl) +{ + return container_of(vctrl->handler, struct vpu_instance, v4l2_ctrl_hdl); +} + +static inline struct vpu_buffer *to_vpu_buf (struct vb2_v4l2_buffer *vbuf) +{ + return container_of(vbuf, struct vpu_buffer, v4l2_m2m_buf.vb); +} + +int vpu_wait_interrupt (struct vpu_instance *inst,unsigned int timeout); + +#endif +drivers/staging/media/wave5/v4l2/vpu_dec.c new file +29
-0@@ -0,0 +1,1393 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - decoder interface +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#include "vpu_dec.h" + +static const struct vpu_format vpu_dec_fmt_list[2 ][6 ] = { + [VPU_FMT_TYPE_CODEC ] = { + { + .v4l2_pix_fmt =V4L2_PIX_FMT_HEVC , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_H264 , + .num_planes =1 , + .max_width =8192 , + .min_width =32 , + .max_height =8192 , + .min_height =32 , + }, + }, + [VPU_FMT_TYPE_RAW ] = { + {drivers/staging/media/wave5/v4l2/vpu_dec.c line 39
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +10
-0+ .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420, + .num_planes = 1, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV12, + .num_planes = 1,You shouldn't need
num_planeshere, you normally can get all that stuff using thev4l2_fill_pixfmt_helpers.Quoted 83 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +83
-0+ .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV21, + .num_planes = 1, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420M, + .num_planes = 3, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV12M, + .num_planes = 2, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, + .num_planes = 2, + .max_width = 8192, + .min_width = 8, + .max_height = 8192, + .min_height = 8, + }, + } +}; + +static enum wave_std to_vpu_codstd(unsigned int v4l2_pix_fmt) +{ + switch (v4l2_pix_fmt) { + case V4L2_PIX_FMT_H264: + return W_AVC_DEC; + case V4L2_PIX_FMT_HEVC: + return W_HEVC_DEC; + default: + return STD_UNKNOWN; + } +} + +static const struct vpu_format *find_vpu_format(unsigned int v4l2_pix_fmt, enum vpu_format_type type) +{ + unsigned int index; + + for (index = 0; index < ARRAY_SIZE(vpu_dec_fmt_list[type]); index++) { + if (vpu_dec_fmt_list[type][index].v4l2_pix_fmt == v4l2_pix_fmt) + return &vpu_dec_fmt_list[type][index]; + } + + return NULL; +} + +static const struct vpu_format *find_vpu_format_by_index(unsigned int index, enum vpu_format_type type) +{ + if (index >= ARRAY_SIZE(vpu_dec_fmt_list[type])) + return NULL; + + if (vpu_dec_fmt_list[type][index].v4l2_pix_fmt == 0) + return NULL; + + return &vpu_dec_fmt_list[type][index]; +} + +static void handle_bitstream_buffer(struct vpu_instance *inst) +{ + struct v4l2_m2m_buffer *v4l2_m2m_buf = NULL; + + unsigned long flags; + + spin_lock_irqsave(&inst->bitstream_lock, flags); +drivers/staging/media/wave5/v4l2/vpu_dec.c line 132
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +10
-0+v4l2_m2m_for_each_src_buf (inst->v4l2_fh.m2m_ctx, v4l2_m2m_buf) { +enum ret_code ret_code =RETCODE_SUCCESS ; +struct vb2_v4l2_buffer *vbuf = &v4l2_m2m_buf->vb; +struct vpu_buffer *vpu_buf =to_vpu_buf (vbuf); +u32 src_size =vb2_get_plane_payload (&vbuf->vb2_buf,0 ); +void *src_buf =vb2_plane_vaddr (&vbuf->vb2_buf,0 ); +dma_addr_t bs_rd_ptr =0 ; +dma_addr_t bs_wr_ptr =0 ; +u32 bs_remain_size =0 ; +size_t offset;Fix indentation.
Quoted 88 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +88
-0+ +if (vpu_buf->consumed) { +DPRINTK (inst->dev,1 ,"already consumed buffer\n" ); +continue ; + } + +vpu_dec_get_bitstream_buffer (inst, &bs_rd_ptr, &bs_wr_ptr, &bs_remain_size); + +if (bs_remain_size < src_size) { +DPRINTK (inst->dev,1 ,"fill next time : remained size < source size.\n" ); +continue ; + } + + offset = bs_wr_ptr - inst->bitstream_vbuf.daddr; +if (bs_wr_ptr + src_size > inst->bitstream_vbuf.daddr + inst->bitstream_vbuf.size) { +int temp_size; + + temp_size = inst->bitstream_vbuf.daddr + inst->bitstream_vbuf.size - bs_wr_ptr; +vdi_write_memory (inst->dev, &inst->bitstream_vbuf, offset, src_buf, + temp_size,VDI_128BIT_LITTLE_ENDIAN ); +vdi_write_memory (inst->dev, &inst->bitstream_vbuf,0 , + src_buf + temp_size, src_size - temp_size,VDI_128BIT_LITTLE_ENDIAN ); + }else { +vdi_write_memory (inst->dev, &inst->bitstream_vbuf, offset, src_buf, + src_size,VDI_128BIT_LITTLE_ENDIAN ); + } + + ret_code =vpu_dec_update_bitstream_buffer (inst, src_size); +if (ret_code !=RETCODE_SUCCESS ) { +DPRINTK (inst->dev,1 ,"failed to call vpu_dec_update_bitstream_buffer() : %d\n" , ret_code); +continue ; + } + + vpu_buf->consumed = TRUE; + +if (inst->state ==VPU_INST_STATE_WAIT_BUF ) + inst->state =VPU_INST_STATE_PIC_RUN ; + } + +spin_unlock_irqrestore (&inst->bitstream_lock, flags); +} + +static void handle_src_buffer (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *src_buf; + +unsigned long flags; + +spin_lock_irqsave (&inst->bitstream_lock, flags); + + src_buf =v4l2_m2m_next_src_buf (inst->v4l2_fh.m2m_ctx); +if (src_buf) { +struct vpu_buffer *vpu_buf =to_vpu_buf (src_buf); + +if (vpu_buf->consumed) { +u32 remain_num =0 ; + +DPRINTK (inst->dev,1 ,"already consumed buffer\n" ); + remain_num =v4l2_m2m_num_src_bufs_ready (inst->v4l2_fh.m2m_ctx); +DPRINTK (inst->dev,1 ,"remain buffer : %d\n" , remain_num); +if (remain_num >1 ) { + src_buf =v4l2_m2m_src_buf_remove (inst->v4l2_fh.m2m_ctx); + inst->timestamp = src_buf->vb2_buf.timestamp; +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_DONE ); + } + } + } +spin_unlock_irqrestore (&inst->bitstream_lock, flags); +} + +static void update_resolution_info (struct v4l2_pix_format_mplane *pix_mp,unsigned int width,unsigned int height) +{ +switch (pix_mp->pixelformat) { +case V4L2_PIX_FMT_YUV420 : +case V4L2_PIX_FMT_NV12 : +case V4L2_PIX_FMT_NV21 : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage = width * height *3 /2 ; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); +break ; +case V4L2_PIX_FMT_YUV420M : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage = width * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved));drivers/staging/media/wave5/v4l2/vpu_dec.c line 230
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +10
-0+ pix_mp->plane_fmt[1 ].bytesperline =round_up (width,32 ) /2 ; + pix_mp->plane_fmt[1 ].sizeimage = width * height /4 ; +memset (&pix_mp->plane_fmt[1 ].reserved,0 ,sizeof (pix_mp->plane_fmt[1 ].reserved)); + pix_mp->plane_fmt[2 ].bytesperline =round_up (width,32 ) /2 ; + pix_mp->plane_fmt[2 ].sizeimage = width * height /4 ; +memset (&pix_mp->plane_fmt[2 ].reserved,0 ,sizeof (pix_mp->plane_fmt[2 ].reserved)); +break ; +case V4L2_PIX_FMT_NV12M : +case V4L2_PIX_FMT_NV21M : + pix_mp->width =round_up (width,32 );Yet more indentation issues.
Quoted 22 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +22
-0+ pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage = width * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); + pix_mp->plane_fmt[1 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[1 ].sizeimage = width * height /2 ; +memset (&pix_mp->plane_fmt[1 ].reserved,0 ,sizeof (pix_mp->plane_fmt[1 ].reserved)); +break ; +default : + pix_mp->width = width; + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =0 ; + pix_mp->plane_fmt[0 ].sizeimage = width * height /2 ; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); +break ; + } +} + +static void vpu_dec_start_decode (struct vpu_instance *inst) +{ +struct dec_param pic_param; +struct queue_status_info q_status;drivers/staging/media/wave5/v4l2/vpu_dec.c line 262
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +10
-0+u32 remain_cmd_q, max_cmd_q =0 ; + +memset (&pic_param,0 ,sizeof (struct dec_param )); + +vpu_dec_give_command (inst,DEC_GET_QUEUE_STATUS , &q_status); +DPRINTK (inst->dev,1 ,"min_src_buf_cnt : %d | default : %d | qcount : %d | report_q : %d\n" , + inst->min_src_frame_buf_count,COMMAND_QUEUE_DEPTH , q_status.instance_queue_count, + q_status.report_queue_count); + + max_cmd_q = (inst->min_src_frame_buf_count < COMMAND_QUEUE_DEPTH) ?Indentation issues all over the place :-) Please fix.
Quoted 2,722 lines
drivers/staging/media/wave5/v4l2/vpu_dec.c new file +1131
-0+ inst->min_src_frame_buf_count : COMMAND_QUEUE_DEPTH; + remain_cmd_q = max_cmd_q - q_status.instance_queue_count; + +while (remain_cmd_q) { +enum ret_code ret_code; + + ret_code =vpu_dec_start_one_frame (inst, &pic_param); +if (ret_code !=RETCODE_SUCCESS ) { +if (ret_code !=RETCODE_QUEUEING_FAILURE ) { +struct vb2_v4l2_buffer *src_buf = +v4l2_m2m_src_buf_remove (inst->v4l2_fh.m2m_ctx); + + inst->state =VPU_INST_STATE_STOP ; +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); +break ; + } + }else { +DPRINTK (inst->dev,1 ,"vpu_dec_start_one_frame success %d\n" , ret_code); + } + + remain_cmd_q--; + } +} + +static void vpu_dec_stop_decode (struct vpu_instance *inst) +{ +u32 i; +unsigned long flags; + + inst->state =VPU_INST_STATE_STOP ; + +spin_lock_irqsave (&inst->bitstream_lock, flags); +vpu_dec_update_bitstream_buffer (inst,0 ); +spin_unlock_irqrestore (&inst->bitstream_lock, flags); + +for (i =0 ; i < inst->min_dst_frame_buf_count; i++) { +vpu_dec_clr_disp_flag (inst, i); +DPRINTK (inst->dev,1 ,"clear display flag : %d\n" , i); + } +} + +static void vpu_dec_finish_decode (struct vpu_instance *inst) +{ +struct dec_output_info dec_output_info; +enum ret_code ret_code; +int irq_status; + +if (kfifo_out (&inst->dev->irq_status, &irq_status,sizeof (int ))) +vpu_clear_interrupt_ex (inst, irq_status); + +if (irq_status & (1 <<INT_WAVE5_BSBUF_EMPTY )) { +DPRINTK (inst->dev,1 ,"bitstream EMPTY!!!!\n" ); + inst->state =VPU_INST_STATE_WAIT_BUF ; +handle_src_buffer (inst); +handle_bitstream_buffer (inst); + } + +if (irq_status & (1 <<INT_WAVE5_DEC_PIC )) { + ret_code =vpu_dec_get_output_info (inst, &dec_output_info); +if (ret_code !=RETCODE_SUCCESS ) { +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); + }else { +if (inst->state ==VPU_INST_STATE_STOP ) { +struct queue_status_info q_status; + +if (dec_output_info.index_frame_display >=0 ) +vpu_dec_clr_disp_flag (inst, dec_output_info.index_frame_display); + +vpu_dec_give_command (inst,DEC_GET_QUEUE_STATUS , &q_status); + +if (q_status.report_queue_count + q_status.instance_queue_count ==0 ) +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); + }else if (dec_output_info.index_frame_decoded ==DECODED_IDX_FLAG_NO_FB && + dec_output_info.index_frame_display ==DISPLAY_IDX_FLAG_NO_FB ) { +DPRINTK (inst->dev,1 ,"no more frame buffer\n" ); + inst->state =VPU_INST_STATE_WAIT_BUF ; + }else { +handle_src_buffer (inst); + +if (dec_output_info.index_frame_display >=0 ) { +struct vb2_v4l2_buffer *dst_buf = +v4l2_m2m_dst_buf_remove_by_idx (inst->v4l2_fh.m2m_ctx, + dec_output_info.index_frame_display); +int stride = dec_output_info.disp_frame.stride; +int height = dec_output_info.disp_pic_height; + +if (inst->dst_fmt.num_planes ==1 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , + (stride * height *3 /2 )); + }else if (inst->dst_fmt.num_planes ==2 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , + (stride * height)); +vb2_set_plane_payload (&dst_buf->vb2_buf,1 , + ((stride /2 ) * height)); + }else if (inst->dst_fmt.num_planes ==3 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , + (stride * height)); +vb2_set_plane_payload (&dst_buf->vb2_buf,1 , + ((stride /2 ) * (height /2 ))); +vb2_set_plane_payload (&dst_buf->vb2_buf,2 , + ((stride /2 ) * (height /2 ))); + } + + dst_buf->vb2_buf.timestamp = inst->timestamp; + dst_buf->field =V4L2_FIELD_NONE ; +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_DONE ); + }else if (dec_output_info.index_frame_display ==DISPLAY_IDX_FLAG_SEQ_END ) { +static const struct v4l2_event vpu_event_eos = { + .type =V4L2_EVENT_EOS + }; + +DPRINTK (inst->dev,1 ,"stream end\n" ); + inst->state =VPU_INST_STATE_STOP ; +v4l2_event_queue_fh (&inst->v4l2_fh, &vpu_event_eos); + } + +if (!kfifo_len (&inst->dev->irq_status)) +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, + inst->v4l2_fh.m2m_ctx); + } + } + } +} + +static int vpu_dec_querycap (struct file *file,void *fh,struct v4l2_capability *cap) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"\n" ); + +strscpy (cap->driver,VPU_DEC_DRV_NAME ,sizeof (cap->driver)); +strscpy (cap->card,VPU_DEC_DRV_NAME ,sizeof (cap->card)); +strscpy (cap->bus_info,"platform:" VPU_DEC_DRV_NAME ,sizeof (cap->bus_info)); + +return 0 ; +} + +static int vpu_dec_enum_framesizes (struct file *file,void *fh,struct v4l2_frmsizeenum *fsize) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"\n" ); + +if (fsize->index) +return -EINVAL ; + + vpu_fmt =find_vpu_format (fsize->pixel_format,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + vpu_fmt =find_vpu_format (fsize->pixel_format,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + } + + fsize->type =V4L2_FRMSIZE_TYPE_CONTINUOUS ; + fsize->stepwise.min_width = vpu_fmt->min_width; + fsize->stepwise.max_width = vpu_fmt->max_width; + fsize->stepwise.step_width =1 ; + fsize->stepwise.min_height = vpu_fmt->min_height; + fsize->stepwise.max_height = vpu_fmt->max_height; + fsize->stepwise.step_height =1 ; + +return 0 ; +} + +static int vpu_dec_enum_fmt_cap (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"index : %d\n" , f->index); + + vpu_fmt =find_vpu_format_by_index (f->index,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + +return 0 ; +} + +static int vpu_dec_try_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d colorspace %d field : %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.colorspace, f->fmt.pix_mp.field); + +if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) +return -EINVAL ; + + vpu_fmt =find_vpu_format (f->fmt.pix_mp.pixelformat,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) { + f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; + f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; +update_resolution_info (&f->fmt.pix_mp, inst->dst_fmt.width, inst->dst_fmt.height); + }else { + f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; + f->fmt.pix_mp.num_planes = vpu_fmt->num_planes; +update_resolution_info (&f->fmt.pix_mp,clamp (f->fmt.pix_mp.width, + vpu_fmt->min_width, vpu_fmt->max_width), +clamp (f->fmt.pix_mp.height, vpu_fmt->min_height, + vpu_fmt->max_height)); + } + + f->fmt.pix_mp.flags =0 ; + f->fmt.pix_mp.field =V4L2_FIELD_NONE ; + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; +memset (&f->fmt.pix_mp.reserved,0 ,sizeof (f->fmt.pix_mp.reserved)); + +return 0 ; +} + +static int vpu_dec_s_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i, ret; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d colorspace %d field %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.colorspace, f->fmt.pix_mp.field); + + ret =vpu_dec_try_fmt_cap (file, fh, f); +if (ret) +return ret; + + inst->dst_fmt.width = f->fmt.pix_mp.width; + inst->dst_fmt.height = f->fmt.pix_mp.height; + inst->dst_fmt.pixelformat = f->fmt.pix_mp.pixelformat; + inst->dst_fmt.field = f->fmt.pix_mp.field; + inst->dst_fmt.flags = f->fmt.pix_mp.flags; + inst->dst_fmt.num_planes = f->fmt.pix_mp.num_planes; +for (i =0 ; i < inst->dst_fmt.num_planes; i++) { + inst->dst_fmt.plane_fmt[i].bytesperline = f->fmt.pix_mp.plane_fmt[i].bytesperline; + inst->dst_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; + } + +return 0 ; +} + +static int vpu_dec_g_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i; + +DPRINTK (inst->dev,1 ,"\n" ); + + f->fmt.pix_mp.width = inst->dst_fmt.width; + f->fmt.pix_mp.height = inst->dst_fmt.height; + f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; + f->fmt.pix_mp.field = inst->dst_fmt.field; + f->fmt.pix_mp.flags = inst->dst_fmt.flags; + f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; +for (i =0 ; i < f->fmt.pix_mp.num_planes; i++) { + f->fmt.pix_mp.plane_fmt[i].bytesperline = inst->dst_fmt.plane_fmt[i].bytesperline; + f->fmt.pix_mp.plane_fmt[i].sizeimage = inst->dst_fmt.plane_fmt[i].sizeimage; + } + + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; + +return 0 ; +} + +static int vpu_dec_enum_fmt_out (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"index : %d\n" , f->index); + + vpu_fmt =find_vpu_format_by_index (f->index,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + +return 0 ; +} + +static int vpu_dec_try_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d colorspace %d field %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.colorspace, f->fmt.pix_mp.field); + +if (f->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) +return -EINVAL ; + + vpu_fmt =find_vpu_format (f->fmt.pix_mp.pixelformat,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; + f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; +update_resolution_info (&f->fmt.pix_mp, inst->src_fmt.width, inst->src_fmt.height); + }else { + f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; + f->fmt.pix_mp.num_planes = vpu_fmt->num_planes; +update_resolution_info (&f->fmt.pix_mp,clamp (f->fmt.pix_mp.width, + vpu_fmt->min_width, vpu_fmt->max_width), +clamp (f->fmt.pix_mp.height, vpu_fmt->min_height, + vpu_fmt->max_height)); + } + + f->fmt.pix_mp.flags =0 ; + f->fmt.pix_mp.field =V4L2_FIELD_NONE ; +memset (&f->fmt.pix_mp.reserved,0 ,sizeof (f->fmt.pix_mp.reserved)); + +return 0 ; +} + +static int vpu_dec_s_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i, ret; + +DPRINTK (inst->dev,1 ,"pixelformat %d width %d height %d num_planes %d field : %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + + ret =vpu_dec_try_fmt_out (file, fh, f); +if (ret) +return ret; + + inst->src_fmt.width = f->fmt.pix_mp.width; + inst->src_fmt.height = f->fmt.pix_mp.height; + inst->src_fmt.pixelformat = f->fmt.pix_mp.pixelformat; + inst->src_fmt.field = f->fmt.pix_mp.field; + inst->src_fmt.flags = f->fmt.pix_mp.flags; + inst->src_fmt.num_planes = f->fmt.pix_mp.num_planes; +for (i =0 ; i < inst->src_fmt.num_planes; i++) { + inst->src_fmt.plane_fmt[i].bytesperline = f->fmt.pix_mp.plane_fmt[i].bytesperline; + inst->src_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; + } + + inst->colorspace = f->fmt.pix_mp.colorspace; + inst->ycbcr_enc = f->fmt.pix_mp.ycbcr_enc; + inst->hsv_enc = f->fmt.pix_mp.hsv_enc; + inst->quantization = f->fmt.pix_mp.quantization; + inst->xfer_func = f->fmt.pix_mp.xfer_func; + +update_resolution_info (&inst->dst_fmt, f->fmt.pix_mp.width, f->fmt.pix_mp.height); + +return 0 ; +} + +static int vpu_dec_g_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i; + +DPRINTK (inst->dev,1 ,"\n" ); + + f->fmt.pix_mp.width = inst->src_fmt.width; + f->fmt.pix_mp.height = inst->src_fmt.height; + f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; + f->fmt.pix_mp.field = inst->src_fmt.field; + f->fmt.pix_mp.flags = inst->src_fmt.flags; + f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; +for (i =0 ; i < f->fmt.pix_mp.num_planes; i++) { + f->fmt.pix_mp.plane_fmt[i].bytesperline = inst->src_fmt.plane_fmt[i].bytesperline; + f->fmt.pix_mp.plane_fmt[i].sizeimage = inst->src_fmt.plane_fmt[i].sizeimage; + } + + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; + +return 0 ; +} + +static int vpu_dec_g_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | target : %d\n" , s->type, s->target); + +if (s->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE ) { +switch (s->target) { +case V4L2_SEL_TGT_COMPOSE_BOUNDS : +case V4L2_SEL_TGT_COMPOSE_PADDED : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->dst_fmt.width; + s->r.height = inst->dst_fmt.height; +break ; +case V4L2_SEL_TGT_COMPOSE : +case V4L2_SEL_TGT_COMPOSE_DEFAULT : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->src_fmt.width; + s->r.height = inst->src_fmt.height; +break ; +default : +return -EINVAL ; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_dec_s_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | target : %d\n" , s->type, s->target); + +if (s->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE ) { +switch (s->target) { +case V4L2_SEL_TGT_COMPOSE : +DPRINTK (inst->dev,1 ,"V4L2_SEL_TGT_COMPOSE width : %d | height : %d\n" , + s->r.width, s->r.height); + inst->dst_fmt.width = s->r.width; + inst->dst_fmt.height = s->r.height; +break ; +default : +return -EINVAL ; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_dec_try_decoder_cmd (struct file *file,void *fh,struct v4l2_decoder_cmd *dc) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"decoder command : %d\n" , dc->cmd); + +if (dc->cmd !=V4L2_DEC_CMD_STOP && dc->cmd !=V4L2_DEC_CMD_START ) +return -EINVAL ; + + dc->flags =0 ; + +if (dc->cmd ==V4L2_DEC_CMD_STOP ) { + dc->stop.pts =0 ; + }else if (dc->cmd ==V4L2_DEC_CMD_START ) { + dc->start.speed =0 ; + dc->start.format =V4L2_DEC_START_FMT_NONE ; + } + +return 0 ; +} + +static int vpu_dec_decoder_cmd (struct file *file,void *fh,struct v4l2_decoder_cmd *dc) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int ret; + +DPRINTK (inst->dev,1 ,"decoder command : %d\n" , dc->cmd); + + ret =vpu_dec_try_decoder_cmd (file, fh, dc); +if (ret <0 ) +return ret; + +if (!vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE )) || + !vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ))) +return 0 ; + +switch (dc->cmd) { +case V4L2_DEC_CMD_STOP : +vpu_dec_stop_decode (inst); +break ; +case V4L2_DEC_CMD_START : +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_dec_subscribe_event (struct v4l2_fh *fh,const struct v4l2_event_subscription *sub) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | id : %d | flags : %d\n" , sub->type, sub->id, sub->flags); + +switch (sub->type) { +case V4L2_EVENT_EOS : +return v4l2_event_subscribe (fh, sub,0 ,NULL ); +case V4L2_EVENT_SOURCE_CHANGE : +return v4l2_src_change_event_subscribe (fh, sub); +case V4L2_EVENT_CTRL : +return v4l2_ctrl_subscribe_event (fh, sub); +default : +return -EINVAL ; + } +} + +static const struct v4l2_ioctl_ops vpu_dec_ioctl_ops = { + .vidioc_querycap = vpu_dec_querycap, + .vidioc_enum_framesizes = vpu_dec_enum_framesizes, + + .vidioc_enum_fmt_vid_cap = vpu_dec_enum_fmt_cap, + .vidioc_s_fmt_vid_cap_mplane = vpu_dec_s_fmt_cap, + .vidioc_g_fmt_vid_cap_mplane = vpu_dec_g_fmt_cap, + .vidioc_try_fmt_vid_cap_mplane = vpu_dec_try_fmt_cap, + + .vidioc_enum_fmt_vid_out = vpu_dec_enum_fmt_out, + .vidioc_s_fmt_vid_out_mplane = vpu_dec_s_fmt_out, + .vidioc_g_fmt_vid_out_mplane = vpu_dec_g_fmt_out, + .vidioc_try_fmt_vid_out_mplane = vpu_dec_try_fmt_out, + + .vidioc_g_selection = vpu_dec_g_selection, + .vidioc_s_selection = vpu_dec_s_selection, + + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, + .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, + .vidioc_streamon = v4l2_m2m_ioctl_streamon, + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, + + .vidioc_try_decoder_cmd = vpu_dec_try_decoder_cmd, + .vidioc_decoder_cmd = vpu_dec_decoder_cmd, + + .vidioc_subscribe_event = vpu_dec_subscribe_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, +}; + +static int vpu_dec_g_volatile_ctrl (struct v4l2_ctrl *ctrl) +{ +struct vpu_instance *inst =ctrl_to_vpu_inst (ctrl); + +DPRINTK (inst->dev,1 ,"name : %s\n" , ctrl->name); + +switch (ctrl->id) { +case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE : +if (inst->state !=VPU_INST_STATE_NONE && inst->state !=VPU_INST_STATE_OPEN ) + ctrl->val = inst->min_dst_frame_buf_count; +break ; +default : +return -EINVAL ; + } + +DPRINTK (inst->dev,1 ,"value : %d\n" , ctrl->val); + +return 0 ; +} + +static int vpu_dec_s_ctrl (struct v4l2_ctrl *ctrl) +{ +struct vpu_instance *inst =ctrl_to_vpu_inst (ctrl); + +DPRINTK (inst->dev,1 ,"name : %s | value : %d\n" , ctrl->name, ctrl->val); + +switch (ctrl->id) { +case V4L2_CID_VPU_THUMBNAIL_MODE : + inst->thumbnail_mode = ctrl->val; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct v4l2_ctrl_ops vpu_dec_ctrl_ops = { + .g_volatile_ctrl = vpu_dec_g_volatile_ctrl, + .s_ctrl = vpu_dec_s_ctrl, +}; + +static const struct v4l2_ctrl_config vpu_thumbnail_mode = { + .ops = &vpu_dec_ctrl_ops, + .id =V4L2_CID_VPU_THUMBNAIL_MODE , + .name ="thumbnail mode" , + .type =V4L2_CTRL_TYPE_BOOLEAN , + .def =0 , + .min =0 , + .max =1 , + .step =1 , + .flags =V4L2_CTRL_FLAG_WRITE_ONLY , +}; + +static void set_default_dec_openparam (struct dec_open_param *open_param) +{ + open_param->bitstream_mode =BS_MODE_INTERRUPT ; + open_param->stream_endian =VPU_STREAM_ENDIAN ; + open_param->frame_endian =VPU_FRAME_ENDIAN ; + open_param->cbcr_interleave = FALSE; + open_param->nv21 = FALSE; +} + +static int vpu_dec_queue_setup (struct vb2_queue *q,unsigned int *num_buffers, +unsigned int *num_planes,unsigned int sizes[], +struct device *alloc_devs[]) +{ +struct vpu_instance *inst =vb2_get_drv_priv (q); +struct v4l2_pix_format_mplane inst_format = + (q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) ? inst->src_fmt : inst->dst_fmt; +unsigned int i; + +DPRINTK (inst->dev,1 ,"num_buffers : %d | num_planes : %d | type : %d\n" , *num_buffers, + *num_planes, q->type); + +if (*num_planes) { +if (inst_format.num_planes != *num_planes) +return -EINVAL ; + +for (i =0 ; i < *num_planes; i++) { +if (sizes[i] < inst_format.plane_fmt[i].sizeimage) +return -EINVAL ; + } + }else { + *num_planes = inst_format.num_planes; + +if (*num_planes ==1 ) { + sizes[0 ] = inst_format.width * inst_format.height *3 /2 ; +if (q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) + sizes[0 ] = inst_format.plane_fmt[0 ].sizeimage; +DPRINTK (inst->dev,1 ,"size[0] : %d\n" , sizes[0 ]); + }else if (*num_planes ==2 ) { + sizes[0 ] = inst_format.width * inst_format.height; + sizes[1 ] = inst_format.width * inst_format.height /2 ; +DPRINTK (inst->dev,1 ,"size[0] : %d | size[1] : %d\n" , sizes[0 ], sizes[1 ]); + }else if (*num_planes ==3 ) { + sizes[0 ] = inst_format.width * inst_format.height; + sizes[1 ] = inst_format.width * inst_format.height /4 ; + sizes[2 ] = inst_format.width * inst_format.height /4 ; +DPRINTK (inst->dev,1 ,"size[0] : %d | size[1] : %d | size[2] : %d\n" , + sizes[0 ], sizes[1 ], sizes[2 ]); + } + } + +if (inst->state ==VPU_INST_STATE_NONE && q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { +enum ret_code ret_code; +struct dec_open_param open_param; + +memset (&open_param,0 ,sizeof (struct dec_open_param )); +set_default_dec_openparam (&open_param); + + inst->bitstream_vbuf.size =ALIGN (inst->src_fmt.plane_fmt[0 ].sizeimage,1024 ) *4 ; +if (vdi_allocate_dma_memory (inst->dev, &inst->bitstream_vbuf) <0 ) +DPRINTK (inst->dev,1 ,"alloc bitstream fail: %zu\n" , inst->bitstream_vbuf.size); + + inst->std =to_vpu_codstd (inst->src_fmt.pixelformat); +if (inst->std ==STD_UNKNOWN ) { +dev_warn (inst->dev->dev,"unsupported pixelformat: %.4s\n" , + (char *)&inst->src_fmt.pixelformat); +return -EINVAL ; + } + open_param.bitstream_buffer = inst->bitstream_vbuf.daddr; + open_param.bitstream_buffer_size = inst->bitstream_vbuf.size; + + ret_code =vpu_dec_open_api (inst, &open_param); +if (ret_code !=RETCODE_SUCCESS ) { +DPRINTK (inst->dev,1 ,"failed to call vpu_dec_open_api() : %d\n" , ret_code); +return -EINVAL ; + } + + inst->state =VPU_INST_STATE_OPEN ; + +//vpu_dec_give_command(inst, ENABLE_LOGGING, 0); + +if (inst->thumbnail_mode) +vpu_dec_give_command (inst,ENABLE_DEC_THUMBNAIL_MODE ,0 ); + + inst->min_src_frame_buf_count = *num_buffers; + } + +if (inst->state !=VPU_INST_STATE_NONE && inst->state !=VPU_INST_STATE_OPEN && q->type == +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { + *num_buffers = inst->min_dst_frame_buf_count; + +if (inst->state ==VPU_INST_STATE_INIT_SEQ ) { +s32 non_linear_num = inst->min_dst_frame_buf_count; +s32 fb_stride, fb_height; +s32 luma_size, chroma_size; + +for (i =0 ; i < non_linear_num; i++) { + fb_stride = inst->dst_fmt.width; + fb_height =ALIGN (inst->dst_fmt.height,32 ); + luma_size = fb_stride * fb_height; + chroma_size =ALIGN (fb_stride /2 ,16 ) * fb_height; + + inst->frame_vbuf[i].size = luma_size + chroma_size; +if (vdi_allocate_dma_memory (inst->dev, &inst->frame_vbuf[i]) <0 ) +DPRINTK (inst->dev,1 ,"failed to alloc FBC buffer : %zu\n" , + inst->frame_vbuf[i].size); + + inst->frame_buf[i].buf_y = inst->frame_vbuf[i].daddr; + inst->frame_buf[i].buf_cb = inst->frame_vbuf[i].daddr + luma_size; + inst->frame_buf[i].buf_cr = (dma_addr_t)-1 ; + inst->frame_buf[i].size = inst->frame_vbuf[i].size; + inst->frame_buf[i].width = inst->src_fmt.width; + inst->frame_buf[i].stride = fb_stride; + inst->frame_buf[i].map_type =COMPRESSED_FRAME_MAP ; + inst->frame_buf[i].update_fb_info = TRUE; + } + } + } + +return 0 ; +} + +static int vpu_dec_buf_init (struct vb2_buffer *vb) +{ +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); + +DPRINTK (inst->dev,1 ,"type : %4d index %4d size[0] %4ld size[1] %4ld size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); +return 0 ; +} + +static int vpu_dec_buf_prepare (struct vb2_buffer *vb) +{ +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); + +DPRINTK (inst->dev,1 ,"type : %4d index %4d size[0] %4ld size[1] %4ld size[2] %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); + +return 0 ; +} + +static void vpu_dec_buf_queue (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vpu_buffer *vpu_buf =to_vpu_buf (vbuf); + +DPRINTK (inst->dev,1 ,"type %4d index %4d size[0] %4ld size[1] : %4ld | size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); + +v4l2_m2m_buf_queue (inst->v4l2_fh.m2m_ctx, vbuf); + +if (vb->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { + vpu_buf->consumed = FALSE; +handle_bitstream_buffer (inst); + vbuf->sequence = inst->queued_src_buf_num++; + } + +if (vb->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { +if (inst->state ==VPU_INST_STATE_INIT_SEQ ) { +dma_addr_t buf_addr_y =0 , buf_addr_cb =0 , buf_addr_cr =0 ; +s32 buf_size =0 ; +s32 non_linear_num = inst->min_dst_frame_buf_count; +s32 fb_stride = inst->dst_fmt.width; +s32 luma_size = fb_stride * inst->dst_fmt.height; +s32 chroma_size = (fb_stride /2 ) * (inst->dst_fmt.height /2 ); + +if (inst->dst_fmt.num_planes ==1 ) { + buf_size =vb2_plane_size (&vbuf->vb2_buf,0 ); + buf_addr_y =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,0 ); + buf_addr_cb = buf_addr_y + luma_size; + buf_addr_cr = buf_addr_cb + chroma_size; + }else if (inst->dst_fmt.num_planes ==2 ) { + buf_size =vb2_plane_size (&vbuf->vb2_buf,0 ) + +vb2_plane_size (&vbuf->vb2_buf,1 ); + buf_addr_y =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,0 ); + buf_addr_cb =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,1 ); + buf_addr_cr = buf_addr_cb + chroma_size; + }else if (inst->dst_fmt.num_planes ==3 ) { + buf_size =vb2_plane_size (&vbuf->vb2_buf,0 ) + +vb2_plane_size (&vbuf->vb2_buf,1 ) + +vb2_plane_size (&vbuf->vb2_buf,2 ); + buf_addr_y =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,0 ); + buf_addr_cb =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,1 ); + buf_addr_cr =vb2_dma_contig_plane_dma_addr (&vbuf->vb2_buf,2 ); + } + inst->frame_buf[vb->index + non_linear_num].buf_y = buf_addr_y; + inst->frame_buf[vb->index + non_linear_num].buf_cb = buf_addr_cb; + inst->frame_buf[vb->index + non_linear_num].buf_cr = buf_addr_cr; + inst->frame_buf[vb->index + non_linear_num].size = buf_size; + inst->frame_buf[vb->index + non_linear_num].width = inst->src_fmt.width; + inst->frame_buf[vb->index + non_linear_num].stride = fb_stride; + inst->frame_buf[vb->index + non_linear_num].map_type =LINEAR_FRAME_MAP ; + inst->frame_buf[vb->index + non_linear_num].update_fb_info = TRUE; + } + +if (inst->state ==VPU_INST_STATE_PIC_RUN || inst->state ==VPU_INST_STATE_STOP || + inst->state ==VPU_INST_STATE_WAIT_BUF ) { +vpu_dec_clr_disp_flag (inst, vb->index); +if (inst->state ==VPU_INST_STATE_WAIT_BUF ) + inst->state =VPU_INST_STATE_PIC_RUN ; + } + vbuf->sequence = inst->queued_dst_buf_num++; + } +} + +static void vpu_dec_buf_finish (struct vb2_buffer *vb) +{ +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); + +DPRINTK (inst->dev,1 ,"type %4d index : %4d size[0] %4ld size[1] %4ld | size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); +} + +static void vpu_dec_buf_cleanup (struct vb2_buffer *vb) +{ +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); + +DPRINTK (inst->dev,1 ,"type %4d index %4d size[0] %4ld size[1] : %4ld | size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); +} + +static int vpu_dec_start_streaming (struct vb2_queue *q,unsigned int count) +{ +struct vpu_instance *inst =vb2_get_drv_priv (q); + +DPRINTK (inst->dev,1 ,"type : %d\n" , q->type); + +if (inst->state ==VPU_INST_STATE_OPEN ) { +struct dec_initial_info initial_info; +enum ret_code ret_code; + + ret_code =vpu_dec_issue_seq_init (inst); +if (ret_code !=RETCODE_SUCCESS ) +DPRINTK (inst->dev,1 ,"failed vpu_dec_issue_seq_init() : %d\n" , ret_code); + +if (vpu_wait_interrupt (inst,VPU_DEC_TIMEOUT ) <0 ) +DPRINTK (inst->dev,1 ,"failed to call vpu_wait_interrupt()\n" ); + + ret_code =vpu_dec_complete_seq_init (inst, &initial_info); +if (ret_code !=RETCODE_SUCCESS ) { +DPRINTK (inst->dev,1 ,"vpu_dec_complete_seq_init: %d, reason : %d\n" , + ret_code, initial_info.seq_init_err_reason); + }else { +static const struct v4l2_event vpu_event_src_ch = { + .type =V4L2_EVENT_SOURCE_CHANGE , + .u.src_change.changes =V4L2_EVENT_SRC_CH_RESOLUTION , + }; + +DPRINTK (inst->dev,1 ,"width %d height %d profile %d | minbuffer : %d\n" , + initial_info.pic_width, initial_info.pic_height, + initial_info.profile, initial_info.min_frame_buffer_count); + + inst->state =VPU_INST_STATE_INIT_SEQ ; + inst->min_dst_frame_buf_count = initial_info.min_frame_buffer_count +1 ; + +if (initial_info.pic_width != inst->src_fmt.width || + initial_info.pic_height != inst->src_fmt.height) { +update_resolution_info (&inst->src_fmt, initial_info.pic_width, + initial_info.pic_height); +update_resolution_info (&inst->dst_fmt, initial_info.pic_width, + initial_info.pic_height); + } + +v4l2_event_queue_fh (&inst->v4l2_fh, &vpu_event_src_ch); + } + } + +if (inst->state ==VPU_INST_STATE_INIT_SEQ && q->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { +enum ret_code ret_code; +s32 non_linear_num = inst->min_dst_frame_buf_count; +s32 linear_num = inst->min_dst_frame_buf_count; +s32 fb_stride = inst->dst_fmt.width; + +DPRINTK (inst->dev,1 ,"fb_stride %d | inst->dst_fmt.height %d\n" , fb_stride, inst->dst_fmt.height); + ret_code =vpu_dec_register_frame_buffer_ex (inst, non_linear_num, linear_num, + fb_stride, inst->dst_fmt.height,COMPRESSED_FRAME_MAP ); +if (ret_code !=RETCODE_SUCCESS ) +DPRINTK (inst->dev,1 ,"fail vpu_dec_register_frame_buffer_ex %d" , ret_code); + + inst->state =VPU_INST_STATE_PIC_RUN ; + } + +return 0 ; +} + +static void vpu_dec_stop_streaming (struct vb2_queue *q) +{ +struct vpu_instance *inst =vb2_get_drv_priv (q); +struct vb2_v4l2_buffer *buf; + +DPRINTK (inst->dev,1 ,"type : %d\n" , q->type); + +if (vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE )) && +vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ))) + inst->state =VPU_INST_STATE_STOP ; + +if (q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { +while ((buf =v4l2_m2m_src_buf_remove (inst->v4l2_fh.m2m_ctx))) { +DPRINTK (inst->dev,1 ,"buf type : %4d | index : %4d\n" , buf->vb2_buf.type, + buf->vb2_buf.index); +v4l2_m2m_buf_done (buf,VB2_BUF_STATE_ERROR ); + } + }else { +while ((buf =v4l2_m2m_dst_buf_remove (inst->v4l2_fh.m2m_ctx))) { +u32 plane =0 ; + +DPRINTK (inst->dev,1 ,"buf type : %4d | index : %4d\n" , buf->vb2_buf.type, + buf->vb2_buf.index); + +for (plane =0 ; plane < inst->dst_fmt.num_planes; plane++) +vb2_set_plane_payload (&buf->vb2_buf, plane,0 ); + +v4l2_m2m_buf_done (buf,VB2_BUF_STATE_ERROR ); + } + } +} + +static const struct vb2_ops vpu_dec_vb2_ops = { + .queue_setup = vpu_dec_queue_setup, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .buf_init = vpu_dec_buf_init, + .buf_prepare = vpu_dec_buf_prepare, + .buf_queue = vpu_dec_buf_queue, + .buf_finish = vpu_dec_buf_finish, + .buf_cleanup = vpu_dec_buf_cleanup, + .start_streaming = vpu_dec_start_streaming, + .stop_streaming = vpu_dec_stop_streaming, +}; + +static void set_default_format (struct v4l2_pix_format_mplane *src_fmt, +struct v4l2_pix_format_mplane *dst_fmt) +{ + src_fmt->pixelformat = vpu_dec_fmt_list[VPU_FMT_TYPE_CODEC ][0 ].v4l2_pix_fmt; + src_fmt->field =V4L2_FIELD_NONE ; + src_fmt->flags =0 ; + src_fmt->num_planes = vpu_dec_fmt_list[VPU_FMT_TYPE_CODEC ][0 ].num_planes; +update_resolution_info (src_fmt,720 ,480 ); + + dst_fmt->pixelformat = vpu_dec_fmt_list[VPU_FMT_TYPE_RAW ][0 ].v4l2_pix_fmt; + dst_fmt->field =V4L2_FIELD_NONE ; + dst_fmt->flags =0 ; + dst_fmt->num_planes = vpu_dec_fmt_list[VPU_FMT_TYPE_RAW ][0 ].num_planes; +update_resolution_info (dst_fmt,736 ,480 ); +} + +static int vpu_dec_queue_init (void *priv,struct vb2_queue *src_vq,struct vb2_queue *dst_vq) +{ +struct vpu_instance *inst = priv; +struct vpu_platform_data *pdata =dev_get_platdata (inst->dev->v4l2_dev.dev); +int ret; + +DPRINTK (inst->dev,1 ,"\n" ); + + src_vq->type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ; + src_vq->io_modes =VB2_MMAP |VB2_USERPTR |VB2_DMABUF ; +if (pdata && pdata->mem_ops) + src_vq->mem_ops = pdata->mem_ops; +else + src_vq->mem_ops = &vb2_dma_contig_memops; + src_vq->ops = &vpu_dec_vb2_ops; + src_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + src_vq->buf_struct_size =sizeof (struct vpu_buffer ); + src_vq->allow_zero_bytesused =1 ; + src_vq->min_buffers_needed =0 ; + src_vq->drv_priv = inst; + src_vq->lock = &inst->dev->dev_lock; + src_vq->dev = inst->dev->v4l2_dev.dev; + ret =vb2_queue_init (src_vq); +if (ret) +return ret; + + dst_vq->type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ; + dst_vq->io_modes =VB2_MMAP |VB2_USERPTR |VB2_DMABUF ; +if (pdata && pdata->mem_ops) + dst_vq->mem_ops = pdata->mem_ops; +else + dst_vq->mem_ops = &vb2_dma_contig_memops; + dst_vq->ops = &vpu_dec_vb2_ops; + dst_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + dst_vq->buf_struct_size =sizeof (struct vpu_buffer ); + dst_vq->allow_zero_bytesused =1 ; + dst_vq->min_buffers_needed =0 ; + dst_vq->drv_priv = inst; + dst_vq->lock = &inst->dev->dev_lock; + dst_vq->dev = inst->dev->v4l2_dev.dev; + ret =vb2_queue_init (dst_vq); +if (ret) +return ret; + +return 0 ; +} + +static const struct vpu_instance_ops vpu_dec_inst_ops = { + .start_process = vpu_dec_start_decode, + .stop_process = vpu_dec_stop_decode, + .finish_process = vpu_dec_finish_decode, +}; + +static int vpu_dec_open (struct file *filp) +{ +struct video_device *vdev =video_devdata (filp); +struct vpu_device *dev =video_drvdata (filp); +struct vpu_instance *inst =NULL ; +struct v4l2_ctrl *ctrl; + + inst =kzalloc (sizeof (*inst),GFP_KERNEL ); +if (!inst) +return -ENOMEM ; + + inst->dev = dev; + inst->type =VPU_INST_TYPE_DEC ; + inst->ops = &vpu_dec_inst_ops; + +spin_lock_init (&inst->bitstream_lock); + +v4l2_fh_init (&inst->v4l2_fh, vdev); + filp->private_data = &inst->v4l2_fh; +v4l2_fh_add (&inst->v4l2_fh); + + inst->v4l2_fh.m2m_ctx =v4l2_m2m_ctx_init (dev->v4l2_m2m_dev, inst, vpu_dec_queue_init); +if (IS_ERR (inst->v4l2_fh.m2m_ctx)) +return -ENODEV ; + +v4l2_ctrl_handler_init (&inst->v4l2_ctrl_hdl,10 ); +v4l2_ctrl_new_custom (&inst->v4l2_ctrl_hdl, &vpu_thumbnail_mode,NULL ); + ctrl =v4l2_ctrl_new_std (&inst->v4l2_ctrl_hdl, &vpu_dec_ctrl_ops, +V4L2_CID_MIN_BUFFERS_FOR_CAPTURE ,1 ,32 ,1 ,1 ); +if (ctrl) + ctrl->flags |=V4L2_CTRL_FLAG_VOLATILE ; + +if (inst->v4l2_ctrl_hdl.error) +return -ENODEV ; + + inst->v4l2_fh.ctrl_handler = &inst->v4l2_ctrl_hdl; +v4l2_ctrl_handler_setup (&inst->v4l2_ctrl_hdl); + +set_default_format (&inst->src_fmt, &inst->dst_fmt); + inst->colorspace =V4L2_COLORSPACE_REC709 ; + inst->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; + inst->hsv_enc =0 ; + inst->quantization =V4L2_QUANTIZATION_DEFAULT ; + inst->xfer_func =V4L2_XFER_FUNC_DEFAULT ; + +return 0 ; +} + +static int vpu_dec_release (struct file *filp) +{ +int i; +struct vpu_instance *inst =to_vpu_inst (filp->private_data); +unsigned int loop_count =0 ; + +v4l2_m2m_ctx_release (inst->v4l2_fh.m2m_ctx); +if (inst->state !=VPU_INST_STATE_NONE ) { +while (vpu_dec_close (inst) ==RETCODE_VPU_STILL_RUNNING ) { +if (vpu_wait_interrupt (inst,VPU_DEC_TIMEOUT ) <0 ) { +DPRINTK (inst->dev,1 ,"failed to call vpu_wait_interrupt()\n" ); +if (loop_count <10 ) { + loop_count++; +continue ; + }else { +DPRINTK (inst->dev,1 ,"failed to call vpu_dec_close()\n" ); +break ; + } + }else { +break ; + } + } + } +for (i =0 ; i < inst->min_dst_frame_buf_count; i++) { +if (inst->frame_vbuf[i].size !=0 ) +vdi_free_dma_memory (inst->dev, &inst->frame_vbuf[i]); + } +if (inst->bitstream_vbuf.size !=0 ) +vdi_free_dma_memory (inst->dev, &inst->bitstream_vbuf); +v4l2_ctrl_handler_free (&inst->v4l2_ctrl_hdl); +v4l2_fh_del (&inst->v4l2_fh); +v4l2_fh_exit (&inst->v4l2_fh); +kfree (inst); + +return 0 ; +} + +static const struct v4l2_file_operations vpu_dec_fops = { + .owner =THIS_MODULE , + .open = vpu_dec_open, + .release = vpu_dec_release, + .unlocked_ioctl = video_ioctl2, + .poll = v4l2_m2m_fop_poll, + .mmap = v4l2_m2m_fop_mmap, +}; + +int vpu_dec_register_device (struct vpu_device *dev) +{ +struct video_device *vdev_dec; + + vdev_dec =devm_kzalloc (dev->v4l2_dev.dev,sizeof (*vdev_dec),GFP_KERNEL ); +if (!vdev_dec) +return -ENOMEM ; + + dev->video_dev_dec = vdev_dec; + +strscpy (vdev_dec->name,VPU_DEC_DEV_NAME ,sizeof (vdev_dec->name)); + vdev_dec->fops = &vpu_dec_fops; + vdev_dec->ioctl_ops = &vpu_dec_ioctl_ops; + vdev_dec->release = video_device_release_empty; + vdev_dec->v4l2_dev = &dev->v4l2_dev; + vdev_dec->vfl_dir =VFL_DIR_M2M ; + vdev_dec->device_caps =V4L2_CAP_VIDEO_M2M_MPLANE |V4L2_CAP_STREAMING ; + vdev_dec->lock = &dev->dev_lock; + +if (video_register_device (vdev_dec,VFL_TYPE_VIDEO ,-1 )) +return -1 ; + +video_set_drvdata (vdev_dec, dev); + +return 0 ; +} + +void vpu_dec_unregister_device (struct vpu_device *dev) +{ +video_unregister_device (dev->video_dev_dec); +} +drivers/staging/media/wave5/v4l2/vpu_dec.h new file +20
-0@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* +* Wave5 series multi-standard codec IP - decoder interface +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#ifndef __VPU_DEC_DRV_H__ +#define __VPU_DEC_DRV_H__ + +#include "vpu.h" + +#define VPU_DEC_DEV_NAME "C&M VPU decoder" +#define VPU_DEC_DRV_NAME "vpu-dec" + +#define V4L2_CID_VPU_THUMBNAIL_MODE (V4L2_CID_USER_BASE + 0x1001) + +int vpu_dec_register_device (struct vpu_device *dev); +void vpu_dec_unregister_device (struct vpu_device *dev); +#endif +drivers/staging/media/wave5/v4l2/vpu_enc.c new file +1559
-0@@ -0,0 +1,1580 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* +* Wave5 series multi-standard codec IP - encoder interface +* +* Copyright (C) 2021 CHIPS&MEDIA INC +*/ +#include "vpu_enc.h" + +static const struct vpu_format vpu_enc_fmt_list[2 ][6 ] = { + [VPU_FMT_TYPE_CODEC ] = { + { + .v4l2_pix_fmt =V4L2_PIX_FMT_HEVC , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_H264 , + .num_planes =1 , + .max_width =8192 , + .min_width =32 , + .max_height =8192 , + .min_height =32 , + }, + }, + [VPU_FMT_TYPE_RAW ] = { + { + .v4l2_pix_fmt =V4L2_PIX_FMT_YUV420 , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV12 , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV21 , + .num_planes =1 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_YUV420M , + .num_planes =3 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV12M , + .num_planes =2 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV21M , + .num_planes =2 , + .max_width =8192 , + .min_width =8 , + .max_height =8192 , + .min_height =8 , + }, + } +}; + +static enum cod_std to_vpu_codstd (unsigned int v4l2_pix_fmt) +{ +switch (v4l2_pix_fmt) { +case V4L2_PIX_FMT_H264 : +return W_AVC_ENC ; +case V4L2_PIX_FMT_HEVC : +return W_HEVC_ENC ; +default : +return STD_UNKNOWN ; + } +} + +static const struct vpu_format *find_vpu_format (unsigned int v4l2_pix_fmt,enum vpu_format_type type) +{ +unsigned int index; + +for (index =0 ; index <ARRAY_SIZE (vpu_enc_fmt_list[type]); index++) { +if (vpu_enc_fmt_list[type][index].v4l2_pix_fmt == v4l2_pix_fmt) +return &vpu_enc_fmt_list[type][index]; + } + +return NULL ; +} + +static const struct vpu_format *find_vpu_format_by_index (unsigned int index,enum vpu_format_type type) +{ +if (index >=ARRAY_SIZE (vpu_enc_fmt_list[type])) +return NULL ; + +if (vpu_enc_fmt_list[type][index].v4l2_pix_fmt ==0 ) +return NULL ; + +return &vpu_enc_fmt_list[type][index]; +} + +static struct vb2_v4l2_buffer *get_valid_src_buf (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *vb2_v4l2_buf =NULL ; +struct v4l2_m2m_buffer *v4l2_m2m_buf =NULL ; +struct vpu_buffer *vpu_buf =NULL ; +bool no_src_buf = TRUE; + +v4l2_m2m_for_each_src_buf (inst->v4l2_fh.m2m_ctx, v4l2_m2m_buf) { + vb2_v4l2_buf = &v4l2_m2m_buf->vb; + vpu_buf =to_vpu_buf (vb2_v4l2_buf); + +if (!vpu_buf->consumed) { +DPRINTK (inst->dev,1 ,"no consumed src idx : %d\n" , + vb2_v4l2_buf->vb2_buf.index); + no_src_buf = FALSE; +break ; + } + } + +if (no_src_buf) + vb2_v4l2_buf =NULL ; + +return vb2_v4l2_buf; +} + +static struct vb2_v4l2_buffer *get_valid_dst_buf (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *vb2_v4l2_buf =NULL ; +struct v4l2_m2m_buffer *v4l2_m2m_buf =NULL ; +struct vpu_buffer *vpu_buf =NULL ; +bool no_dst_buf = TRUE; + +v4l2_m2m_for_each_dst_buf (inst->v4l2_fh.m2m_ctx, v4l2_m2m_buf) { + vb2_v4l2_buf = &v4l2_m2m_buf->vb; + vpu_buf =to_vpu_buf (vb2_v4l2_buf); + +if (!vpu_buf->consumed) { +DPRINTK (inst->dev,1 ,"no consumed dst idx : %d\n" , + vb2_v4l2_buf->vb2_buf.index); + no_dst_buf = FALSE; +break ; + } + } + +if (no_dst_buf) + vb2_v4l2_buf =NULL ; + +return vb2_v4l2_buf; +} + +static void update_resolution_info (struct v4l2_pix_format_mplane *pix_mp,unsigned int width, +unsigned int height) +{ +switch (pix_mp->pixelformat) { +case V4L2_PIX_FMT_YUV420 : +case V4L2_PIX_FMT_NV12 : +case V4L2_PIX_FMT_NV21 : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage =round_up (width,32 ) * height *3 /2 ; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); +break ; +case V4L2_PIX_FMT_YUV420M : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage =round_up (width,32 ) * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); + pix_mp->plane_fmt[1 ].bytesperline =round_up (width,32 ) /2 ; + pix_mp->plane_fmt[1 ].sizeimage =round_up (width,32 ) * height /4 ; +memset (&pix_mp->plane_fmt[1 ].reserved,0 ,sizeof (pix_mp->plane_fmt[1 ].reserved)); + pix_mp->plane_fmt[2 ].bytesperline =round_up (width,32 ) /2 ; + pix_mp->plane_fmt[2 ].sizeimage =round_up (width,32 ) * height /4 ; +memset (&pix_mp->plane_fmt[2 ].reserved,0 ,sizeof (pix_mp->plane_fmt[2 ].reserved)); +break ; +case V4L2_PIX_FMT_NV12M : +case V4L2_PIX_FMT_NV21M : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[0 ].sizeimage =round_up (width,32 ) * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); + pix_mp->plane_fmt[1 ].bytesperline =round_up (width,32 ); + pix_mp->plane_fmt[1 ].sizeimage =round_up (width,32 ) * height /2 ; +memset (&pix_mp->plane_fmt[1 ].reserved,0 ,sizeof (pix_mp->plane_fmt[1 ].reserved)); +break ; +default : + pix_mp->width =round_up (width,32 ); + pix_mp->height = height; + pix_mp->plane_fmt[0 ].bytesperline =0 ; + pix_mp->plane_fmt[0 ].sizeimage =round_up (width,32 ) * height; +memset (&pix_mp->plane_fmt[0 ].reserved,0 ,sizeof (pix_mp->plane_fmt[0 ].reserved)); +break ; + } +} + +static void vpu_enc_start_encode (struct vpu_instance *inst) +{ +enum ret_code ret_code; +struct queue_status_info q_status; +u32 remain_cmd_q, max_cmd_q =0 ; + +vpu_enc_give_command (inst,ENC_GET_QUEUE_STATUS , &q_status); +DPRINTK (inst->dev,1 ,"min_src_buf_cnt : %d | default : %d | qcount : %d | report_q : %d\n" , + inst->min_src_frame_buf_count,COMMAND_QUEUE_DEPTH , q_status.instance_queue_count, + q_status.report_queue_count); + + max_cmd_q = (inst->min_src_frame_buf_count <COMMAND_QUEUE_DEPTH ) ? + inst->min_src_frame_buf_count :COMMAND_QUEUE_DEPTH ; + remain_cmd_q = max_cmd_q - q_status.instance_queue_count; + +while (remain_cmd_q) { +struct vb2_v4l2_buffer *src_buf; +struct vb2_v4l2_buffer *dst_buf; +struct vpu_buffer *src_vbuf; +struct vpu_buffer *dst_vbuf; +struct frame_buffer frame_buf; +struct enc_param pic_param; +s32 luma_size = (inst->dst_fmt.width * inst->dst_fmt.height); +s32 chroma_size = ((inst->dst_fmt.width /2 ) * (inst->dst_fmt.height /2 )); + +memset (&pic_param,0 ,sizeof (struct enc_param )); + + src_buf =get_valid_src_buf (inst); + dst_buf =get_valid_dst_buf (inst); + +if (!src_buf || !dst_buf) { +DPRINTK (inst->dev,1 ,"no valid src/dst buf\n" ); +break ; + } + + src_vbuf =to_vpu_buf (src_buf); + dst_vbuf =to_vpu_buf (dst_buf); + +if (inst->src_fmt.num_planes ==1 ) { + frame_buf.buf_y =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); + frame_buf.buf_cb = frame_buf.buf_y + luma_size; + frame_buf.buf_cr = frame_buf.buf_cb + chroma_size; + }else if (inst->src_fmt.num_planes ==2 ) { + frame_buf.buf_y =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); + frame_buf.buf_cb =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,1 ); + frame_buf.buf_cr = frame_buf.buf_cb + chroma_size; + }else if (inst->src_fmt.num_planes ==3 ) { + frame_buf.buf_y =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); + frame_buf.buf_cb =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,1 ); + frame_buf.buf_cr =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,2 ); + } + frame_buf.stride = inst->dst_fmt.width; + frame_buf.cbcr_interleave =0 ; + +DPRINTK (inst->dev,1 ,"encoding src sequence : %d | dst sequence : %d\n" , + src_buf->sequence, dst_buf->sequence); + + pic_param.src_idx = src_buf->vb2_buf.index; + pic_param.source_frame = &frame_buf; + pic_param.pic_stream_buffer_addr =vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 ); + pic_param.pic_stream_buffer_size =vb2_plane_size (&dst_buf->vb2_buf,0 ); + pic_param.code_option.implicit_header_encode =1 ; + + ret_code =vpu_enc_start_one_frame (inst, &pic_param); +if (ret_code !=RETCODE_SUCCESS ) { +if (ret_code !=RETCODE_QUEUEING_FAILURE ) { + src_buf =v4l2_m2m_src_buf_remove (inst->v4l2_fh.m2m_ctx); + dst_buf =v4l2_m2m_dst_buf_remove (inst->v4l2_fh.m2m_ctx); +DPRINTK (inst->dev,1 ,"fail to call vpu_enc_start_one_frame() %d\n" , + ret_code); + inst->state =VPU_INST_STATE_STOP ; +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_ERROR ); + } + }else { +DPRINTK (inst->dev,1 ,"success to call vpu_enc_start_one_frame() %d\n" , + ret_code); + src_vbuf->consumed = TRUE; + dst_vbuf->consumed = TRUE; + } + + remain_cmd_q--; + } +} + +static void vpu_enc_stop_encode (struct vpu_instance *inst) +{ +struct queue_status_info q_status; + + inst->state =VPU_INST_STATE_STOP ; + +vpu_enc_give_command (inst,ENC_GET_QUEUE_STATUS , &q_status); + +if (q_status.report_queue_count + q_status.instance_queue_count ==0 ) +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); +} + +static void vpu_enc_finish_encode (struct vpu_instance *inst) +{ +enum ret_code ret_code; +struct enc_output_info enc_output_info; +int irq_status; + +if (kfifo_out (&inst->dev->irq_status, &irq_status,sizeof (int ))) +vpu_clear_interrupt_ex (inst, irq_status); + + ret_code =vpu_enc_get_output_info (inst, &enc_output_info); +if (ret_code !=RETCODE_SUCCESS ) { +DPRINTK (inst->dev,1 ,"vpu_enc_get_output_info fail %d | reason: %d | info : %d\n" , + ret_code, enc_output_info.error_reason, enc_output_info.warn_info); + }else { +struct vb2_v4l2_buffer *dst_buf =NULL ; +struct v4l2_m2m_buffer *v4l2_m2m_buf =NULL ; + + v4l2_m2m_buf =NULL ; +v4l2_m2m_for_each_dst_buf (inst->v4l2_fh.m2m_ctx, v4l2_m2m_buf) { + dst_buf = &v4l2_m2m_buf->vb; +if (enc_output_info.bitstream_buffer ==vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 )) +break ; + } + +if (enc_output_info.enc_src_idx >=0 ) { +struct vb2_v4l2_buffer *src_buf = +v4l2_m2m_src_buf_remove_by_idx (inst->v4l2_fh.m2m_ctx, + enc_output_info.enc_src_idx); + + inst->timestamp = src_buf->vb2_buf.timestamp; +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_DONE ); + } + +if (enc_output_info.recon_frame_index ==RECON_IDX_FLAG_ENC_END ) { +static const struct v4l2_event vpu_event_eos = { + .type =V4L2_EVENT_EOS + }; + + dst_buf->flags |=V4L2_BUF_FLAG_LAST ; +vb2_set_plane_payload (&dst_buf->vb2_buf,0 ,0 ); + + inst->state =VPU_INST_STATE_STOP ; +v4l2_event_queue_fh (&inst->v4l2_fh, &vpu_event_eos); + }else { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , enc_output_info.bitstream_size); + + dst_buf->vb2_buf.timestamp = inst->timestamp; + dst_buf->field =V4L2_FIELD_NONE ; +if (enc_output_info.pic_type ==PIC_TYPE_I ) { +if (enc_output_info.enc_vcl_nut ==19 || enc_output_info.enc_vcl_nut ==20 ) + dst_buf->flags |=V4L2_BUF_FLAG_KEYFRAME ; +else + dst_buf->flags |=V4L2_BUF_FLAG_PFRAME ; + }else if (enc_output_info.pic_type ==PIC_TYPE_P ) { + dst_buf->flags |=V4L2_BUF_FLAG_PFRAME ; + }else if (enc_output_info.pic_type ==PIC_TYPE_B ) { + dst_buf->flags |=V4L2_BUF_FLAG_BFRAME ; + } + } + +v4l2_m2m_dst_buf_remove_by_buf (inst->v4l2_fh.m2m_ctx, dst_buf); +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_DONE ); + } + +if (inst->state ==VPU_INST_STATE_STOP ) { +struct queue_status_info q_status; + +vpu_enc_give_command (inst,ENC_GET_QUEUE_STATUS , &q_status); +DPRINTK (inst->dev,1 ,"default : %d | qcount : %d | report_q : %d\n" , +COMMAND_QUEUE_DEPTH , q_status.instance_queue_count, + q_status.report_queue_count); + +if (q_status.report_queue_count + q_status.instance_queue_count ==0 ) +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); + }else { +v4l2_m2m_job_finish (inst->dev->v4l2_m2m_dev, inst->v4l2_fh.m2m_ctx); + } +} + +static int vpu_enc_querycap (struct file *file,void *fh,struct v4l2_capability *cap) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"\n" ); + +strscpy (cap->driver,VPU_ENC_DRV_NAME ,sizeof (cap->driver)); +strscpy (cap->card,VPU_ENC_DRV_NAME ,sizeof (cap->card)); +strscpy (cap->bus_info,"platform:" VPU_ENC_DRV_NAME ,sizeof (cap->bus_info)); + +return 0 ; +} + +static int vpu_enc_enum_framesizes (struct file *file,void *fh,struct v4l2_frmsizeenum *fsize) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"\n" ); + +if (fsize->index) +return -EINVAL ; + + vpu_fmt =find_vpu_format (fsize->pixel_format,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + vpu_fmt =find_vpu_format (fsize->pixel_format,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + } + + fsize->type =V4L2_FRMSIZE_TYPE_CONTINUOUS ; + fsize->stepwise.min_width = vpu_fmt->min_width; + fsize->stepwise.max_width = vpu_fmt->max_width; + fsize->stepwise.step_width =1 ; + fsize->stepwise.min_height = vpu_fmt->min_height; + fsize->stepwise.max_height = vpu_fmt->max_height; + fsize->stepwise.step_height =1 ; + +return 0 ; +} + +static int vpu_enc_enum_fmt_cap (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"index : %d\n" , f->index); + + vpu_fmt =find_vpu_format_by_index (f->index,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + +return 0 ; +} + +static int vpu_enc_try_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"fourcc: %d width %d height %d num_planes %d field : %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + +if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) +return -EINVAL ; + + vpu_fmt =find_vpu_format (f->fmt.pix_mp.pixelformat,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; + f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; +update_resolution_info (&f->fmt.pix_mp, inst->dst_fmt.width, inst->dst_fmt.height); + }else { + f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; + f->fmt.pix_mp.num_planes = vpu_fmt->num_planes; +update_resolution_info (&f->fmt.pix_mp,clamp (f->fmt.pix_mp.width, + vpu_fmt->min_width, vpu_fmt->max_width), +clamp (f->fmt.pix_mp.height, vpu_fmt->min_height, + vpu_fmt->max_height)); + } + + f->fmt.pix_mp.flags =0 ; + f->fmt.pix_mp.field =V4L2_FIELD_NONE ; + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; +memset (&f->fmt.pix_mp.reserved,0 ,sizeof (f->fmt.pix_mp.reserved)); + +return 0 ; +} + +static int vpu_enc_s_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i, ret; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d field %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + + ret =vpu_enc_try_fmt_cap (file, fh, f); +if (ret) +return ret; + + inst->dst_fmt.width = f->fmt.pix_mp.width; + inst->dst_fmt.height = f->fmt.pix_mp.height; + inst->dst_fmt.pixelformat = f->fmt.pix_mp.pixelformat; + inst->dst_fmt.field = f->fmt.pix_mp.field; + inst->dst_fmt.flags = f->fmt.pix_mp.flags; + inst->dst_fmt.num_planes = f->fmt.pix_mp.num_planes; +for (i =0 ; i < inst->dst_fmt.num_planes; i++) { + inst->dst_fmt.plane_fmt[i].bytesperline = f->fmt.pix_mp.plane_fmt[i].bytesperline; + inst->dst_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; + } + +return 0 ; +} + +static int vpu_enc_g_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i; + +DPRINTK (inst->dev,1 ,"\n" ); + + f->fmt.pix_mp.width = inst->dst_fmt.width; + f->fmt.pix_mp.height = inst->dst_fmt.height; + f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; + f->fmt.pix_mp.field = inst->dst_fmt.field; + f->fmt.pix_mp.flags = inst->dst_fmt.flags; + f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; +for (i =0 ; i < f->fmt.pix_mp.num_planes; i++) { + f->fmt.pix_mp.plane_fmt[i].bytesperline = inst->dst_fmt.plane_fmt[i].bytesperline; + f->fmt.pix_mp.plane_fmt[i].sizeimage = inst->dst_fmt.plane_fmt[i].sizeimage; + } + + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; + +return 0 ; +} + +static int vpu_enc_enum_fmt_out (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"index : %d\n" , f->index); + + vpu_fmt =find_vpu_format_by_index (f->index,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + +return 0 ; +} + +static int vpu_enc_try_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +const struct vpu_format *vpu_fmt; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d field %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + +if (f->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) +return -EINVAL ; + + vpu_fmt =find_vpu_format (f->fmt.pix_mp.pixelformat,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) { + f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; + f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; +update_resolution_info (&f->fmt.pix_mp, inst->src_fmt.width, inst->src_fmt.height); + }else { + f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; + f->fmt.pix_mp.num_planes = vpu_fmt->num_planes; +update_resolution_info (&f->fmt.pix_mp,clamp (f->fmt.pix_mp.width, + vpu_fmt->min_width, vpu_fmt->max_width), +clamp (f->fmt.pix_mp.height, vpu_fmt->min_height, + vpu_fmt->max_height)); + } + + f->fmt.pix_mp.flags =0 ; + f->fmt.pix_mp.field =V4L2_FIELD_NONE ; +memset (&f->fmt.pix_mp.reserved,0 ,sizeof (f->fmt.pix_mp.reserved)); + +return 0 ; +} + +static int vpu_enc_s_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i, ret; + +DPRINTK (inst->dev,1 ,"4cc %d width %d height %d num_planes %d field : %d\n" , + f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes, f->fmt.pix_mp.field); + + ret =vpu_enc_try_fmt_out (file, fh, f); +if (ret) +return ret; + + inst->src_fmt.width = f->fmt.pix_mp.width; + inst->src_fmt.height = f->fmt.pix_mp.height; + inst->src_fmt.pixelformat = f->fmt.pix_mp.pixelformat; + inst->src_fmt.field = f->fmt.pix_mp.field; + inst->src_fmt.flags = f->fmt.pix_mp.flags; + inst->src_fmt.num_planes = f->fmt.pix_mp.num_planes; +for (i =0 ; i < inst->src_fmt.num_planes; i++) { + inst->src_fmt.plane_fmt[i].bytesperline = f->fmt.pix_mp.plane_fmt[i].bytesperline; + inst->src_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; + } + + inst->colorspace = f->fmt.pix_mp.colorspace; + inst->ycbcr_enc = f->fmt.pix_mp.ycbcr_enc; + inst->hsv_enc = f->fmt.pix_mp.hsv_enc; + inst->quantization = f->fmt.pix_mp.quantization; + inst->xfer_func = f->fmt.pix_mp.xfer_func; + +update_resolution_info (&inst->dst_fmt, f->fmt.pix_mp.width, f->fmt.pix_mp.height); + +return 0 ; +} + +static int vpu_enc_g_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int i; + +DPRINTK (inst->dev,1 ,"\n" ); + + f->fmt.pix_mp.width = inst->src_fmt.width; + f->fmt.pix_mp.height = inst->src_fmt.height; + f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; + f->fmt.pix_mp.field = inst->src_fmt.field; + f->fmt.pix_mp.flags = inst->src_fmt.flags; + f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; +for (i =0 ; i < f->fmt.pix_mp.num_planes; i++) { + f->fmt.pix_mp.plane_fmt[i].bytesperline = inst->src_fmt.plane_fmt[i].bytesperline; + f->fmt.pix_mp.plane_fmt[i].sizeimage = inst->src_fmt.plane_fmt[i].sizeimage; + } + + f->fmt.pix_mp.colorspace = inst->colorspace; + f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; + f->fmt.pix_mp.hsv_enc = inst->hsv_enc; + f->fmt.pix_mp.quantization = inst->quantization; + f->fmt.pix_mp.xfer_func = inst->xfer_func; + +return 0 ; +} + +static int vpu_enc_g_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | target : %d\n" , s->type, s->target); + +if (s->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT ) { +switch (s->target) { +case V4L2_SEL_TGT_CROP_DEFAULT : +case V4L2_SEL_TGT_CROP_BOUNDS : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->src_fmt.width; + s->r.height = inst->src_fmt.height; +break ; +case V4L2_SEL_TGT_CROP : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->dst_fmt.width; + s->r.height = inst->dst_fmt.height; +DPRINTK (inst->dev,1 ,"V4L2_SEL_TGT_CROP width : %d | height : %d\n" , + s->r.width, s->r.height); +break ; +default : +return -EINVAL ; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_enc_s_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | target : %d\n" , s->type, s->target); + +if (s->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT ) { +switch (s->target) { +case V4L2_SEL_TGT_CROP : +DPRINTK (inst->dev,1 ,"V4L2_SEL_TGT_CROP width : %d | height : %d\n" , + s->r.width, s->r.height); + inst->dst_fmt.width = s->r.width; + inst->dst_fmt.height = s->r.height; +break ; +default : +return -EINVAL ; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_enc_try_encoder_cmd (struct file *file,void *fh,struct v4l2_encoder_cmd *ec) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"\n" ); + +if (ec->cmd !=V4L2_ENC_CMD_STOP && ec->cmd !=V4L2_ENC_CMD_START ) +return -EINVAL ; + + ec->flags =0 ; +return 0 ; +} + +static int vpu_enc_encoder_cmd (struct file *file,void *fh,struct v4l2_encoder_cmd *ec) +{ +struct vpu_instance *inst =to_vpu_inst (fh); +int ret; + +DPRINTK (inst->dev,1 ,"\n" ); + + ret =vpu_enc_try_encoder_cmd (file, fh, ec); +if (ret <0 ) +return ret; + +if (!vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE )) || + !vb2_is_streaming (v4l2_m2m_get_vq (inst->v4l2_fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ))) +return 0 ; + +switch (ec->cmd) { +case V4L2_ENC_CMD_STOP : +vpu_enc_stop_encode (inst); +break ; +case V4L2_ENC_CMD_START : +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int vpu_enc_subscribe_event (struct v4l2_fh *fh,const struct v4l2_event_subscription *sub) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d | id : %d | flags : %d\n" , sub->type, sub->id, sub->flags); + +switch (sub->type) { +case V4L2_EVENT_EOS : +return v4l2_event_subscribe (fh, sub,0 ,NULL ); +case V4L2_EVENT_CTRL : +return v4l2_ctrl_subscribe_event (fh, sub); +default : +return -EINVAL ; + } +} + +static int vpu_enc_g_parm (struct file *file,void *fh,struct v4l2_streamparm *a) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d\n" , a->type); + +if (a->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT && a->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) +return -EINVAL ; + + a->parm.output.capability =V4L2_CAP_TIMEPERFRAME ; + a->parm.output.timeperframe.numerator =1 ; + a->parm.output.timeperframe.denominator = inst->frame_rate; + +DPRINTK (inst->dev,1 ,"numerator : %d | denominator : %d\n" , + a->parm.output.timeperframe.numerator, + a->parm.output.timeperframe.denominator); + +return 0 ; +} + +static int vpu_enc_s_parm (struct file *file,void *fh,struct v4l2_streamparm *a) +{ +struct vpu_instance *inst =to_vpu_inst (fh); + +DPRINTK (inst->dev,1 ,"type : %d\n" , a->type); + +if (a->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT && a->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) +return -EINVAL ; + + a->parm.output.capability =V4L2_CAP_TIMEPERFRAME ; +if (a->parm.output.timeperframe.denominator !=0 && a->parm.output.timeperframe.numerator !=0 ) { + inst->frame_rate = a->parm.output.timeperframe.denominator / a->parm.output.timeperframe.numerator; + }else { + a->parm.output.timeperframe.numerator =1 ; + a->parm.output.timeperframe.denominator = inst->frame_rate; + } + +DPRINTK (inst->dev,1 ,"numerator : %d | denominator : %d\n" , + a->parm.output.timeperframe.numerator, + a->parm.output.timeperframe.denominator); + +return 0 ; +} + +static const struct v4l2_ioctl_ops vpu_enc_ioctl_ops = { + .vidioc_querycap = vpu_enc_querycap, + .vidioc_enum_framesizes = vpu_enc_enum_framesizes, + + .vidioc_enum_fmt_vid_cap = vpu_enc_enum_fmt_cap, + .vidioc_s_fmt_vid_cap_mplane = vpu_enc_s_fmt_cap, + .vidioc_g_fmt_vid_cap_mplane = vpu_enc_g_fmt_cap, + .vidioc_try_fmt_vid_cap_mplane = vpu_enc_try_fmt_cap, + + .vidioc_enum_fmt_vid_out = vpu_enc_enum_fmt_out, + .vidioc_s_fmt_vid_out_mplane = vpu_enc_s_fmt_out, + .vidioc_g_fmt_vid_out_mplane = vpu_enc_g_fmt_out, + .vidioc_try_fmt_vid_out_mplane = vpu_enc_try_fmt_out, + + .vidioc_g_selection = vpu_enc_g_selection, + .vidioc_s_selection = vpu_enc_s_selection, + + .vidioc_g_parm = vpu_enc_g_parm, + .vidioc_s_parm = vpu_enc_s_parm, + + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, + .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, + .vidioc_streamon = v4l2_m2m_ioctl_streamon, + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, + + .vidioc_try_encoder_cmd = vpu_enc_try_encoder_cmd, + .vidioc_encoder_cmd = vpu_enc_encoder_cmd, + + .vidioc_subscribe_event = vpu_enc_subscribe_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, +}; + +static int vpu_enc_g_volatile_ctrl (struct v4l2_ctrl *ctrl) +{ +struct vpu_instance *inst =ctrl_to_vpu_inst (ctrl); + +DPRINTK (inst->dev,1 ,"name : %s\n" , ctrl->name); + +switch (ctrl->id) { +case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT : +if (inst->state !=VPU_INST_STATE_NONE && inst->state !=VPU_INST_STATE_OPEN ) + ctrl->val = inst->min_src_frame_buf_count; +break ; +default : +return -EINVAL ; + } + +DPRINTK (inst->dev,1 ,"value : %d\n" , ctrl->val); + +return 0 ; +} + +static int vpu_enc_s_ctrl (struct v4l2_ctrl *ctrl) +{ +struct vpu_instance *inst =ctrl_to_vpu_inst (ctrl); + +DPRINTK (inst->dev,1 ,"name : %s | value : %d\n" , ctrl->name, ctrl->val); + +switch (ctrl->id) { +case V4L2_CID_HFLIP : + inst->mirror_direction |= (ctrl->val <<1 ); +break ; +case V4L2_CID_VFLIP : + inst->mirror_direction |= ctrl->val; +break ; +case V4L2_CID_ROTATE : + inst->rot_angle = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_VBV_SIZE : + inst->vbv_buf_size = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE : +switch (ctrl->val) { +case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN : + inst->profile =HEVC_PROFILE_MAIN ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE : + inst->profile =HEVC_PROFILE_STILLPICTURE ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10 : + inst->profile =HEVC_PROFILE_MAIN10 ; + inst->bit_depth =10 ; +break ; +default : + inst->profile =0 ; + inst->bit_depth =0 ; +break ; + } +break ; +case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL : +switch (ctrl->val) { +case V4L2_MPEG_VIDEO_HEVC_LEVEL_1 : + inst->level =10 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_2 : + inst->level =20 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_2_1 : + inst->level =21 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_3 : + inst->level =30 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_3_1 : + inst->level =31 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_4 : + inst->level =40 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_4_1 : + inst->level =41 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_5 : + inst->level =50 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1 : + inst->level =51 *3 ; +break ; +case V4L2_MPEG_VIDEO_HEVC_LEVEL_5_2 : + inst->level =52 *3 ; +break ; +default : + inst->level =0 ; +break ; + } +break ; +case V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP : + inst->min_qp_i = ctrl->val; + inst->min_qp_p = ctrl->val; + inst->min_qp_b = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP : + inst->max_qp_i = ctrl->val; + inst->max_qp_p = ctrl->val; + inst->max_qp_b = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_H264_PROFILE : +switch (ctrl->val) { +case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE : +case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE : + inst->profile =H264_PROFILE_BP ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN : + inst->profile =H264_PROFILE_MP ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED : + inst->profile =H264_PROFILE_EXTENDED ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH : + inst->profile =H264_PROFILE_HP ; + inst->bit_depth =8 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10 : + inst->profile =H264_PROFILE_HIGH10 ; + inst->bit_depth =10 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422 : + inst->profile =H264_PROFILE_HIGH422 ; + inst->bit_depth =10 ; +break ; +case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_PREDICTIVE : + inst->profile =H264_PROFILE_HIGH444 ; + inst->bit_depth =10 ; +break ; +default : + inst->profile =0 ; + inst->bit_depth =0 ; +break ; + } +break ; +case V4L2_CID_MPEG_VIDEO_H264_LEVEL : +switch (ctrl->val) { +case V4L2_MPEG_VIDEO_H264_LEVEL_1_0 : + inst->level =10 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_1B : + inst->level =9 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_1_1 : + inst->level =11 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_1_2 : + inst->level =12 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_1_3 : + inst->level =13 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_2_0 : + inst->level =20 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_2_1 : + inst->level =21 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_2_2 : + inst->level =22 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_3_0 : + inst->level =30 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_3_1 : + inst->level =31 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_3_2 : + inst->level =32 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_4_0 : + inst->level =40 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_4_1 : + inst->level =41 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_4_2 : + inst->level =42 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_5_0 : + inst->level =50 ; +break ; +case V4L2_MPEG_VIDEO_H264_LEVEL_5_1 : + inst->level =51 ; +break ; +default : + inst->level =0 ; +break ; + } +break ; +case V4L2_CID_MPEG_VIDEO_H264_MIN_QP : + inst->min_qp_i = ctrl->val; + inst->min_qp_p = ctrl->val; + inst->min_qp_b = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_H264_MAX_QP : + inst->max_qp_i = ctrl->val; + inst->max_qp_p = ctrl->val; + inst->max_qp_b = ctrl->val; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct v4l2_ctrl_ops vpu_enc_ctrl_ops = { + .g_volatile_ctrl = vpu_enc_g_volatile_ctrl, + .s_ctrl = vpu_enc_s_ctrl, +}; + +static void set_default_enc_openparam (struct enc_open_param *open_param) +{ +unsigned int i; + + open_param->stream_endian =VPU_STREAM_ENDIAN ; + open_param->source_endian =VPU_SOURCE_ENDIAN ; + open_param->line_buf_int_en = TRUE; + + open_param->wave_param.gop_preset_idx =PRESET_IDX_IPP_SINGLE ; + open_param->wave_param.decoding_refresh_type =1 ; + open_param->wave_param.intra_qp =30 ; + open_param->wave_param.tmvp_enable =1 ; + open_param->wave_param.max_num_merge =2 ; + open_param->wave_param.lf_cross_slice_boundary_enable =1 ; + open_param->wave_param.skip_intra_trans =1 ; + open_param->wave_param.sao_enable =1 ; + open_param->wave_param.transform8x8_enable =1 ; + open_param->wave_param.intra_nx_n_enable =1 ; +for (i =0 ; i <MAX_GOP_NUM ; i++) + open_param->wave_param.fixed_bit_ratio[i] =1 ; + open_param->wave_param.cu_level_rc_enable =1 ;Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/staging/media/wave5/v4l2/vpu_enc.c line 1095
Quoted 10 lines
drivers/staging/media/wave5/v4l2/vpu_enc.c new file +10
-0+ open_param->wave_param.hvs_qp_enable =1 ; + open_param->wave_param.hvs_qp_scale =2 ; + open_param->wave_param.hvs_max_delta_qp =10 ; + open_param->wave_param.gop_param.custom_gop_size =1 ; + open_param->wave_param.initial_rc_qp =-1 ; + open_param->wave_param.nr_intra_weight_y =7 ; + open_param->wave_param.nr_intra_weight_cb =7 ; + open_param->wave_param.nr_intra_weight_cr =7 ; + open_param->wave_param.nr_inter_weight_y =4 ; + open_param->wave_param.nr_inter_weight_cb =4 ;Make sure you replace all of these with proper errnos.
Quoted 36 lines
drivers/staging/media/wave5/v4l2/vpu_enc.c new file +11
-0Lines of this file are not shown. View the raw message.
drivers/staging/media/wave5/v4l2/vpu_enc.h new file +18
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 2 lines
2.17.1
Regards,
Ezequiel
Part of the diff is not shown here. View the raw message.
kernel test robot
build botRe: [PATCH 3/6] staging: media: wave5: Add the v4l2 layer
In reply to Dafna HirschfeldI love your patch! Perhaps something to improve:
Hi Dafna,
I love your patch! Perhaps something to improve:
[auto build test WARNING on staging/staging-testing]
url: https://github.com/0day-ci/linux/commits/Dafna-Hirschfeld/staging-media-wave5-add-wave5-codec-driver/20210916-002552 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 5e57c668dc097c6c27c973504706edec53f79281 config: csky-randconfig-r033-20210916 (attached as .config) compiler: csky-linux-gcc (GCC) 11.2.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/99e6d1e51b84739f614c6ae5a772b04671bad9ba
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Dafna-Hirschfeld/staging-media-wave5-add-wave5-codec-driver/20210916-002552 git checkout 99e6d1e51b84739f614c6ae5a772b04671bad9ba
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=csky
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
In file included from include/linux/bitops.h:33,
from include/linux/kernel.h:12,
from include/linux/kfifo.h:39,
from drivers/staging/media/wave5/vpuapi/vpuapi.h:11,
from drivers/staging/media/wave5/vpuapi/vpuapi.c:9:
arch/csky/include/asm/bitops.h:77: warning: "__clear_bit" redefined
77 | #define __clear_bit(nr, vaddr) clear_bit(nr, vaddr)
|
In file included from arch/csky/include/asm/bitops.h:76,
from include/linux/bitops.h:33,
from include/linux/kernel.h:12,
from include/linux/kfifo.h:39,
from drivers/staging/media/wave5/vpuapi/vpuapi.h:11,
from drivers/staging/media/wave5/vpuapi/vpuapi.c:9:
include/asm-generic/bitops/non-atomic.h:34: note: this is the location of the previous definition
34 | #define __clear_bit arch___clear_bit
|
drivers/staging/media/wave5/vpuapi/vpuapi.c: In function 'vpu_dec_get_bitstream_buffer':
>> drivers/staging/media/wave5/vpuapi/vpuapi.c:323:26: warning: variable 'p_attr' set but not used [-Wunused-but-set-variable]
323 | struct vpu_attr *p_attr;
| ^~~~~~
drivers/staging/media/wave5/vpuapi/vpuapi.c: In function 'vpu_enc_register_frame_buffer':
>> drivers/staging/media/wave5/vpuapi/vpuapi.c:824:32: warning: variable 'open_param' set but not used [-Wunused-but-set-variable]
824 | struct enc_open_param *open_param;
| ^~~~~~~~~~--
In file included from include/linux/bitops.h:33,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/preempt.h:11,
from include/linux/spinlock.h:55,
from include/linux/mmzone.h:8,
from include/linux/gfp.h:6,
from include/linux/slab.h:15,
from drivers/staging/media/wave5/vdi/vdi.h:13,
from drivers/staging/media/wave5/vdi/vdi.c:8:
arch/csky/include/asm/bitops.h:77: warning: "__clear_bit" redefined
77 | #define __clear_bit(nr, vaddr) clear_bit(nr, vaddr)
|
In file included from arch/csky/include/asm/bitops.h:76,
from include/linux/bitops.h:33,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/preempt.h:11,
from include/linux/spinlock.h:55,
from include/linux/mmzone.h:8,
from include/linux/gfp.h:6,
from include/linux/slab.h:15,
from drivers/staging/media/wave5/vdi/vdi.h:13,
from drivers/staging/media/wave5/vdi/vdi.c:8:
include/asm-generic/bitops/non-atomic.h:34: note: this is the location of the previous definition
34 | #define __clear_bit arch___clear_bit
|
>> drivers/staging/media/wave5/vdi/vdi.c:239:6: warning: no previous prototype for 'byte_swap' [-Wmissing-prototypes]
239 | void byte_swap(unsigned char *data, int len)
| ^~~~~~~~~
>> drivers/staging/media/wave5/vdi/vdi.c:251:6: warning: no previous prototype for 'word_swap' [-Wmissing-prototypes]
251 | void word_swap(unsigned char *data, int len)
| ^~~~~~~~~
>> drivers/staging/media/wave5/vdi/vdi.c:264:6: warning: no previous prototype for 'dword_swap' [-Wmissing-prototypes]
264 | void dword_swap(unsigned char *data, int len)
| ^~~~~~~~~~
>> drivers/staging/media/wave5/vdi/vdi.c:277:6: warning: no previous prototype for 'lword_swap' [-Wmissing-prototypes] 277 | void lword_swap(unsigned char *data, int len)
| ^~~~~~~~~~
--
In file included from include/linux/bitops.h:33,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/media/v4l2-ctrls.h:11,
from drivers/staging/media/wave5/v4l2/vpu.h:10,
from drivers/staging/media/wave5/v4l2/vpu_enc.h:10,
from drivers/staging/media/wave5/v4l2/vpu_enc.c:7:
arch/csky/include/asm/bitops.h:77: warning: "__clear_bit" redefined
77 | #define __clear_bit(nr, vaddr) clear_bit(nr, vaddr)
|
In file included from arch/csky/include/asm/bitops.h:76,
from include/linux/bitops.h:33,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/media/v4l2-ctrls.h:11,
from drivers/staging/media/wave5/v4l2/vpu.h:10,
from drivers/staging/media/wave5/v4l2/vpu_enc.h:10,
from drivers/staging/media/wave5/v4l2/vpu_enc.c:7:
include/asm-generic/bitops/non-atomic.h:34: note: this is the location of the previous definition
34 | #define __clear_bit arch___clear_bit
|
drivers/staging/media/wave5/v4l2/vpu_enc.c: In function 'to_vpu_codstd':
>> drivers/staging/media/wave5/v4l2/vpu_enc.c:84:24: warning: implicit conversion from 'enum wave_std' to 'enum cod_std' [-Wenum-conversion]
84 | return W_AVC_ENC;
| ^~~~~~~~~
drivers/staging/media/wave5/v4l2/vpu_enc.c:86:24: warning: implicit conversion from 'enum wave_std' to 'enum cod_std' [-Wenum-conversion]
86 | return W_HEVC_ENC;
| ^~~~~~~~~~
drivers/staging/media/wave5/v4l2/vpu_enc.c:88:24: warning: implicit conversion from 'enum wave_std' to 'enum cod_std' [-Wenum-conversion]
88 | return STD_UNKNOWN;
| ^~~~~~~~~~~
drivers/staging/media/wave5/v4l2/vpu_enc.c: In function 'vpu_enc_queue_setup':
>> drivers/staging/media/wave5/v4l2/vpu_enc.c:1150:27: warning: implicit conversion from 'enum cod_std' to 'enum wave_std' [-Wenum-conversion]
1150 | inst->std = to_vpu_codstd(inst->dst_fmt.pixelformat);
| ^vim +/open_param +824 drivers/staging/media/wave5/vpuapi/vpuapi.c
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 818
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 819 enum ret_code vpu_enc_register_frame_buffer(struct vpu_instance *inst, int num, int stride,
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 820 int height, enum tiled_map_type map_type)
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 821 {
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 822 struct enc_info *p_enc_info;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 823 enum ret_code ret;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 @824 struct enc_open_param *open_param;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 825 struct frame_buffer *fb;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 826 struct vpu_device *vpu_dev = inst->dev;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 827 u32 size_luma, size_chroma;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 828 int i;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 829
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 830 p_enc_info = &inst->codec_info->enc_info;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 831 open_param = &p_enc_info->open_param;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 832
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 833 if (p_enc_info->stride)
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 834 return RETCODE_CALLED_BEFORE;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 835
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 836 if (!p_enc_info->initial_info_obtained)
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 837 return RETCODE_WRONG_CALL_SEQUENCE;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 838
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 839 if (num < p_enc_info->initial_info.min_frame_buffer_count)
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 840 return RETCODE_INSUFFICIENT_FRAME_BUFFERS;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 841
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 842 if (stride == 0 || (stride % 8 != 0) || stride < 0)
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 843 return RETCODE_INVALID_STRIDE;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 844
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 845 if (height == 0 || height < 0)
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 846 return RETCODE_INVALID_PARAM;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 847
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 848 if (mutex_lock_interruptible(&vpu_dev->hw_lock))
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 849 return RETCODE_FAILURE;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 850
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 851 p_enc_info->num_frame_buffers = num;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 852 p_enc_info->stride = stride;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 853
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 854 fb = inst->frame_buf;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 855 size_luma = stride * height;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 856 size_chroma = ALIGN(stride / 2, 16) * height;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 857
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 858 for (i = 0; i < num; i++) {
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 859 if (fb[i].update_fb_info) {
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 860 fb[i].update_fb_info = FALSE;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 861 fb[i].stride = stride;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 862 fb[i].height = height;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 863 fb[i].map_type = COMPRESSED_FRAME_MAP;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 864 fb[i].cbcr_interleave = true;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 865 fb[i].endian = VDI_128BIT_LITTLE_ENDIAN;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 866 fb[i].buf_y_size = size_luma;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 867 fb[i].buf_cb = fb[i].buf_y + size_luma;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 868 fb[i].buf_cb_size = size_chroma;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 869 fb[i].buf_cr_size = 0;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 870 }
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 871 }
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 872
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 873 ret = wave5_vpu_enc_register_framebuffer(inst->dev->dev, inst, &fb[0],
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 874 COMPRESSED_FRAME_MAP, p_enc_info->num_frame_buffers);
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 875
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 876 mutex_unlock(&vpu_dev->hw_lock);
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 877
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 878 return ret;
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 879 }
77ec4cac6e8198 Dafna Hirschfeld 2021-09-15 880 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 4/6 staging: wave5: Add TODO file
In reply to Dafna HirschfeldAdd a TODO file listing all that is need for destaging.
--- drivers/staging/media/wave5/TODO | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 drivers/staging/media/wave5/TODO
drivers/staging/media/wave5/TODO new file +42 -0
@@ -0,0 +1,42 @@ +* Test on real silicon once available + + This driver has so far been tested on pre-silicon FPGA and on the beta BeagleV + board which uses the StarFive JH7100 beta SoC. + + Testing on FPGA shows it working fine, though the FPGA uses polled interrupts + and copied buffers between the host and it's on board RAM. + + Testing on BeagleV shows buffer corruption that is currently attributed to a + known silicon issue in the SoC that makes the cache coherent interconnect not + so coherent. + This can likely be solved when the riscv non-coherent dma support lands and + provide optional v4l2 non-contiguous allocator, though it remains to be seen + whether support non-coherent use cases will be useful in real world hw. + + Until we can test and resolve any issues on final silicon (due 2H 2021) + this driver should remain in staging. + +* Handle interrupts better + + Currently the interrupt handling uses an unusual design employing a kfifo to + transfer irq status to irq thread. This was done as a work around for dropped + interrupts seen with IRQF_ONESHOT based handling. + + This needs further investigation and fixing properly, with the aid of + C&M and StarFive engineers. + +* Fix early end of stream handling + + When using a gstreamer pipeline like this: + gst-launch-1.0 filesrc location=<file> ! parsebin ! h264parse ! v4l2h264dec ! jpegenc ! identity eos-after=3 ! multifilesink location=%05d.jpeg + i.e. forced eos after 3 buffers + the pipeline stalls on exit waiting for end of job. + We need to add some form of early exit detection, instead of the current + behaviour of only considering a job finish on PIC_END. + +* Support more formats + + The current frontend v4l2 layer only supports V4L2_PIX_FMT_HEVC and + V4L2_PIX_FMT_H264. + The backend logic supports other formats, so we should wire up the support + for further bitsream formats.
Signature · 1 line
2.17.1
PATCH 5/6 dt-bindings: media: staging: wave5: add yaml devicetree bindings
In reply to Dafna HirschfeldFrom: Robert Beckett <[email protected]>
Add bindings for the wave5 chips&media codec driver
--- .../bindings/staging/media/cnm,wave.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/staging/media/cnm,wave.yaml
Documentation/devicetree/bindings/staging/media/cnm,wave.yaml new file +71 -0
@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/staging/media/cnm,wave.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Chips&Media Wave 5 Series multi-standard codec IP + +maintainers: + - Nas Chung <[email protected]> + - Robert Beckett <[email protected]> + - Dafna Hirschfeld <[email protected]> + +description: |- + The Chips&Media WAVE codec IP is a multi format video encoder/decoder + +properties: + compatible: + anyOf: + - items: + - enum: + - cnm,cm511-vpu + - cnm,cm517-vpu + - cnm,cm521-vpu + - cnm,cm521c-vpu + - cnm,cm521c-dual-vpu + - cnm,cm521e1-vpu + - cnm,cm537-vpu + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + const: vcodec + + interrupts: + maxItems: 1 + + power-domains: + maxItems: 1 + + resets: + maxItems: 1 + + sram: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle pointing to the SRAM device node + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + +additionalProperties: false + +examples: + - | + vpu: video-codec@12345678 { + compatible = "cnm,cm521-vpu"; + reg = <0x12345678 0x1000>; + interrupts = <42>; + clocks = <&clks 42>; + clock-names = "vcodec"; + sram = <&sram>; + }; +
Signature · 1 line
2.17.1
PATCH 6/6 media: wave5: Add wave5 driver to maintainers file
In reply to Dafna HirschfeldFrom: Robert Beckett <[email protected]>
Add the Chips&Media wave5 encoder/decoder driver
to the maintainers file
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -19962,6 +19962,15 @@ F: drivers/watchdog/ F: include/linux/watchdog.h F: include/uapi/linux/watchdog.h +WAVE5 VPU CODEC DRIVER +M: Nas Chung <[email protected]> +M: Robert Beckett <[email protected]> +M: Dafna Hirschfeld <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/staging/media/cnm,wave.yaml +F: drivers/staging/media/wave5/ + WHISKEYCOVE PMIC GPIO DRIVER M: Kuppuswamy Sathyanarayanan <[email protected]> L: [email protected]
Signature · 1 line
2.17.1
Hi Dafna,
Quoted 4 lines · Dafna Hirschfeld
The wave5 codec is a stateful encoder/decoder.
It is found on the JH7100 SoC.
For what it's worth; I think this is also the video decoder block on the SigmaStar SSD201/SSD202D (32bit ARM..) that have some limited support in mainline.
Cheers,
Daniel