media: adds the feature of the amvdec ports are based on v4l2.[1/2]
authorNanxin Qin <nanxin.qin@amlogic.com>
Mon, 29 Jan 2018 10:06:33 +0000 (18:06 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Mon, 9 Jul 2018 07:40:09 +0000 (00:40 -0700)
PD#153299:
1. amports has v4l for video decoding implemented upstream.
2. Only the decoding of h264 has been implemented at the moment.
3. the maximun resolution supports 1080p currently.
4. it is nv12 that the canvas data format of the decoder output.
5. the detailed description can be referred to wiki.
wiki: Media/The_V4L2_Amvdec_Ports_Instructions

Change-Id: Ie19311e1f44ae53b491500be9903f3d82c83b800
Signed-off-by: Nanxin Qin <nanxin.qin@amlogic.com>
arch/arm64/boot/dts/amlogic/mesong12a.dtsi
arch/arm64/boot/dts/amlogic/mesongxl.dtsi
arch/arm64/boot/dts/amlogic/mesongxm.dtsi
arch/arm64/boot/dts/amlogic/mesontxlx.dtsi
drivers/amlogic/media/common/codec_mm/codec_mm.c
drivers/amlogic/media/common/v4l_util/Kconfig
include/linux/amlogic/media/codec_mm/codec_mm.h
include/linux/amlogic/media/utils/amstream.h
include/linux/amlogic/media/vfm/vframe.h

index 9f8f293558108f46e1931febfd7d5c80ae6d03c1..0d752d9e9587c5332deab5a1a9a76d38ff8e55d1 100644 (file)
                        "mailbox_2";
        };
 
+       vcodec_dec {
+               compatible = "amlogic, vcodec-dec";
+               dev_name = "aml-vcodec-dec";
+               status = "okay";
+       };
+
        amvenc_avc{
                compatible = "amlogic, amvenc_avc";
                dev_name = "amvenc_avc";
index 509953c35fb30016cf3c300bb004730eb722d347..05b0e8dda810241bf32513c47c0f17c80c451687 100644 (file)
                reserve_mem_size = <0x00300000>;
        };
 
+       vcodec_dec {
+               compatible = "amlogic, vcodec-dec";
+               dev_name = "aml-vcodec-dec";
+               status = "okay";
+       };
+
        securitykey {
                compatible = "aml, securitykey";
                storage_query = <0x82000060>;
index 31586260b341a9c22a3b8e516cb96bbb1ef56418..3cb75c8156d64a01df6f4e357beb0ff99cdc4e2e 100644 (file)
                reserve_mem_size = <0x00300000>;
        };
 
+       vcodec_dec {
+               compatible = "amlogic, vcodec-dec";
+               dev_name = "aml-vcodec-dec";
+               status = "okay";
+       };
+
        securitykey {
                compatible = "aml, securitykey";
                storage_query = <0x82000060>;
index 0d6a78c99fb492ccafb06d5e894a5d5648130a1f..f56dc75cf0878c9f15a5cad9d347f391aa70b909 100644 (file)
                reserve_mem_size = <0x00300000>;
        };
 
