Cedrus driver for the Allwinner Video Engine, using media requests
Subsystems (7)
v10 cover Cedrus driver for the Allwinner Video Engine, using media requests
This is the ninth iteration of the updated Cedrus driver, that supports the Video Engine found on most Allwinner SoCs, starting with the A10. It was tested on the A13, A20, A33 and H3.
The initial version of this driver[0] was originally written and submitted by Florent Revest using a previous version of the request API that is necessary to provide coherency between controls and the buffers they apply to.
The driver was adapted to use the latest version of the media request API[1], as submitted by Hans Verkuil. Media request API support is a hard requirement for the Cedrus driver.
The driver itself currently only supports MPEG2 and more codecs will be added eventually. The default output frame format provided by the Video Engine is a multi-planar tiled YUV format (based on NV12). A specific format is introduced in the V4L2 API to describe it. Starting with the A33, the Video Engine can also output untiled YUV formats.
This implementation is based on the significant work that was conducted by various members of the linux-sunxi community for understanding and documenting the Video Engine's innards.
In addition to the media requests API, the following series are required for Cedrus:
* vicodec: the Virtual Codec driver
* allwinner: a64: add SRAM controller / system control
* SRAM patches from the Cedrus VPU driver series version 5
Changes since v10:
* Moved to strscpy
* Fixed the checkpatch warning
* Fixed the wrongful P-frames mention in the MPEG2 documentation
* Removed the DT patches
Changes since v8:
* Removed dummy job_abort as it is now optional;
* Fixed video device registration order;
* Fixed queue_setup for properly handling CREATE_BUFFERS;
* Switched to single-planar API and applied associated reworks, since our formats are not multi-planar V4L2 pixel formats.
* Added validation of the number of buffers associated with the request, by modifying the relevant helper as instructed;
* Used strlcpy where needed;
* Applied various minor fixups from suggestions;
* Added some comments for clarity.
Changes since v7:
* Rebased on the latest Request API;
* Brought back comment about DRAM width;
* Fixed building as a module;
* Fixed copyright headers.
Changes since v6:
* Reworked MPEG2 controls to stick closer to the bitstream;
* Updated controls documentation accordingly and added requested fixes;
* Renamed tiled format to V4L2_PIX_FMT_SUNXI_TILED_NV12;
* Added various minor driver fixes based on Hans' feedback;
* Fixed dst frame alignment based on Jernej's feedback and tests;
* Removed set bits for the disabled secondary output.
Changes since v5:
* Added MPEG2 quantization matrices definitions and support;
* Cleaned up registers definitions;
* Moved the driver to staging as requested;
* Removed label and newline in device-tree sources;
* Made it possible to build the driver for COMPILE_TEST;
* Fixed various strict checkpatch warnings;
* Used v4l2_m2m_register_media_controller and MEDIA_ENT_F_PROC_VIDEO_DECODER;
* Moved capabilities to compatible-specific variants;
* Removed overkill buffer checks in device_run;
* Renamed from Sunxi-Cedrus to Cedrus.
Changes since v4:
* updated to version 16 of the media requests API;
* added support for VPU-based untiling (starting with the A33);
* added support for the H3, with SRAM support;
* reworked SRAM support and associated compatibles;
* improved failure paths;
* added some MPEG2 input data validation;
* reworked video/format functions to handle multiple formats;
* removed in-driver buffer queues;
* used a threaded irq instead of a workqueue;
* merged various improvements and cleanups from Maxime;
* renamed MPEG2_SLICE_HEADER to MPEG2_SLICE_PARAMS;
* added prefixes to MPEG2 picture coding types;
* used single-buffer allocations to ensure contiguous planes
Changes since v3:
* updated to version 15 of the media request API;
* got rid of untested MPEG1 support;
* added definitons for picture coding types;
* added documentation about MPEG2 slice header fields;
* added documentation about MPEG2 slice format;
* added documentation about the MB32 NV12 format;
* added MPEG2 slice header validation;
* removed the assigned-clocks property;
* reworked and fixed error paths;
* harmonized debug prints, with v4l2 helpers when applicable;
* checked the series through checkpatch;
* switched to SPDX license headers;
* renamed MPEG2 frame header to slice header for consistency and clarity;
* removed A20 SRAM compatible from the driver's list.
Changes since v2:
* updated to version 13 of the media request API;
* integrated various changes from Maxime Ripard;
* reworked memory reservation to use CMA, dynamic allocation and allow DMABUF;
* removed reserved memory binding since the CMA pool is the default one (and allow ENODEV in the driver, for that use case);
* added SRAM controller support for the SRAM region used by the VE;
* updated the device-tree bindings the for SRAM region;
* added per-platform bindings;
* added A13 support;
* renamed VE node name and label;
* fixed Florent's authorship for the MPEG2 headers;
* added a MAINTAINERS entry.
Changes since v1:
* use the latest version of the request API for Hans Verkuil;
* added media controller support and dependency
* renamed v4l2 format to the more explicit V4L2_PIX_FMT_MB32_NV12;
* reworked bindings documentation;
* moved driver to drivers/media/platforms/sunxi/cedrus to pair with incoming CSI support ;
* added a workqueue and lists to schedule buffer completion, since it cannot be done in interrupt context;
* split mpeg2 support into a setup and a trigger function to avoid race condition;
* split video-related ops to a dedicated sunxi_cedrus_video file;
* cleaned up the included headers for each file;
* used device PFN offset instead of subtracting PHYS_BASE;
* used reset_control_reset instead of assert+deassert;
* put the device in reset when removing driver;
* changed dt bindings to use the last 96 Mib of the first 256 MiB of DRAM;
* made it clear in the mpeg frame header structure that forward and backward indexes are used as reference frames for motion vectors;
* lots of small cosmetic and consistency changes, including naming harmonization and headers text rework.
Cheers!
[0]: https://patchwork.kernel.org/patch/9299073/
[1]: https://git.linuxtv.org/hverkuil/media_tree.git/log/?h=reqv18-1
Paul Kocialkowski (5):
media: videobuf2-core: Rework and rename helper for request buffer
count
media: v4l: Add definitions for MPEG-2 slice format and metadata
media: v4l: Add definition for the Sunxi tiled NV12 format
dt-bindings: media: Document bindings for the Cedrus VPU driver
media: platform: Add Cedrus VPU decoder driver
.../devicetree/bindings/media/cedrus.txt | 54 ++ .../media/uapi/v4l/extended-controls.rst | 176 ++++++ .../media/uapi/v4l/pixfmt-compressed.rst | 16 + .../media/uapi/v4l/pixfmt-reserved.rst | 13 + .../media/uapi/v4l/vidioc-queryctrl.rst | 14 +- .../media/videodev2.h.rst.exceptions | 2 + MAINTAINERS | 7 + .../media/common/videobuf2/videobuf2-core.c | 18 +- .../media/common/videobuf2/videobuf2-v4l2.c | 2 +- drivers/media/v4l2-core/v4l2-ctrls.c | 63 ++ drivers/media/v4l2-core/v4l2-ioctl.c | 2 + drivers/staging/media/Kconfig | 2 + drivers/staging/media/Makefile | 1 + drivers/staging/media/sunxi/Kconfig | 15 + drivers/staging/media/sunxi/Makefile | 1 + drivers/staging/media/sunxi/cedrus/Kconfig | 14 + drivers/staging/media/sunxi/cedrus/Makefile | 3 + drivers/staging/media/sunxi/cedrus/TODO | 7 + drivers/staging/media/sunxi/cedrus/cedrus.c | 431 ++++++++++++++ drivers/staging/media/sunxi/cedrus/cedrus.h | 167 ++++++ .../staging/media/sunxi/cedrus/cedrus_dec.c | 70 +++ .../staging/media/sunxi/cedrus/cedrus_dec.h | 27 + .../staging/media/sunxi/cedrus/cedrus_hw.c | 327 +++++++++++ .../staging/media/sunxi/cedrus/cedrus_hw.h | 30 + .../staging/media/sunxi/cedrus/cedrus_mpeg2.c | 246 ++++++++ .../staging/media/sunxi/cedrus/cedrus_regs.h | 235 ++++++++ .../staging/media/sunxi/cedrus/cedrus_video.c | 542 ++++++++++++++++++ .../staging/media/sunxi/cedrus/cedrus_video.h | 30 + include/media/v4l2-ctrls.h | 18 +- include/media/videobuf2-core.h | 4 +- include/uapi/linux/v4l2-controls.h | 65 +++ include/uapi/linux/videodev2.h | 6 + 32 files changed, 2586 insertions(+), 22 deletions(-) create mode 100644 Documentation/devicetree/bindings/media/cedrus.txt create mode 100644 drivers/staging/media/sunxi/Kconfig create mode 100644 drivers/staging/media/sunxi/Makefile create mode 100644 drivers/staging/media/sunxi/cedrus/Kconfig create mode 100644 drivers/staging/media/sunxi/cedrus/Makefile create mode 100644 drivers/staging/media/sunxi/cedrus/TODO create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus.h create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_dec.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_dec.h create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_hw.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_hw.h create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_regs.h create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_video.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_video.h
Signature · 1 line
2.17.1
PATCH v10 1/5 media: videobuf2-core: Rework and rename helper for request buffer count
From: Paul Kocialkowski <[email protected]>
The helper indicating whether buffers are associated with the request is reworked and renamed to return the number of associated buffer objects.
This is useful for drivers that need to check how many buffers are in the request to validate it.
Existing users of the helper don't need particular adaptation since the meaning of zero/non-zero remains consistent.
--- .../media/common/videobuf2/videobuf2-core.c | 18 ++++++++---------- .../media/common/videobuf2/videobuf2-v4l2.c | 2 +- include/media/videobuf2-core.h | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-)
drivers/media/common/videobuf2/videobuf2-core.c +8 -10
@@ -1368,23 +1368,21 @@ bool vb2_request_object_is_buffer(struct media_request_object *obj) }EXPORT_SYMBOL_GPL (vb2_request_object_is_buffer); -bool vb2_request_has_buffers (struct media_request *req) +unsigned int vb2_request_buffer_cnt (struct media_request *req) {struct media_request_object *obj;unsigned long flags; -bool has_buffers = false; +unsigned int buffer_cnt =0 ;spin_lock_irqsave (&req->lock, flags); -list_for_each_entry (obj, &req->objects, list) { -if (vb2_request_object_is_buffer (obj)) { - has_buffers = true; -break ; - } - } +list_for_each_entry (obj, &req->objects, list) +if (vb2_request_object_is_buffer (obj)) + buffer_cnt++;spin_unlock_irqrestore (&req->lock, flags); -return has_buffers; + +return buffer_cnt; } -EXPORT_SYMBOL_GPL (vb2_request_has_buffers); +EXPORT_SYMBOL_GPL (vb2_request_buffer_cnt);int vb2_core_prepare_buf (struct vb2_queue *q,unsigned int index,void *pb) {
drivers/media/common/videobuf2/videobuf2-v4l2.c +1 -1
@@ -1139,7 +1139,7 @@ int vb2_request_validate(struct media_request *req)struct media_request_object *obj;int ret =0 ; -if (!vb2_request_has_buffers (req)) +if (!vb2_request_buffer_cnt (req))return -ENOENT ;list_for_each_entry (obj, &req->objects, list) {
include/media/videobuf2-core.h +2 -2
@@ -1191,10 +1191,10 @@ int vb2_verify_memory_type(struct vb2_queue *q,bool vb2_request_object_is_buffer (struct media_request_object *obj);/** -* vb2_request_has_buffers() - return true if the request contains buffers +* vb2_request_buffer_cnt() - return the number of buffers in the request * * @req: the request. */ -bool vb2_request_has_buffers (struct media_request *req); +unsigned int vb2_request_buffer_cnt (struct media_request *req);#endif /* _MEDIA_VIDEOBUF2_CORE_H */
Signature · 1 line
2.17.1
PATCH v10 2/5 media: v4l: Add definitions for MPEG-2 slice format and metadata
In reply to Maxime RipardFrom: Paul Kocialkowski <[email protected]>
Stateless video decoding engines require both the MPEG-2 slices and associated metadata from the video stream in order to decode frames.
This introduces definitions for a new pixel format, describing buffers with MPEG-2 slice data, as well as control structure sfor passing the frame metadata to drivers.
This is based on work from both Florent Revest and Hugues Fruchet.
--- .../media/uapi/v4l/extended-controls.rst | 176 ++++++++++++++++++ .../media/uapi/v4l/pixfmt-compressed.rst | 16 ++ .../media/uapi/v4l/vidioc-queryctrl.rst | 14 +- .../media/videodev2.h.rst.exceptions | 2 + drivers/media/v4l2-core/v4l2-ctrls.c | 63 +++++++ drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/media/v4l2-ctrls.h | 18 +- include/uapi/linux/v4l2-controls.h | 65 +++++++ include/uapi/linux/videodev2.h | 5 + 9 files changed, 351 insertions(+), 9 deletions(-)
Documentation/media/uapi/v4l/extended-controls.rst +176 -0
@@ -1497,6 +1497,182 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type - +.. _v4l2-mpeg-mpeg2: + +``V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS (struct)`` + Specifies the slice parameters (as extracted from the bitstream) for the + associated MPEG-2 slice data. This includes the necessary parameters for + configuring a stateless hardware decoding pipeline for MPEG-2. + The bitstream parameters are defined according to :ref:`mpeg2part2`. + +.. c:type:: v4l2_ctrl_mpeg2_slice_params + +.. cssclass:: longtable + +.. flat-table:: struct v4l2_ctrl_mpeg2_slice_params + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - __u32 + - ``bit_size`` + - Size (in bits) of the current slice data. + * - __u32 + - ``data_bit_offset`` + - Offset (in bits) to the video data in the current slice data. + * - struct :c:type:`v4l2_mpeg2_sequence` + - ``sequence`` + - Structure with MPEG-2 sequence metadata, merging relevant fields from + the sequence header and sequence extension parts of the bitstream. + * - struct :c:type:`v4l2_mpeg2_picture` + - ``picture`` + - Structure with MPEG-2 picture metadata, merging relevant fields from + the picture header and picture coding extension parts of the bitstream. + * - __u8 + - ``quantiser_scale_code`` + - Code used to determine the quantization scale to use for the IDCT. + * - __u8 + - ``backward_ref_index`` + - Index for the V4L2 buffer to use as backward reference, used with + B-coded and P-coded frames. + * - __u8 + - ``forward_ref_index`` + - Index for the V4L2 buffer to use as forward reference, used with + B-coded frames. + +.. c:type:: v4l2_mpeg2_sequence + +.. cssclass:: longtable + +.. flat-table:: struct v4l2_mpeg2_sequence + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - __u16 + - ``horizontal_size`` + - The width of the displayable part of the frame's luminance component. + * - __u16 + - ``vertical_size`` + - The height of the displayable part of the frame's luminance component. + * - __u32 + - ``vbv_buffer_size`` + - Used to calculate the required size of the video buffering verifier, + defined (in bits) as: 16 * 1024 * vbv_buffer_size. + * - __u8 + - ``profile_and_level_indication`` + - The current profile and level indication as extracted from the + bitstream. + * - __u8 + - ``progressive_sequence`` + - Indication that all the frames for the sequence are progressive instead + of interlaced. + * - __u8 + - ``chroma_format`` + - The chrominance sub-sampling format (1: 4:2:0, 2: 4:2:2, 3: 4:4:4). + +.. c:type:: v4l2_mpeg2_picture + +.. cssclass:: longtable + +.. flat-table:: struct v4l2_mpeg2_picture + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - __u8 + - ``picture_coding_type`` + - Picture coding type for the frame covered by the current slice + (V4L2_MPEG2_PICTURE_CODING_TYPE_I, V4L2_MPEG2_PICTURE_CODING_TYPE_P or + V4L2_MPEG2_PICTURE_CODING_TYPE_B). + * - __u8 + - ``f_code[2][2]`` + - Motion vector codes. + * - __u8 + - ``intra_dc_precision`` + - Precision of Discrete Cosine transform (0: 8 bits precision, + 1: 9 bits precision, 2: 10 bits precision, 3: 11 bits precision). + * - __u8 + - ``picture_structure`` + - Picture structure (1: interlaced top field, 2: interlaced bottom field, + 3: progressive frame). + * - __u8 + - ``top_field_first`` + - If set to 1 and interlaced stream, top field is output first. + * - __u8 + - ``frame_pred_frame_dct`` + - If set to 1, only frame-DCT and frame prediction are used. + * - __u8 + - ``concealment_motion_vectors`` + - If set to 1, motion vectors are coded for intra macroblocks. + * - __u8 + - ``q_scale_type`` + - This flag affects the inverse quantization process. + * - __u8 + - ``intra_vlc_format`` + - This flag affects the decoding of transform coefficient data. + * - __u8 + - ``alternate_scan`` + - This flag affects the decoding of transform coefficient data. + * - __u8 + - ``repeat_first_field`` + - This flag affects the decoding process of progressive frames. + * - __u8 + - ``progressive_frame`` + - Indicates whether the current frame is progressive. + +``V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION (struct)`` + Specifies quantization matrices (as extracted from the bitstream) for the + associated MPEG-2 slice data. + +.. c:type:: v4l2_ctrl_mpeg2_quantization + +.. cssclass:: longtable + +.. flat-table:: struct v4l2_ctrl_mpeg2_quantization + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - __u8 + - ``load_intra_quantiser_matrix`` + - One bit to indicate whether to load the ``intra_quantiser_matrix`` data. + * - __u8 + - ``load_non_intra_quantiser_matrix`` + - One bit to indicate whether to load the ``non_intra_quantiser_matrix`` + data. + * - __u8 + - ``load_chroma_intra_quantiser_matrix`` + - One bit to indicate whether to load the + ``chroma_intra_quantiser_matrix`` data, only relevant for non-4:2:0 YUV + formats. + * - __u8 + - ``load_chroma_non_intra_quantiser_matrix`` + - One bit to indicate whether to load the + ``chroma_non_intra_quantiser_matrix`` data, only relevant for non-4:2:0 + YUV formats. + * - __u8 + - ``intra_quantiser_matrix[64]`` + - The quantization matrix coefficients for intra-coded frames, in zigzag + scanning order. It is relevant for both luma and chroma components, + although it can be superseded by the chroma-specific matrix for + non-4:2:0 YUV formats. + * - __u8 + - ``non_intra_quantiser_matrix[64]`` + - The quantization matrix coefficients for non-intra-coded frames, in + zigzag scanning order. It is relevant for both luma and chroma + components, although it can be superseded by the chroma-specific matrix + for non-4:2:0 YUV formats. + * - __u8 + - ``chroma_intra_quantiser_matrix[64]`` + - The quantization matrix coefficients for the chominance component of + intra-coded frames, in zigzag scanning order. Only relevant for + non-4:2:0 YUV formats. + * - __u8 + - ``chroma_non_intra_quantiser_matrix[64]`` + - The quantization matrix coefficients for the chrominance component of + non-intra-coded frames, in zigzag scanning order. Only relevant for + non-4:2:0 YUV formats. MFC 5.1 MPEG Controls ---------------------
Documentation/media/uapi/v4l/pixfmt-compressed.rst +16 -0
@@ -60,6 +60,22 @@ Compressed Formats - ``V4L2_PIX_FMT_MPEG2`` - 'MPG2' - MPEG2 video elementary stream. + * .. _V4L2-PIX-FMT-MPEG2-SLICE: + + - ``V4L2_PIX_FMT_MPEG2_SLICE`` + - 'MG2S' + - MPEG-2 parsed slice data, as extracted from the MPEG-2 bitstream. + This format is adapted for stateless video decoders that implement a + MPEG-2 pipeline (using the :ref:`codec` and :ref:`media-request-api`). + Metadata associated with the frame to decode is required to be passed + through the ``V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS`` control and + quantization matrices can optionally be specified through the + ``V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION`` control. + See the :ref:`associated Codec Control IDs <v4l2-mpeg-mpeg2>`. + Exactly one output and one capture buffer must be provided for use with + this pixel format. The output buffer must contain the appropriate number + of macroblocks to decode a full corresponding frame to the matching + capture buffer. * .. _V4L2-PIX-FMT-MPEG4: - ``V4L2_PIX_FMT_MPEG4``
Documentation/media/uapi/v4l/vidioc-queryctrl.rst +12 -2
@@ -424,8 +424,18 @@ See also the examples in :ref:`control`. - any - An unsigned 32-bit valued control ranging from minimum to maximum inclusive. The step value indicates the increment between values. - - + * - ``V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS`` + - n/a + - n/a + - n/a + - A struct :c:type:`v4l2_ctrl_mpeg2_slice_params`, containing MPEG-2 + slice parameters for stateless video decoders. + * - ``V4L2_CTRL_TYPE_MPEG2_QUANTIZATION`` + - n/a + - n/a + - n/a + - A struct :c:type:`v4l2_ctrl_mpeg2_quantization`, containing MPEG-2 + quantization matrices for stateless video decoders. .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
Documentation/media/videodev2.h.rst.exceptions +2 -0
@@ -129,6 +129,8 @@ replace symbol V4L2_CTRL_TYPE_STRING :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_U16 :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_U32 :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_U8 :c:type:`v4l2_ctrl_type` +replace symbol V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS :c:type:`v4l2_ctrl_type` +replace symbol V4L2_CTRL_TYPE_MPEG2_QUANTIZATION :c:type:`v4l2_ctrl_type` # V4L2 capability defines replace define V4L2_CAP_VIDEO_CAPTURE device-capabilities
drivers/media/v4l2-core/v4l2-ctrls.c +63 -0
93 lines not on this page · raw message
drivers/media/v4l2-core/v4l2-ioctl.c +1 -0
@@ -1309,6 +1309,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_H263 : descr ="H.263" ;break ;case V4L2_PIX_FMT_MPEG1 : descr ="MPEG-1 ES" ;break ;case V4L2_PIX_FMT_MPEG2 : descr ="MPEG-2 ES" ;break ; +case V4L2_PIX_FMT_MPEG2_SLICE : descr ="MPEG-2 Parsed Slice Data" ;break ;case V4L2_PIX_FMT_MPEG4 : descr ="MPEG-4 part 2 ES" ;break ;case V4L2_PIX_FMT_XVID : descr ="Xvid" ;break ;case V4L2_PIX_FMT_VC1_ANNEX_G : descr ="VC-1 (SMPTE 412M Annex G)" ;break ;
include/media/v4l2-ctrls.h +11 -7
@@ -35,13 +35,15 @@ struct poll_table_struct;/** * union v4l2_ctrl_ptr - A pointer to a control value. -* @p_s32: Pointer to a 32-bit signed value. -* @p_s64: Pointer to a 64-bit signed value. -* @p_u8: Pointer to a 8-bit unsigned value. -* @p_u16: Pointer to a 16-bit unsigned value. -* @p_u32: Pointer to a 32-bit unsigned value. -* @p_char: Pointer to a string. -* @p: Pointer to a compound value. +* @p_s32: Pointer to a 32-bit signed value. +* @p_s64: Pointer to a 64-bit signed value. +* @p_u8: Pointer to a 8-bit unsigned value. +* @p_u16: Pointer to a 16-bit unsigned value. +* @p_u32: Pointer to a 32-bit unsigned value. +* @p_char: Pointer to a string. +* @p_mpeg2_slice_params: Pointer to a MPEG2 slice parameters structure. +* @p_mpeg2_quantization: Pointer to a MPEG2 quantization data structure. +* @p: Pointer to a compound value. */ union v4l2_ctrl_ptr {s32 *p_s32;
@@ -50,6 +52,8 @@ union v4l2_ctrl_ptr {u16 *p_u16;u32 *p_u32;char *p_char; +struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params; +struct v4l2_ctrl_mpeg2_quantization *p_mpeg2_quantization;void *p; };
include/uapi/linux/v4l2-controls.h +65 -0
75 lines not on this page · raw message
include/uapi/linux/videodev2.h +5 -0
@@ -635,6 +635,7 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3')/* H263 */ #define V4L2_PIX_FMT_MPEG1 v4l2_fourcc('M', 'P', 'G', '1')/* MPEG-1 ES */ #define V4L2_PIX_FMT_MPEG2 v4l2_fourcc('M', 'P', 'G', '2')/* MPEG-2 ES */ +#define V4L2_PIX_FMT_MPEG2_SLICE v4l2_fourcc('M', 'G', '2', 'S')/* MPEG-2 parsed slice data */ #define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4')/* MPEG-4 part 2 ES */ #define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D')/* Xvid */ #define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G')/* SMPTE 421M Annex G compliant stream */
@@ -1608,6 +1609,8 @@ struct v4l2_ext_control {__u8 __user *p_u8;__u16 __user *p_u16;__u32 __user *p_u32; +struct v4l2_ctrl_mpeg2_slice_params __user *p_mpeg2_slice_params; +struct v4l2_ctrl_mpeg2_quantization __user *p_mpeg2_quantization;void __user *ptr; }; } __attribute__ ((packed));
@@ -1653,6 +1656,8 @@ enum v4l2_ctrl_type {V4L2_CTRL_TYPE_U8 =0x0100 ,V4L2_CTRL_TYPE_U16 =0x0101 ,V4L2_CTRL_TYPE_U32 =0x0102 , +V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS =0x0103 , + V4L2_CTRL_TYPE_MPEG2_QUANTIZATION = 0x0104, };/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
Signature · 1 line
2.17.1
PATCH v10 3/5 media: v4l: Add definition for the Sunxi tiled NV12 format
In reply to Maxime RipardFrom: Paul Kocialkowski <[email protected]>
This introduces support for the Sunxi tiled NV12 format, where each component of the YUV frame is divided into macroblocks. Hence, the size of each plane requires specific alignment. The pixels inside each macroblock are coded in linear order (line after line from top to bottom).
This tiled NV12 format is used by the video engine on Allwinner
platforms: it is the default format for decoded frames (and the only one available in the oldest supported platforms).
--- Documentation/media/uapi/v4l/pixfmt-reserved.rst | 13 +++++++++++++ drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/uapi/linux/videodev2.h | 1 + 3 files changed, 15 insertions(+)
Documentation/media/uapi/v4l/pixfmt-reserved.rst +13 -0
@@ -243,7 +243,20 @@ please make a proposal on the linux-media mailing list. It is an opaque intermediate format and the MDP hardware must be used to convert ``V4L2_PIX_FMT_MT21C`` to ``V4L2_PIX_FMT_NV12M``, ``V4L2_PIX_FMT_YUV420M`` or ``V4L2_PIX_FMT_YVU420``. + * .. _V4L2-PIX-FMT-SUNXI-TILED-NV12: + - ``V4L2_PIX_FMT_SUNXI_TILED_NV12`` + - 'ST12' + - Two-planar NV12-based format used by the video engine found on Allwinner + (codenamed sunxi) platforms, with 32x32 tiles for the luminance plane + and 32x64 tiles for the chrominance plane. The data in each tile is + stored in linear order, within the tile bounds. Each tile follows the + previous one linearly in memory (from left to right, top to bottom). + + The associated buffer dimensions are aligned to match an integer number + of tiles, resulting in 32-aligned resolutions for the luminance plane + and 16-aligned resolutions for the chrominance plane (with 2x2 + subsampling). .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
drivers/media/v4l2-core/v4l2-ioctl.c +1 -0
@@ -1337,6 +1337,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SE401 : descr ="GSPCA SE401" ;break ;case V4L2_PIX_FMT_S5C_UYVY_JPG : descr ="S5C73MX interleaved UYVY/JPEG" ;break ;case V4L2_PIX_FMT_MT21C : descr ="Mediatek Compressed Format" ;break ; +case V4L2_PIX_FMT_SUNXI_TILED_NV12 : descr ="Sunxi Tiled NV12 Format" ;break ;default :WARN (1 ,"Unknown pixelformat 0x%08x\n" , fmt->pixelformat);if (fmt->description[0 ])
include/uapi/linux/videodev2.h +1 -0
@@ -677,6 +677,7 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ')/* Depth data 16-bit */ #define V4L2_PIX_FMT_MT21C v4l2_fourcc('M', 'T', '2', '1')/* Mediatek compressed block mode */ #define V4L2_PIX_FMT_INZI v4l2_fourcc('I', 'N', 'Z', 'I')/* Intel Planar Greyscale 10-bit and Depth 16-bit */ +#define V4L2_PIX_FMT_SUNXI_TILED_NV12 v4l2_fourcc('S', 'T', '1', '2')/* Sunxi Tiled NV12 Format */ /* 10bit raw bayer packed, 32 bytes for every 25 pixels, last LSB 6 bits unused */ #define V4L2_PIX_FMT_IPU3_SBGGR10 v4l2_fourcc('i', 'p', '3', 'b')/* IPU3 packed 10-bit BGGR bayer */
Signature · 1 line
2.17.1
PATCH v10 4/5 dt-bindings: media: Document bindings for the Cedrus VPU driver
In reply to Maxime RipardFrom: Paul Kocialkowski <[email protected]>
This adds a device-tree binding document that specifies the properties used by the Cedrus VPU driver, as well as examples.
--- .../devicetree/bindings/media/cedrus.txt | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/cedrus.txt
Documentation/devicetree/bindings/media/cedrus.txt new file +54 -0
@@ -0,0 +1,54 @@ +Device-tree bindings for the VPU found in Allwinner SoCs, referred to as the +Video Engine (VE) in Allwinner literature. + +The VPU can only access the first 256 MiB of DRAM, that are DMA-mapped starting +from the DRAM base. This requires specific memory allocation and handling. + +Required properties: +- compatible : must be one of the following compatibles: + - "allwinner,sun4i-a10-video-engine" + - "allwinner,sun5i-a13-video-engine" + - "allwinner,sun7i-a20-video-engine" + - "allwinner,sun8i-a33-video-engine" + - "allwinner,sun8i-h3-video-engine" +- reg : register base and length of VE; +- clocks : list of clock specifiers, corresponding to entries in + the clock-names property; +- clock-names : should contain "ahb", "mod" and "ram" entries; +- resets : phandle for reset; +- interrupts : VE interrupt number; +- allwinner,sram : SRAM region to use with the VE. + +Optional properties: +- memory-region : CMA pool to use for buffers allocation instead of the + default CMA pool. + +Example: + +reserved-memory { + #address-cells = <1>; + #size-cells = <1>; + ranges; + + /* Address must be kept in the lower 256 MiBs of DRAM for VE. */ + cma_pool: cma@4a000000 { + compatible = "shared-dma-pool"; + size = <0x6000000>; + alloc-ranges = <0x4a000000 0x6000000>; + reusable; + linux,cma-default; + }; +}; + +video-codec@1c0e000 { + compatible = "allwinner,sun7i-a20-video-engine"; + reg = <0x01c0e000 0x1000>; + + clocks = <&ccu CLK_AHB_VE>, <&ccu CLK_VE>, + <&ccu CLK_DRAM_VE>; + clock-names = "ahb", "mod", "ram"; + + resets = <&ccu RST_VE>; + interrupts = <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>; + allwinner,sram = <&ve_sram 1>; +};
Signature · 1 line
2.17.1
PATCH v10 5/5 media: platform: Add Cedrus VPU decoder driver
In reply to Maxime RipardFrom: Paul Kocialkowski <[email protected]>
This introduces the Cedrus VPU driver that supports the VPU found in Allwinner SoCs, also known as Video Engine. It is implemented through a V4L2 M2M decoder device and a media device (used for media requests). So far, it only supports MPEG-2 decoding.
Since this VPU is stateless, synchronization with media requests is required in order to ensure consistency between frame headers that contain metadata about the frame to process and the raw slice data that is used to generate the frame.
This driver was made possible thanks to the long-standing effort carried out by the linux-sunxi community in the interest of reverse engineering, documenting and implementing support for the Allwinner VPU.
--- MAINTAINERS | 7 + drivers/staging/media/Kconfig | 2 + drivers/staging/media/Makefile | 1 + drivers/staging/media/sunxi/Kconfig | 15 + drivers/staging/media/sunxi/Makefile | 1 + drivers/staging/media/sunxi/cedrus/Kconfig | 14 + drivers/staging/media/sunxi/cedrus/Makefile | 3 + drivers/staging/media/sunxi/cedrus/TODO | 7 + drivers/staging/media/sunxi/cedrus/cedrus.c | 431 ++++++++++++++ drivers/staging/media/sunxi/cedrus/cedrus.h | 167 ++++++ .../staging/media/sunxi/cedrus/cedrus_dec.c | 70 +++ .../staging/media/sunxi/cedrus/cedrus_dec.h | 27 + .../staging/media/sunxi/cedrus/cedrus_hw.c | 327 +++++++++++ .../staging/media/sunxi/cedrus/cedrus_hw.h | 30 + .../staging/media/sunxi/cedrus/cedrus_mpeg2.c | 246 ++++++++ .../staging/media/sunxi/cedrus/cedrus_regs.h | 235 ++++++++ .../staging/media/sunxi/cedrus/cedrus_video.c | 542 ++++++++++++++++++ .../staging/media/sunxi/cedrus/cedrus_video.h | 30 + 18 files changed, 2155 insertions(+) create mode 100644 drivers/staging/media/sunxi/Kconfig create mode 100644 drivers/staging/media/sunxi/Makefile create mode 100644 drivers/staging/media/sunxi/cedrus/Kconfig create mode 100644 drivers/staging/media/sunxi/cedrus/Makefile create mode 100644 drivers/staging/media/sunxi/cedrus/TODO create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus.h create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_dec.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_dec.h create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_hw.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_hw.h create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_regs.h create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_video.c create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_video.h
MAINTAINERS +7 -0
@@ -663,6 +663,13 @@ L: [email protected] S: Maintained F: drivers/crypto/sunxi-ss/ +ALLWINNER VPU DRIVER +M: Maxime Ripard <[email protected]> +M: Paul Kocialkowski <[email protected]> +L: [email protected] +S: Maintained +F: drivers/staging/media/sunxi/cedrus/ + ALPHA PORT M: Richard Henderson <[email protected]> M: Ivan Kokshaysky <[email protected]>
drivers/staging/media/Kconfig +2 -0
@@ -31,6 +31,8 @@ source "drivers/staging/media/mt9t031/Kconfig" source "drivers/staging/media/omap4iss/Kconfig" +source "drivers/staging/media/sunxi/Kconfig" + source "drivers/staging/media/tegra-vde/Kconfig" source "drivers/staging/media/zoran/Kconfig"
drivers/staging/media/Makefile +1 -0
@@ -5,5 +5,6 @@ obj-$(CONFIG_SOC_CAMERA_IMX074) += imx074/ obj-$(CONFIG_SOC_CAMERA_MT9T031) += mt9t031/ obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/ obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/ +obj-$(CONFIG_VIDEO_SUNXI) += sunxi/ obj-$(CONFIG_TEGRA_VDE) += tegra-vde/ obj-$(CONFIG_VIDEO_ZORAN) += zoran/
drivers/staging/media/sunxi/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +config VIDEO_SUNXI + bool "Allwinner sunXi family Video Devices" + depends on ARCH_SUNXI || COMPILE_TEST + help + If you have an Allwinner SoC based on the sunXi family, say Y. + + Note that this option doesn't include new drivers in the + kernel: saying N will just cause Kconfig to skip all the + questions about Allwinner media devices. + +if VIDEO_SUNXI + +source "drivers/staging/media/sunxi/cedrus/Kconfig" + +endif
drivers/staging/media/sunxi/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_VIDEO_SUNXI_CEDRUS) += cedrus/
drivers/staging/media/sunxi/cedrus/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +config VIDEO_SUNXI_CEDRUS + tristate "Allwinner Cedrus VPU driver" + depends on VIDEO_DEV && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on HAS_DMA + depends on OF + select SUNXI_SRAM + select VIDEOBUF2_DMA_CONTIG + select V4L2_MEM2MEM_DEV + help + Support for the VPU found in Allwinner SoCs, also known as the Cedar + video engine. + + To compile this driver as a module, choose M here: the module + will be called sunxi-cedrus.
drivers/staging/media/sunxi/cedrus/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_VIDEO_SUNXI_CEDRUS) += sunxi-cedrus.o + +sunxi-cedrus-y = cedrus.o cedrus_video.o cedrus_hw.o cedrus_dec.o cedrus_mpeg2.o
drivers/staging/media/sunxi/cedrus/TODO new file +7 -0
@@ -0,0 +1,7 @@ +Before this stateless decoder driver can leave the staging area: +* The Request API needs to be stabilized; +* The codec-specific controls need to be thoroughly reviewed to ensure they + cover all intended uses cases; +* Userspace support for the Request API needs to be reviewed; +* Another stateless decoder driver should be submitted; +* At least one stateless encoder driver should be submitted.
drivers/staging/media/sunxi/cedrus/cedrus.c new file +431 -0
431 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus.h new file +167 -0
167 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus_dec.c new file +70 -0
70 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus_dec.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Cedrus VPU driver +* +* Copyright (C) 2016 Florent Revest <[email protected]> +* Copyright (C) 2018 Paul Kocialkowski <[email protected]> +* Copyright (C) 2018 Bootlin +* +* Based on the vim2m driver, that is: +* +* Copyright (c) 2009-2010 Samsung Electronics Co., Ltd. +* Pawel Osciak, <[email protected]> +* Marek Szyprowski, <[email protected]> +*/ + +#ifndef _CEDRUS_DEC_H_ +#define _CEDRUS_DEC_H_ + +extern const struct v4l2_ioctl_ops cedrus_ioctl_ops; + +void cedrus_device_work (struct work_struct *work); +void cedrus_device_run (void *priv); + +int cedrus_queue_init (void *priv,struct vb2_queue *src_vq, +struct vb2_queue *dst_vq); + +#endif
drivers/staging/media/sunxi/cedrus/cedrus_hw.c new file +327 -0
327 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus_hw.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Cedrus VPU driver +* +* Copyright (C) 2016 Florent Revest <[email protected]> +* Copyright (C) 2018 Paul Kocialkowski <[email protected]> +* Copyright (C) 2018 Bootlin +* +* Based on the vim2m driver, that is: +* +* Copyright (c) 2009-2010 Samsung Electronics Co., Ltd. +* Pawel Osciak, <[email protected]> +* Marek Szyprowski, <[email protected]> +*/ + +#ifndef _CEDRUS_HW_H_ +#define _CEDRUS_HW_H_ + +#define CEDRUS_CLOCK_RATE_DEFAULT 320000000 + +int cedrus_engine_enable (struct cedrus_dev *dev,enum cedrus_codec codec); +void cedrus_engine_disable (struct cedrus_dev *dev); + +void cedrus_dst_format_set (struct cedrus_dev *dev, +struct v4l2_pix_format *fmt); + +int cedrus_hw_probe (struct cedrus_dev *dev); +void cedrus_hw_remove (struct cedrus_dev *dev); + +#endif
drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c new file +246 -0
246 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus_regs.h new file +235 -0
235 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus_video.c new file +542 -0
542 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus_video.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Cedrus VPU driver +* +* Copyright (C) 2016 Florent Revest <[email protected]> +* Copyright (C) 2018 Paul Kocialkowski <[email protected]> +* Copyright (C) 2018 Bootlin +* +* Based on the vim2m driver, that is: +* +* Copyright (c) 2009-2010 Samsung Electronics Co., Ltd. +* Pawel Osciak, <[email protected]> +* Marek Szyprowski, <[email protected]> +*/ + +#ifndef _CEDRUS_VIDEO_H_ +#define _CEDRUS_VIDEO_H_ + +struct cedrus_format { +u32 pixelformat; +u32 directions; +unsigned int capabilities; +}; + +extern const struct v4l2_ioctl_ops cedrus_ioctl_ops; + +int cedrus_queue_init (void *priv,struct vb2_queue *src_vq, +struct vb2_queue *dst_vq); + +#endif
Signature · 1 line
2.17.1