+       vcodec_dec {
+               compatible = "amlogic, vcodec-dec";
+               dev_name = "aml-vcodec-dec";
+               status = "okay";
+       };
+
        securitykey {
                compatible = "aml, securitykey";
                status = "okay";
index e6665d306ad2f9102a2bd775c89cdf9d6d9a7bfe..5646d85392aacff8714998750fb8ba9cf33ee39a 100644 (file)
@@ -137,6 +137,7 @@ struct codec_mm_mgt_s {
        int alloced_sys_size;
        int alloced_for_sc_size;
        int alloced_for_sc_cnt;
+       int alloced_from_coherent;
 
        int alloc_from_sys_pages_max;
        int enable_kmalloc_on_nomem;
@@ -1352,6 +1353,83 @@ int codec_mm_get_reserved_size(void)
 }
 EXPORT_SYMBOL(codec_mm_get_reserved_size);
 
+struct device *v4l_get_dev_from_codec_mm(void)
+{
+       struct codec_mm_mgt_s *mgt = get_mem_mgt();
+
+       return mgt->dev;
+}
+EXPORT_SYMBOL(v4l_get_dev_from_codec_mm);
+
+struct codec_mm_s *v4l_reqbufs_from_codec_mm(const char *owner,
+       unsigned int addr, unsigned int size, unsigned int index)
+{
+       unsigned long flags;
+       struct codec_mm_mgt_s *mgt = get_mem_mgt();
+       struct codec_mm_s *mem = NULL;
+       int buf_size = PAGE_ALIGN(size);
+
+       mem = kzalloc(sizeof(struct codec_mm_s), GFP_KERNEL);
+       if (IS_ERR_OR_NULL(mem))
+               goto out;
+
+       mem->owner[0]    = owner;
+       mem->mem_handle  = NULL;
+       mem->buffer_size = buf_size;
+       mem->page_count  = buf_size / PAGE_SIZE;
+       mem->phy_addr    = addr;
+       mem->ins_buffer_id = index;
+       mem->alloced_jiffies = get_jiffies_64();
+       mem->from_flags
+               = AMPORTS_MEM_FLAGS_FROM_GET_FROM_COHERENT;
+
+       spin_lock_irqsave(&mgt->lock, flags);
+
+       mem->mem_id = mgt->global_memid++;
+       mgt->alloced_from_coherent += buf_size;
+       mgt->total_alloced_size += buf_size;
+       mgt->alloced_cma_size += buf_size;
+       list_add_tail(&mem->list, &mgt->mem_list);
+
+       spin_unlock_irqrestore(&mgt->lock, flags);
+
+       if (debug_mode & 0x20)
+               pr_info("%s alloc coherent size %d at %lx from %d.\n",
+                       owner, buf_size, mem->phy_addr, mem->from_flags);
+out:
+       return mem;
+}
+EXPORT_SYMBOL(v4l_reqbufs_from_codec_mm);
+
+void v4l_freebufs_back_to_codec_mm(const char *owner, struct codec_mm_s *mem)
+{
+       unsigned long flags;
+       struct codec_mm_mgt_s *mgt = get_mem_mgt();
+
+       if (IS_ERR_OR_NULL(mem))
+               return;
+
+       if (!mem->owner[0] || strcmp(owner, mem->owner[0]) ||
+               !mem->buffer_size)
+               goto out;
+
+       spin_lock_irqsave(&mgt->lock, flags);
+
+       mgt->alloced_from_coherent -= mem->buffer_size;
+       mgt->total_alloced_size -= mem->buffer_size;
+       mgt->alloced_cma_size -= mem->buffer_size;
+       list_del(&mem->list);
+
+       spin_unlock_irqrestore(&mgt->lock, flags);
+
+       if (debug_mode & 0x20)
+               pr_info("%s free mem size %d at %lx from %d\n", mem->owner[0],
+                       mem->buffer_size, mem->phy_addr, mem->from_flags);
+out:
+       kfree(mem);
+}
+EXPORT_SYMBOL(v4l_freebufs_back_to_codec_mm);
+
 /*
  *with_wait:
  *1: if no mem, do wait and free some cache.
@@ -1916,7 +1994,7 @@ static int codec_mm_probe(struct platform_device *pdev)
        if (r == 0)
                pr_debug("codec_mm reserved memory probed done\n");
 
-       pr_debug("codec_mm_probe ok\n");
+       pr_info("codec_mm_probe ok\n");
 
        codec_mm_scatter_mgt_init();
        codec_mm_keeper_mgr_init();
index 69324b3ab27c1652de9283e9c913235b252c4ad4..5511b627ea43c2d6cfca2d03fe44c5e00527a966 100644 (file)
@@ -4,6 +4,8 @@
 
 config AMLOGIC_VIDEOBUF_RESOURCE
        bool "Amlogic V4L UTIL Support"
+       select VIDEOBUF2_DMA_CONTIG
+       select V4L2_MEM2MEM_DEV
        default n
        help
                Select to enable V4L UTIL support
index 5de94ec81fdbf4f766d5a8d84ebe7083051b092d..8f71042a1307a5b34f09e7ffa8ac2dfe4e4c7832 100644 (file)
@@ -96,6 +96,7 @@ struct codec_mm_s {
 #define AMPORTS_MEM_FLAGS_FROM_GET_FROM_CMA 4
 #define AMPORTS_MEM_FLAGS_FROM_GET_FROM_TVP 5
 #define AMPORTS_MEM_FLAGS_FROM_GET_FROM_CMA_RES 6
+#define AMPORTS_MEM_FLAGS_FROM_GET_FROM_COHERENT 7
        int from_flags;
        /*may can be shared on many user..*/
           /*decoder/di/ppmgr,*/
@@ -148,4 +149,10 @@ void *codec_mm_dma_alloc_coherent(const char *owner, int size,
                        dma_addr_t *dma_handle, gfp_t flag, int memflags);
 void codec_mm_dma_free_coherent(const char *owner, int size,
                        void *cpu_addr, dma_addr_t dma_handle, int memflags);
+
+struct device *v4l_get_dev_from_codec_mm(void);
+struct codec_mm_s *v4l_reqbufs_from_codec_mm(const char *owner,
+       unsigned int addr, unsigned int size, unsigned int index);
+void v4l_freebufs_back_to_codec_mm(const char *owner, struct codec_mm_s *mem);
+
 #endif
index f40bdff4ff7bb38aa7b016333f59b708cada69c6..34e650b717f7d9a5488c13d9409d3864b554c69f 100644 (file)
@@ -230,6 +230,7 @@ enum FRAME_BASE_VIDEO_PATH {
        FRAME_BASE_PATH_DI_AMVIDEO,
        FRAME_BASE_PATH_AMVIDEO,
        FRAME_BASE_PATH_AMVIDEO2,
+       FRAME_BASE_PATH_V4L_VIDEO,
        FRAME_BASE_PATH_MAX
 };
 
index 9e53f1e485c9a3f6a7f506c10ec96a59a9bfb1f4..8403e1abdd65dabe15f6a423943c67153cc0f89d 100644 (file)
@@ -75,6 +75,7 @@
 #define VFRAME_FLAG_ERROR_RECOVERY             8
 #define VFRAME_FLAG_SYNCFRAME                  0x10
 #define VFRAME_FLAG_GAME_MODE          0x20
+#define VFRAME_FLAG_EMPTY_FRAME_V4L            0x80
 
 enum pixel_aspect_ratio_e {
        PIXEL_ASPECT_RATIO_1_1,
@@ -256,6 +257,7 @@ struct vframe_s {
        u32 next_vf_pts;
        u32 disp_pts;
        u64 disp_pts_us64;
+       u64 timestamp;
        u32 flag;
 
        u32 canvas0Addr;
@@ -346,6 +348,8 @@ struct vframe_s {
        /*for MMU H265/VP9 compress header*/
        void *mem_head_handle;
        struct vframe_pic_mode_s pic_mode;
+
+       unsigned long v4l_mem_handle;
 } /*vframe_t */;
 
 #if 0