Browse Source

Merge branch 'CR_683_JPU_devel_Andy.Hu' into 'JH7100_VisionFive_devel'

CR_683_jpu_devel

See merge request jh7100/freelight-u-sdk!6
jianlong.huang 2 years ago
parent
commit
7933853dc0
100 changed files with 11516 additions and 0 deletions
  1. 1 0
      conf/buildroot_initramfs_config
  2. 17 0
      soft_3rdpart/codaj12/Android.mk
  3. 169 0
      soft_3rdpart/codaj12/Makefile
  4. BIN
      soft_3rdpart/codaj12/Nieuport_JpgDec
  5. BIN
      soft_3rdpart/codaj12/Nieuport_JpgEnc
  6. 15 0
      soft_3rdpart/codaj12/README.md
  7. 546 0
      soft_3rdpart/codaj12/TestRunnerCodaJ12Dec.sh
  8. 459 0
      soft_3rdpart/codaj12/TestRunnerCodaJ12Enc.sh
  9. 556 0
      soft_3rdpart/codaj12/TestRunnerCodaJ12Multi.sh
  10. 639 0
      soft_3rdpart/codaj12/TestRunnerCommon.sh
  11. 0 0
      soft_3rdpart/codaj12/TestRunnerParamCodaJ12Dec.txt
  12. 0 0
      soft_3rdpart/codaj12/TestRunnerParamCodaJ12Enc.txt
  13. 21 0
      soft_3rdpart/codaj12/build_ffmpeg.sh
  14. 50 0
      soft_3rdpart/codaj12/build_for_riscv.sh
  15. 62 0
      soft_3rdpart/codaj12/cfg/HuffmanTable01.cfg
  16. 84 0
      soft_3rdpart/codaj12/cfg/HuffmanTable01_ES.cfg
  17. 18 0
      soft_3rdpart/codaj12/cfg/QuantTable00.cfg
  18. 18 0
      soft_3rdpart/codaj12/cfg/QuantTable01.cfg
  19. 18 0
      soft_3rdpart/codaj12/cfg/QuantTable02.cfg
  20. 18 0
      soft_3rdpart/codaj12/cfg/QuantTableEX_23.cfg
  21. 32 0
      soft_3rdpart/codaj12/cfg/outI400_qcif_inI400.cfg
  22. 34 0
      soft_3rdpart/codaj12/cfg/outI400_qcif_inI400_12b.cfg
  23. 32 0
      soft_3rdpart/codaj12/cfg/outI400_qcif_inUYVY.cfg
  24. 32 0
      soft_3rdpart/codaj12/cfg/outI400_qcif_inVYUY.cfg
  25. 32 0
      soft_3rdpart/codaj12/cfg/outI400_qcif_inYUYV.cfg
  26. 32 0
      soft_3rdpart/codaj12/cfg/outI400_qcif_inYVYU.cfg
  27. 32 0
      soft_3rdpart/codaj12/cfg/outI420_cif_inNV12.cfg
  28. 32 0
      soft_3rdpart/codaj12/cfg/outI420_cif_inNV12_tiled.cfg
  29. 32 0
      soft_3rdpart/codaj12/cfg/outI420_qcif_inI420.cfg
  30. 34 0
      soft_3rdpart/codaj12/cfg/outI420_qcif_inI420_12b.cfg
  31. 32 0
      soft_3rdpart/codaj12/cfg/outI420_qcif_inNV12.cfg
  32. 32 0
      soft_3rdpart/codaj12/cfg/outI420_qcif_inNV21.cfg
  33. 32 0
      soft_3rdpart/codaj12/cfg/outI420_qcif_inUYVY.cfg
  34. 32 0
      soft_3rdpart/codaj12/cfg/outI420_qcif_inVYUY.cfg
  35. 32 0
      soft_3rdpart/codaj12/cfg/outI420_qcif_inYUYV.cfg
  36. 32 0
      soft_3rdpart/codaj12/cfg/outI420_qcif_inYVYU.cfg
  37. 32 0
      soft_3rdpart/codaj12/cfg/outI422_qcif_inI422.cfg
  38. 34 0
      soft_3rdpart/codaj12/cfg/outI422_qcif_inI422_12b.cfg
  39. 32 0
      soft_3rdpart/codaj12/cfg/outI422_qcif_inNV16.cfg
  40. 32 0
      soft_3rdpart/codaj12/cfg/outI422_qcif_inNV16_tiled.cfg
  41. 32 0
      soft_3rdpart/codaj12/cfg/outI422_qcif_inNV61.cfg
  42. 32 0
      soft_3rdpart/codaj12/cfg/outI422_qcif_inUYVY.cfg
  43. 32 0
      soft_3rdpart/codaj12/cfg/outI422_qcif_inVYUY.cfg
  44. 32 0
      soft_3rdpart/codaj12/cfg/outI422_qcif_inYUYV.cfg
  45. 32 0
      soft_3rdpart/codaj12/cfg/outI422_qcif_inYVYU.cfg
  46. 32 0
      soft_3rdpart/codaj12/cfg/outI440_qcif_in16NV.cfg
  47. 32 0
      soft_3rdpart/codaj12/cfg/outI440_qcif_in61NV.cfg
  48. 32 0
      soft_3rdpart/codaj12/cfg/outI440_qcif_inI440.cfg
  49. 34 0
      soft_3rdpart/codaj12/cfg/outI440_qcif_inI440_12b.cfg
  50. 32 0
      soft_3rdpart/codaj12/cfg/outI440_qcif_inUYVY.cfg
  51. 32 0
      soft_3rdpart/codaj12/cfg/outI440_qcif_inVYUY.cfg
  52. 32 0
      soft_3rdpart/codaj12/cfg/outI440_qcif_inYUYV.cfg
  53. 32 0
      soft_3rdpart/codaj12/cfg/outI440_qcif_inYVYU.cfg
  54. 32 0
      soft_3rdpart/codaj12/cfg/outI444_3840_2160_inI444.cfg
  55. 32 0
      soft_3rdpart/codaj12/cfg/outI444_4608_3456_inI444.cfg
  56. 32 0
      soft_3rdpart/codaj12/cfg/outI444_cif_inNV24.cfg
  57. 32 0
      soft_3rdpart/codaj12/cfg/outI444_cif_inNV24_tiled.cfg
  58. 32 0
      soft_3rdpart/codaj12/cfg/outI444_qcif_inI444.cfg
  59. 32 0
      soft_3rdpart/codaj12/cfg/outI444_qcif_inNV24.cfg
  60. 32 0
      soft_3rdpart/codaj12/cfg/outI444_qcif_inNV42.cfg
  61. 32 0
      soft_3rdpart/codaj12/cfg/outI444_qcif_inUYVY.cfg
  62. 32 0
      soft_3rdpart/codaj12/cfg/outI444_qcif_inVYUY.cfg
  63. 32 0
      soft_3rdpart/codaj12/cfg/outI444_qcif_inYUVP.cfg
  64. 32 0
      soft_3rdpart/codaj12/cfg/outI444_qcif_inYUYV.cfg
  65. 32 0
      soft_3rdpart/codaj12/cfg/outI444_qcif_inYVYU.cfg
  66. 34 0
      soft_3rdpart/codaj12/cfg/outI444_vga_inI444_12b.cfg
  67. 8 0
      soft_3rdpart/codaj12/cmd/jpg_dec_test_12b.cmd
  68. 6 0
      soft_3rdpart/codaj12/cmd/jpg_dec_test_8b.cmd
  69. 5 0
      soft_3rdpart/codaj12/cmd/jpg_enc_test_12b.cmd
  70. 42 0
      soft_3rdpart/codaj12/cmd/jpg_enc_test_8b.cmd
  71. 41 0
      soft_3rdpart/codaj12/codaj12Driver_buildroot.mak
  72. 148 0
      soft_3rdpart/codaj12/codaj12_buildroot.mak
  73. 27 0
      soft_3rdpart/codaj12/config.h
  74. BIN
      soft_3rdpart/codaj12/ffmpeg/riscvlinux/libz.a
  75. BIN
      soft_3rdpart/codaj12/ffmpeg/src/ffmpeg-2.1.8.tar.gz
  76. 131 0
      soft_3rdpart/codaj12/jdi/jdi.h
  77. 49 0
      soft_3rdpart/codaj12/jdi/linux/driver/Makefile
  78. 51 0
      soft_3rdpart/codaj12/jdi/linux/driver/Makefile.usb
  79. 0 0
      soft_3rdpart/codaj12/jdi/linux/driver/Module.symvers
  80. 4 0
      soft_3rdpart/codaj12/jdi/linux/driver/build_env_setup_android.sh
  81. 8 0
      soft_3rdpart/codaj12/jdi/linux/driver/build_env_setup_riscv.sh
  82. 109 0
      soft_3rdpart/codaj12/jdi/linux/driver/driver.dsp
  83. 29 0
      soft_3rdpart/codaj12/jdi/linux/driver/driver.dsw
  84. 646 0
      soft_3rdpart/codaj12/jdi/linux/driver/jmm.h
  85. 301 0
      soft_3rdpart/codaj12/jdi/linux/driver/jpu-starfive.h
  86. 1217 0
      soft_3rdpart/codaj12/jdi/linux/driver/jpu.c
  87. 50 0
      soft_3rdpart/codaj12/jdi/linux/driver/jpu.h
  88. 2 0
      soft_3rdpart/codaj12/jdi/linux/driver/jpu.mod
  89. 26 0
      soft_3rdpart/codaj12/jdi/linux/driver/load
  90. 25 0
      soft_3rdpart/codaj12/jdi/linux/driver/load.sh
  91. 24 0
      soft_3rdpart/codaj12/jdi/linux/driver/load_android.sh
  92. 14 0
      soft_3rdpart/codaj12/jdi/linux/driver/unload
  93. 14 0
      soft_3rdpart/codaj12/jdi/linux/driver/unload.sh
  94. 13 0
      soft_3rdpart/codaj12/jdi/linux/driver/unload_android.sh
  95. 874 0
      soft_3rdpart/codaj12/jdi/linux/jdi.c
  96. 660 0
      soft_3rdpart/codaj12/jdi/mm.c
  97. 123 0
      soft_3rdpart/codaj12/jdi/mm.h
  98. 853 0
      soft_3rdpart/codaj12/jdi/nonos/jdi.c
  99. 39 0
      soft_3rdpart/codaj12/jpuapi/Android.mk
  100. 1804 0
      soft_3rdpart/codaj12/jpuapi/jpuapi.c

+ 1 - 0
conf/buildroot_initramfs_config

@@ -177,6 +177,7 @@ BR2_PACKAGE_HTOP=y
 BR2_PACKAGE_UTIL_LINUX_MOUNT=y
 BR2_PACKAGE_WAVE511=y
 BR2_PACKAGE_WAVE521=y
+BR2_PACKAGE_CODAJ12=y
 BR2_PACKAGE_SF_OMX_IL=y
 BR2_PACKAGE_SF_OMX_IL_TEST=y
 BR2_PACKAGE_SF_GST_OMX=y

+ 17 - 0
soft_3rdpart/codaj12/Android.mk

@@ -0,0 +1,17 @@
+#
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+	  include $(all-subdir-makefiles)
+

+ 169 - 0
soft_3rdpart/codaj12/Makefile

@@ -0,0 +1,169 @@
+# ----------------------------------------------------------------------
+#
+# Project: C&M Video decoder sample
+#
+# ----------------------------------------------------------------------
+.PHONY: CREATE_DIR
+
+USE_PTHREAD = yes
+USE_RTL_SIM = no
+BUILD_CONFIGURATION = EmbeddedLinux
+MAKECMDGOALS ?=
+
+ifeq ($(RTL_SIM), 1)
+USE_RTL_SIM = yes
+endif
+
+PLATFORM = nativelinux_64bit
+
+CROSS_CC_PREFIX =
+JDI_C           = jdi/linux/jdi.c
+MM_C            =
+PLATFORM_FLAGS  =
+VPATH           = jdi/linux:
+USE_FFMPEG      = yes
+USE_ALLOCATOR   = no
+
+INCLUDES = -I./jpuapi -I./include -I./jdi -I./sample -I./sample/helper
+ifeq ("$(BUILD_CONFIGURATION)", "NonOS")
+    CROSS_CC_PREFIX = arm-none-eabi-
+    JDI_C           = jdi/nonos/jdi.c
+    USE_FFMPEG      = no
+    USE_PTHREAD     = no
+    PLATFORM        = none
+    DEFINES         = -DLIB_C_STUB
+    PLATFORM_FLAGS  =
+    VPATH           = jdi/nonos:
+    USE_FFMPEG      = no
+    USE_ALLOCATOR   = yes
+endif
+ifeq ("$(BUILD_CONFIGURATION)", "EmbeddedLinux")
+    CROSS_CC_PREFIX = riscv64-buildroot-linux-gnu-
+    PLATFORM        = riscvlinux
+    USE_FFMPEG      ?= yes
+endif
+
+CC  = $(CROSS_CC_PREFIX)gcc
+CXX = $(CROSS_CC_PREFIX)g++
+AR  = $(CROSS_CC_PREFIX)ar
+
+ifeq ($(USE_FFMPEG), yes)
+DEFINES += -DSUPPORT_FFMPEG
+INCLUDES += -I./ffmpeg/include
+LDLIBS  += -lavformat -lavcodec -lavutil -lz
+LDFLAGS += -L./ffmpeg/$(PLATFORM)
+LDFLAGS += -L./ffmpeg/lib
+endif
+
+ifeq ($(USE_RTL_SIM), yes)
+DEFINES += -DCNM_SIM_PLATFORM -DCNM_SIM_DPI_INTERFACE
+else
+endif
+
+CFLAGS  += -g -I. -Wno-implicit-function-declaration -Wno-int-to-pointer-cast -Wno-format -Wl,--fatal-warning $(INCLUDES) $(DEFINES) $(PLATFORM_FLAGS) -Wall -Werror
+ifeq ($(MAKECMDGOALS), multi)
+CFLAGS  +=  -DSUPPORT_MULTI_INSTANCE_TEST
+endif
+ifeq ($(USE_RTL_SIM), yes)
+ifeq ($(IUS), 1)
+#CFLAGS  += -m32 # ncverilog is 32bit version
+CFLAGS  += -fPIC # ncverilog is 64bit version
+endif
+USE_ALLOCATOR = yes
+endif
+ARFLAGS += cru
+ifeq ($(USE_PTHREAD), yes)
+LDLIBS  += -lpthread
+endif
+LDLIBS  += -lm
+
+OBJDIR=obj
+ALLOBJS=*.o
+ALLDEPS=*.dep
+ALLLIBS=*.a
+RM=rm -f
+MKDIR=mkdir -p
+
+ENC_SOURCES = $(JDI_C) jpuapi.c jpuapifunc.c jpuhelper.c jpulog.c cnm_fpga.c main_jpg_enc_test.c \
+              yuv_feeder.c platform.c datastructure.c bitstreamwriter.c
+DEC_SOURCES = $(JDI_C) jpuapi.c jpuapifunc.c jpuhelper.c jpulog.c cnm_fpga.c main_jpg_dec_test.c \
+              platform.c datastructure.c bitstreamfeeder.c bsfeeder_fixedsize_impl.c
+MUL_SOURCES = $(JDI_C) jpuapi.c jpuapifunc.c jpuhelper.c jpulog.c cnm_fpga.c main_multi_instance_test.c \
+              platform.c datastructure.c yuv_feeder.c
+MUL_SOURCES += bitstreamfeeder.c bsfeeder_fixedsize_impl.c main_jpg_dec_test.c
+MUL_SOURCES += bitstreamwriter.c main_jpg_enc_test.c
+
+ifeq ($(USE_RTL_SIM), yes)
+ENC_SOURCES += main_sim.c
+DEC_SOURCES += main_sim.c
+MUL_SOURCES += main_sim.c
+endif
+ifeq ($(USE_ALLOCATOR), yes)
+ENC_SOURCES += mm.c
+DEC_SOURCES += mm.c
+MUL_SOURCES += mm.c
+endif
+ifeq ($(USE_FFMPEG), yes)
+ENC_SOURCES += bswriter_container_impl.c
+DEC_SOURCES += bsfeeder_framesize_impl.c
+MUL_SOURCES += bsfeeder_framesize_impl.c
+MUL_SOURCES += bswriter_container_impl.c
+endif
+
+
+
+VPATH += jdi:
+VPATH += jdi/nonos:
+VPATH += jpuapi:
+VPATH += sample:sample/helper:
+
+
+DEC_OBJECTNAMES=$(patsubst %.c,%.o,$(DEC_SOURCES))
+DEC_OBJECTPATHS=$(addprefix $(OBJDIR)/,$(notdir $(DEC_OBJECTNAMES)))
+ENC_OBJECTNAMES=$(patsubst %.c,%.o,$(ENC_SOURCES))
+ENC_OBJECTPATHS=$(addprefix $(OBJDIR)/,$(notdir $(ENC_OBJECTNAMES)))
+MUL_OBJECTNAMES=$(patsubst %.c,%.o,$(MUL_SOURCES))
+MUL_OBJECTPATHS=$(addprefix $(OBJDIR)/,$(notdir $(MUL_OBJECTNAMES)))
+
+ifeq ($(MAKECMDGOALS), multi)
+	TARGET = multi
+else
+	TARGET = decoder
+	TARGET += encoder
+endif
+
+all: $(TARGET)
+
+
+encoder: CREATE_DIR $(ENC_OBJECTPATHS)
+ifeq ($(USE_RTL_SIM), yes)
+	# do not need to make excutable
+else
+	$(CC) -o jpg_enc_test $(LDFLAGS) -Wl,-gc-section -Wl,--start-group $(ENC_OBJECTPATHS) $(LDLIBS) -Wl,--end-group
+endif
+
+decoder: CREATE_DIR $(DEC_OBJECTPATHS)
+ifeq ($(USE_RTL_SIM), yes)
+	# do not need to make excutable
+else
+	$(CC) -o jpg_dec_test $(LDFLAGS) -Wl,-gc-section -Wl,--start-group $(DEC_OBJECTPATHS) $(LDLIBS) -Wl,--end-group
+endif
+
+multi: CREATE_DIR $(MUL_OBJECTPATHS)
+ifeq ($(USE_RTL_SIM), yes)
+	# do not need to make excutable
+else
+	$(CC) -o multi_instance_test $(LDFLAGS) -Wl,-gc-section -Wl,--start-group $(MUL_OBJECTPATHS) $(LDLIBS) -Wl,--end-group
+endif
+
+-include $(OBJECTPATHS:.o=.dep)
+
+clean:
+	$(RM) $(TARGET) jpg_enc_test jpg_dec_test multi_instance_test
+	$(RM) $(OBJDIR)/$(ALLOBJS)
+	$(RM) $(OBJDIR)/$(ALLDEPS)
+
+CREATE_DIR:
+	-mkdir -p $(OBJDIR)
+obj/%.o: %.c Makefile
+	$(CC) $(CFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)

BIN
soft_3rdpart/codaj12/Nieuport_JpgDec


BIN
soft_3rdpart/codaj12/Nieuport_JpgEnc


File diff suppressed because it is too large
+ 15 - 0
soft_3rdpart/codaj12/README.md


+ 546 - 0
soft_3rdpart/codaj12/TestRunnerCodaJ12Dec.sh

@@ -0,0 +1,546 @@
+#!/bin/bash
+
+source TestRunnerCommon.sh
+
+# Global varaibles for decoder option
+fail_stop=0
+refc_exec="Nieuport_JpgDec"
+bin_dir="./"
+stream_dir="./stream"
+wiki_log_file="./log/dec_confluence.log"
+g_random_test="false";
+jenkins=""
+txt_param_switch=0
+output_path="output_fpga.yuv"
+default_yuv_fmt=""
+default_subsample="none"
+default_ordering="none"
+simulation="false"
+default_bssize=5242880      # 5MB
+MAX_BS_SIZE=10485760        # 10MB, You can allocate more memory.
+MIN_BS_SIZE=8192            # 8KB
+g_random_test="false"
+g_slice_height=0
+g_enable_slice_intr=0
+default_read_delay=
+default_write_delay=
+
+fmt_test_400_list=("none" "420p" "422p" "444p" "nv12" "nv21" "nv16" "nv61" "nv24" "nv42" "yuyv" "yvyu" "uyvy" "vyuy")
+fmt_test_420_list=("none" "420p" "422p" "444p" "nv12" "nv21" "nv16" "nv61" "nv24" "nv42" "yuyv" "yvyu" "uyvy" "vyuy")
+fmt_test_422_list=("none" "420p" "422p" "444p" "nv12" "nv21" "nv16" "nv61" "nv24" "nv42" "yuyv" "yvyu" "uyvy" "vyuy")
+fmt_test_440_list=("none" "420p" "422p" "444p" "nv12" "nv21" "nv16" "nv61" "nv16v" "nv61v" "nv24" "nv42" "yuyv" "yvyu" "uyvy" "vyuy")
+fmt_test_444_list=("none" "420p" "422p" "444p" "nv12" "nv21" "nv16" "nv61" "nv24" "nv42" "yuyv" "yvyu" "uyvy" "vyuy" "ayuv")
+
+fmt_test_400_num=${#fmt_test_400_list[@]}
+fmt_test_420_num=${#fmt_test_420_list[@]}
+fmt_test_422_num=${#fmt_test_422_list[@]}
+fmt_test_440_num=${#fmt_test_440_list[@]}
+fmt_test_444_num=${#fmt_test_444_list[@]}
+
+MAX_OUTPUT_FMT=$((${#SUPPORTED_YUV_FMT[@]} -1))
+
+function help {
+    echo ""
+    echo "-------------------------------------------------------------------------------"
+    echo "Chips&Media conformance Tool v2.0"
+    echo "All copyright reserved by Chips&Media"
+    echo "-------------------------------------------------------------------------------"
+    echo "$0 OPTION streamlist_file"
+    echo "-h                        help"
+    echo "-n num                    number of frames."
+    echo "--enable-random           generate random option."
+    echo "--bin-dir                 ref-c directory, default: ./"
+    echo "--stream-dir              stream directory"
+    echo "--12bit                   input stream is an extended sequential jpeg"
+    echo "--stream-endian           ENDIAN  bitstream endianness. refer to datasheet Chapter 4."
+    echo "--frame-endian            ENDIAN   pixel endianness of 16bit input source. refer to datasheet Chapter 4."
+    echo "--pixelj                  16bit-pixel justification. 0(default) - msb justified, 1 - lsb justified in little-endianness"
+    echo "--subsample               conversion sub-sample(ignore case: NONE, 420, 422, 444";
+    echo "--ordering                conversion ordering(ingore-case: NONE, NV12, NV21, YUYV, YVYU, UYVY, VYUY, AYUV";
+    echo "                          NONE - planar format";
+    echo "                          NV12, NV21 - semi-planar format for all the subsamples.";
+    echo "                                       If subsample isn't defined or is none, the sub-sample depends on jpeg information";
+    echo "                                       The subsample 440 can be converted to the semi-planar format. It means that the encoded sub-sample should be 440.";
+    echo "                          YUVV..VYUY - packed format. subsample be ignored.";
+    echo "                          AYUV       - 444 packed format. subsample be ignored.";
+    echo "--scaleH                  Horizontal downscale: 0(none), 1(1/2), 2(1/4), 3(1/8)";
+    echo "--scaleV                  Vertical downscale  : 0(none), 1(1/2), 2(1/4), 3(1/8)";
+    echo "--rotation                0, 90, 180, 270 CCW"
+    echo "--mirror                  0, 1(vertical), 2(horizontal), 3(both)"
+}
+
+function generate_parameters {
+    local val=0
+    local list
+
+    g_stream_endian=$(gen_val 0 3 $default_stream_endian)
+    if [ "$g_jpeg_12bit" == "true" ]; then
+        g_frame_endian=$(gen_val 0 7 $default_frame_endian)
+    else
+        g_frame_endian=$(gen_val 0 3 $default_frame_endian)
+    fi
+
+    # PPU AND SCALER
+    if [ "$g_random_test" == "true" ]; then
+        ppu_random=$(gen_val 0 1) # 0 - rotation/mirror, 1 - scaler
+        if [ "$ppu_random" == "0" ]; then
+            g_rotation=$(gen_val_angle $default_rotation)
+            g_mirror=$(gen_val 0 3 $default_mirror)
+            g_scale_h=0
+            g_scale_v=0
+        elif [ "$ppu_random" == "1" ]; then
+            g_rotation=0
+            g_mirror=0
+            g_scale_h=$(gen_val 0 3 $default_scaleH)
+            g_scale_v=$(gen_val 0 3 $default_scaleV)
+        fi
+    else
+        g_rotation=$(gen_val_angle $default_rotation)
+        g_mirror=$(gen_val 0 3 $default_mirror)
+        g_scale_h=$(gen_val 0 3 $default_scaleH)
+        g_scale_v=$(gen_val 0 3 $default_scaleV)
+        if [ "$g_rotation" != "0" ] || [ "$g_mirror" != "0" ]; then
+            if [ "$g_scale_h" != "0" ] || [ "$g_scale_h" != "0" ]; then
+                echo "The PPU(rotator and mirror) doesn't work with the down-scaler"
+                echo "rotation: $g_rotation, mirror: $mirror, scale-H: $g_scale_h, scale-V: $g_scale_v"
+                exit 1
+            fi
+        fi
+    fi
+
+    # SUBSAMPLE AND ORDERING
+    if [ "$g_random_test" == "true" ]; then
+        default_yuv_fmt="-99"
+    fi
+    if [ "$default_yuv_fmt" == "-99" ]; then
+        case $g_orig_fmt in
+        400) list=(${fmt_test_400_list[@]});;
+        420) list=(${fmt_test_420_list[@]});;
+        422) list=(${fmt_test_422_list[@]});;
+        440) list=(${fmt_test_440_list[@]});;
+        444) list=(${fmt_test_444_list[@]});;
+        esac
+        max_fmt_num=${#list[@]}
+        val=$(gen_val 0 $((max_fmt_num-1)))
+        output_format="${list[$val]}"
+        # generate subsample and ordering parameter for ref-sw
+        convert_fmt_val_for_refsw $output_format $g_orig_fmt
+    else
+        g_subsample="$default_subsample"
+        g_ordering="$default_ordering"
+    fi
+
+    if [ "$g_rotation" != "0" ] || [ "$g_mirror" != "0" ]; then
+        # color format converter and rotator cannot work together.
+        if [ "$g_subsample" != "none" ]; then
+            g_subsample="none"
+        fi
+        if [ "$g_ordering" != "nv12" ] && [ "$g_ordering" != "nv21" ]; then
+            g_ordering="none"
+        fi
+    fi
+
+    g_bs_size=$(gen_val $MIN_BS_SIZE $MAX_BS_SIZE $default_bssize)
+    g_bs_size=$((($g_bs_size + 4095) & ~4095))
+
+    g_pixel_just=$(gen_val 0 1 $default_pixelj)
+
+    # generate -pn -pk and -v options for c-model
+    convert_fmt_val_for_cmodel $g_subsample $g_orig_fmt $g_ordering
+}
+
+function build_test_param {
+    local param=""
+
+    param="$param --rotation=$g_rotation"
+    param="$param --mirror=$g_mirror"
+    param="$param --stream-endian=$g_stream_endian --frame-endian=$g_frame_endian"
+    param="$param --subsample=$g_subsample --ordering=$g_ordering"
+    param="$param --scaleH=$g_scale_h"
+    param="$param --scaleV=$g_scale_v"
+    param="$param --bs-size=$g_bs_size"
+    param="$param --pixelj=$g_pixel_just"
+    if [ "$simulation" == "true" ]; then
+        param="$param $g_fsdb_param --TestRunner=1"
+    fi
+
+    g_func_ret_str="$param"
+}
+
+function get_yuv_format {
+    local format=""
+    local cmd="${bin_dir}/${refc_exec} -i $1 -m 1"
+
+    if [ "$g_jpeg_12bit" == "true" ]; then
+        cmd="$cmd -u"
+    fi
+    $cmd > result.txt
+    while read line; do
+        line=$(echo $line | tr -d '\n')
+        line=$(echo $line | tr -d '\r')
+        line="${line%%\#*}"
+        attr=$(echo $line | cut -d':' -f1)
+        attr=$(echo $attr | tr -d ' ')
+        value=$(echo $line | cut -d':' -f2-)
+        value=$(echo $value | tr -d ' ')
+        value="${value//:/}"
+        if [ "$attr" == "OutputYUVformat" ]; then
+            format="$value"
+            break;
+        fi
+    done < result.txt
+
+    echo "$format"
+}
+
+################################################################################
+# Parse arguments                                                              #
+################################################################################
+OPTSTRING="-o hw: -l enable-random,stream-dir:,bin-dir:"
+OPTSTRING="${OPTSTRING},stream-endian:,frame-endian:"
+OPTSTRING="${OPTSTRING},slice-height:,enable-slice-intr:,subsample:,ordering:,output:,input:,bs-size:"
+OPTSTRING="${OPTSTRING},scaleH:,scaleV:,rotation:,mirror:"
+OPTSTRING="${OPTSTRING},12bit,pixelj:"
+
+OPTS=`getopt $OPTSTRING -- "$@"`
+
+if [ $? -ne 0 ]; then
+    exit 1
+fi
+
+eval set -- "$OPTS"
+
+while true; do
+    case "$1" in
+        -h)
+            help
+            exit 1
+            shift;;
+        --bin-dir)
+            bin_dir=$2
+            shift 2;;
+        --enable-random)
+            g_random_test="true"
+            shift;;
+        --stream-dir)
+            echo "stream-dir"
+            stream_dir=$2
+            shift 2;;
+        --stream-endian)
+            default_stream_endian=$2
+            shift 2;;
+        --frame-endian)
+            default_frame_endian="$2"
+            shift 2;;
+        --12bit)
+            g_jpeg_12bit="true"
+            shift;;
+        --pixelj)
+            default_pixelj="$2"
+            shift 2;;
+        --input)
+            streamset_path="$2"
+            shift 2;;
+        --output)
+            output_path="$2"
+            shift 2;;
+        --subsample)
+            default_subsample="$2"
+            shift 2;;
+        --ordering)
+            default_ordering="$2"
+            shift 2;;
+        --scaleH)
+            default_scaleH="$2"
+            shift 2;;
+        --scaleV)
+            default_scaleV="$2"
+            shift 2;;
+        --rotation)
+            default_rotation="$2"
+            shift 2;;
+        --mirror)
+            default_mirror="$2"
+            shift 2;;
+        --bs-size)
+            default_bssize="$2"
+            shift 2;;
+        --)
+            shift
+            break;;
+    esac
+done
+
+shift $(($OPTIND - 1))
+
+if [ "$simulation" == "true" ]; then
+    ACLK_MIN=160
+    ACLK_MAX=300
+    CCLK_MIN=160
+    CCLK_MAX=300
+    DEFAULT_ACLK=200
+    DEFAULT_CCLK=200
+    test_exec="./runit"
+else
+    DEFAULT_ACLK=20
+    DEFAULT_CCLK=20
+    test_exec="./jpg_dec_test"
+fi
+
+
+
+################################################################################
+# Get param from target text file                                              #
+################################################################################
+name_value=()
+input_param_name="TestRunnerParamCodaJ12Dec.txt"
+if [ -f $input_param_name ]; then
+    while read line; do
+        # remove right comment
+        line="${line%%\#*}"
+        if [ "$line" = "" ]; then continue; fi
+
+        OIFS=$IFS
+        IFS='='
+        count=0
+        for word in $line; do
+            word=${word// /}
+            name_value[$count]="$word"
+            count=$(($count+1))
+        done
+        IFS=$OIFS
+        attr="${name_value[0]}"
+        value="${name_value[1]}"
+
+        case "$attr" in
+            default)            default_opt="$value";;
+            aclk)               [ ! -z $default_aclk ]          || default_aclk="$value";;
+            cclk)               [ ! -z $default_cclk ]          || default_cclk="$value";;
+            n)                  g_frame_num="-n $value";;
+            fake_test)          fake_test="$value";;
+            stream-endian)      [ ! -z $default_stream_endian ] || default_stream_endian="$value";;
+            frame-endian)       [ ! -z $default_frame_endian ]  || default_frame_endian="$value";;
+            scaleH)             [ ! -z $default_scaleH ]        || default_scaleH="$value";;
+            scaleV)             [ ! -z $default_scaleV ]        || default_scaleV="$value";;
+            rotation)           [ ! -z $default_rotation ]      || default_rotation="$value";;
+            mirror)             [ ! -z $default_mirror ]        || default_mirror="$value";;
+            pixelj)             [ ! -z $default_pixelj ]        || default_pixelj="$value";;
+            slice-height)       [ ! -z $default_slice_height ]  || default_slice_height="$value";;
+            enable-slice-intr)  [ ! -z $default_slice_int ]     || default_slice_int="$value";;
+            txt-param)      txt_param_switch=1;;
+            *) ;;
+        esac
+    done < $input_param_name
+else
+    if [ ! -f $input_param_name ]; then
+        echo "$input_param_name file doesn't exist";
+    fi
+fi
+
+# SET DEFAULT VALUES
+if [ "$g_random_test" != "true" ]; then
+    [ ! -z $default_aclk ]          || default_aclk=$DEFAULT_ACLK
+    [ ! -z $default_cclk ]          || default_cclk=$DEFAULT_CCLK
+    [ ! -z $default_stream_endian ] || default_stream_endian=0
+    [ ! -z $default_frame_endian ]  || default_frame_endian=0
+    [ ! -z $default_scaleH ]        || default_scaleH=0
+    [ ! -z $default_scaleV ]        || default_scaleV=0
+    [ ! -z $default_rotation ]      || default_rotation=0
+    [ ! -z $default_mirror ]        || default_mirror=0
+    [ ! -z $default_slice_int ]     || default_slice_int=0
+    [ ! -z $default_slice_height ]  || default_slice_height=0
+    [ ! -z $default_pixelj ]        || default_pixelj=0
+else
+    default_slice_int=0
+    default_slice_height=0
+fi
+
+if [ -z $streamset_path ]; then
+    streamset_path=$1
+fi
+streamset_file=`basename ${streamset_path}`
+
+################################################################################
+# count stream number                                                          #
+################################################################################
+stream_file_array=()
+ext="${streamset_file##*.}"
+ext=$(tr '[:upper:]' '[:lower:]' <<< $ext)
+single_file="false"
+if [ "$ext" == "jpg" ] || [ "$ext" == "jpeg" ]; then
+    stream_file_array[0]="$streamset_path"
+    single_file="true"
+else
+    if [ ! -e "${streamset_path}" ]; then
+        echo "No such file: ${streamset_path}"
+        exit 1
+    fi
+    parse_streamset_file $streamset_path stream_file_array
+fi
+
+num_of_streams=${#stream_file_array[@]}
+
+count=1
+success_count=0
+failure_count=0
+remain_count=${num_of_streams}
+basedir=${basedir//\/}  # remove last delimeter
+
+mkdir -p temp
+mkdir -p output
+mkdir -p log/decoder_conformance
+conf_log_path="log/decoder_conformance/${streamset_file}.log"
+conf_err_log_path="log/decoder_conformance/${streamset_file}_error.log"
+temp_log_path="./temp/temp.log"
+# truncate contents of log file
+echo "" > $conf_log_path
+echo "" > $conf_err_log_path
+echo "" > $temp_log_path
+beginTime=$(date +%s%N)
+
+################################################################################
+# read cmd file.                                                               #
+################################################################################
+for (( c=0; c< $num_of_streams ; c++ )) do
+    line=${stream_file_array[$c]}
+    if [ "$single_file" == "true" ]; then
+        stream="${line}"
+    else
+        stream="${stream_dir}/${line}"
+    fi
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+    log_conf "[${count}/${num_of_streams}] ${stream}" ${temp_log_path}
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+
+    if [ ! -f $stream ]; then
+        log_conf "Not found $stream" $temp_log_path
+        log_conf "[RESULT] FAILURE" $temp_log_path
+        echo "Not found $stream" >> $conf_err_log_path
+        echo "[RESULT] FAILURE" >> $conf_err_log_path
+        cat $temp_log_path >> $conf_log_path
+        failure_count=$(($failure_count + 1))
+        remain_count=$(($remain_count - 1))
+        count=$(($count + 1))
+        continue
+    fi
+
+    result=0
+    target_stream=$stream
+
+################################################################################
+# make argc & argv parameter                                                   #
+################################################################################
+    if [ $result -eq 0 ]; then
+        g_orig_fmt=$(get_yuv_format $target_stream)
+        generate_parameters
+        build_test_param
+        test_param="$g_func_ret_str"
+
+################################################################################
+# Golden YUV                                                                   #
+################################################################################
+        golden_yuv_path="output_refc.yuv"
+        generate_golden_yuv $stream $golden_yuv_path
+        result=$?
+
+################################################################################
+# print information                                                            #
+################################################################################
+
+        if [ $result -eq 0 ]; then
+            log_conf "RANDOM TEST    : $g_random_test" $temp_log_path
+            log_conf "ENDIAN         : STREAM($g_stream_endian) FRAME($g_frame_endian)" $temp_log_path
+            log_conf "SUBSAMPLE      : $g_subsample" $temp_log_path
+            log_conf "ORDERING       : $g_ordering" $temp_log_path
+            log_conf "ROTATE         : $g_rotation" $temp_log_path
+            log_conf "MIRROR         : ${MIRROR_NAME[$g_mirror]}" $temp_log_path
+            log_conf "SCALE DOWN     : H: ${SCALEDOWN_NAME[$g_scale_h]} V: ${SCALEDOWN_NAME[$g_scale_v]}" $temp_log_path
+            log_conf "PIXEL_JUST.    : ${JUSTIFY_NAME[$g_pixel_just]}" $temp_log_path
+
+            rm -f output_fpga.yuv
+            cmd="$test_exec $test_param --output=$output_path --input=$target_stream"
+            cmd_log="$test_exec $test_param --output=$output_path --input=$stream"
+            log_conf "$cmd_log" $temp_log_path
+            cat $temp_log_path >> $conf_log_path
+
+            if [ "$fake_test" == "1" ]; then
+                echo "<< Testing just script >>"
+            else
+				exit
+                $cmd
+                result=$?
+                if [ "$result" == "0" ]; then
+                    cmp $output_path output_refc.yuv
+                    if [ "$?" != "0" ]; then
+                        result=1
+                    fi
+                fi
+            fi
+        fi
+    else
+        cat $temp_log_path >> $conf_log_path
+    fi
+
+    if [ $result -eq 0 ]; then
+        log_conf "[RESULT] SUCCESS" $conf_log_path
+        success_count=$(($success_count + 1))
+    else
+        cat ./ErrorLog.txt >> $conf_log_path
+        log_conf "[RESULT] FAILURE" $conf_log_path
+        failure_count=$(($failure_count + 1))
+        cat $temp_log_path >> $conf_err_log_path
+        cat ./ErrorLog.txt >> $conf_err_log_path
+        echo "cmp $stream $target_stream"
+        cmp $stream $target_stream
+        echo "[RESULT] FAILURE" >> $conf_err_log_path
+        if [ $result -eq 10 ]; then
+            echo "Abnormal exit!!!"
+            break
+        fi
+    fi
+    remain_count=$(($remain_count - 1))
+    count=$(($count + 1))
+    # clear temp log
+    echo "" > $temp_log_path
+    # delete temporal input file
+    if [ $fail_stop -eq 1 ] && [ $result -ne 0 ]; then
+        break;
+    fi
+done
+
+endTime=$(date +%s%N)
+elapsed=$((($endTime - $beginTime) / 1000000000))
+elapsedH=$(($elapsed / 3600))
+elapsedS=$(($elapsed % 60))
+elapsedM=$(((($elapsed - $elapsedS) / 60) % 60))
+if [ "$((elapsedS / 10))" == "0" ]; then elapsedS="0${elapsedS}" ;fi
+if [ "$((elapsedM / 10))" == "0" ]; then elapsedM="0${elapsedM}" ;fi
+if [ "$((elapsedH / 10))" == "0" ]; then elapsedH="0${elapsedH}" ;fi
+
+if [ $elapsed -le 60 ]; then
+    time_hms="{color:red}*${elapsedH}:${elapsedM}:${elapsedS}*{color}"
+else
+    time_hms="${elapsedH}:${elapsedM}:${elapsedS}"
+fi
+
+log_filename=$(basename $conf_log_path)
+log_err_filename=$(basename $conf_err_log_path)
+if [ $failure_count == 0 ] && [ $num_of_streams != 0 ]; then
+    pass=${PASS}
+    rm $conf_err_log_path
+    log_err_filename=""
+else
+    pass=${FAIL}
+fi
+
+wiki_log="| $streamset_file | $num_of_streams | $success_count | $failure_count | $remain_count | $log_filename | ${log_err_filename} | $pass | $time_hms | | | |"
+
+echo $wiki_log
+echo $wiki_log >> $wiki_log_file
+
+if [ "$num_of_streams" == "0" ]; then
+    echo "num_of_streams: $num_of_streams = exit 1"
+    exit 1
+fi
+
+exit $failure_count

+ 459 - 0
soft_3rdpart/codaj12/TestRunnerCodaJ12Enc.sh

@@ -0,0 +1,459 @@
+#!/bin/bash
+
+source TestRunnerCommon.sh
+
+# Global varaibles for encoder options
+wiki_log_file="./log/enc_confluence.log"
+jenkins=""
+txt_param_switch=0
+output_path="output_fpga.jpg"
+DEFAULT_BS_SIZE=5242880    # 5MB
+MIN_BS_SIZE=8192           # 8KB
+default_read_delay=
+default_write_delay=
+
+g_random_test=0
+simulation="false"
+
+yuv_dir="./yuv"
+bin_dir="./"
+cfg_dir="./cfg"
+g_aclk=$DEFAULT_ACLK
+g_cclk=$DEFAULT_CCLK
+refc_exec="Nieuport_JpgEnc"
+tiled_exec="./tiled_mode"
+
+
+################################################################################
+# Initialize parameter variables                                               #
+################################################################################
+
+function help {
+    echo ""
+    echo "-------------------------------------------------------------------------------"
+    echo "Chips&Media conformance Tool v2.0"
+    echo "All copyright reserved by Chips&Media"
+    echo "-------------------------------------------------------------------------------"
+    echo "$0 OPTION streamlist_file"
+    echo "-h                        help"
+    echo "--enable-random           It generates random parameters"
+    echo "--bin-dir                 ref-c directory, default: ./"
+    echo "--cfg-dir                 base directory of encoder configuration files. default: ./cfg"
+    echo "--yuv-dir                 base directory storing YUV. default: ./yuv"
+    echo "--stream-endian           ENDIAN  bitstream endianness. refer to datasheet Chapter 4."
+    echo "--frame-endian            ENDIAN   pixel endianness of 16bit input source. refer to datasheet Chapter 4."
+    echo "--slice-height            the vertical hieght of a slice. multiple of 16 for 420, multiple of 8 for others"
+    echo "--enable-slice-intr=ONOFF enable get the interrupt at every slice encoded. ONOFF - 0 for disable, 1 for enable. default OFF"
+    echo "--bs-size                 itstream buffer size in byte"
+    echo "--output                  output path"
+    echo "--input                   input path"
+    echo "--rotation=angle          0, 90, 180, 270"
+    echo "--mirror=value            0, 1(Vertical), 2(Horizontal), 3(both)"
+}
+
+function generate_parameters {
+    local cfg=$1
+
+    g_stream_endian=$(gen_val 0 3 $default_stream_endian)
+    if [ "$jpeg_12bit" == "1" ]; then
+        g_frame_endian=$(gen_val 0 7 $default_frame_endian)
+    else
+        g_frame_endian=$(gen_val 0 3 $default_frame_endian)
+    fi
+
+    g_pixel_just=$(gen_val 0 1 $default_pixelj)
+    g_rotation=$(gen_val_angle $default_rotation)
+    g_mirror=$(gen_val 0 3 $default_mirror)
+
+    if [ "$g_random_test" == "1" ]; then
+        slice_random=$(gen_val 0 1) # 0: disable slice done, 1: enable slice_done
+    else
+        slice_random=0
+    fi
+    if [ "$slice_random" == "1" ] || [ "$default_slice_height" != "0" ]; then
+        read_cfg $cfg
+        if [ "$g_rotation" == "90" ] || [ "$g_rotation" == "270" ]; then
+            local temp=$cfg_width
+            cfg_width=$cfg_height
+            cfg_height=$temp
+            if [ "$cfg_img_format" == "2" ]; then
+                # 422 to 440
+                cfg_img_format=3
+            elif [ "$cfg_img_format" == "3" ]; then
+                # 440 to 422
+                cfg_img_format=2
+            fi
+        fi
+        if [ "$g_rotation" != "0" ] || [ "$g_mirror" != "0" ]; then
+            # disable the slice-encoding mode
+            g_slice_height=0
+            g_enable_slice_intr=0
+        else
+            g_slice_height=$(gen_valid_slice_height $cfg_width $cfg_height $cfg_img_format $default_slice_height)
+            if [ "$g_slice_height" != "0" ]; then
+                g_enable_slice_intr=$(gen_val 0 1 $default_slice_int)
+            else
+                g_enable_slice_intr=0
+            fi
+        fi
+    else
+        g_slice_height=0
+        g_enable_slice_intr=0
+    fi
+
+    g_bs_size=$(gen_val $MIN_BS_SIZE $DEFAULT_BS_SIZE $default_bs_size)
+    g_bs_size=$((($g_bs_size + 4095) & ~4095))
+
+    g_tiled_mode=$default_tiled_mode
+}
+
+function build_test_param {
+    local param=""
+
+    if [ "$jpeg_12bit" == "1" ]; then
+        param="$param --12bit"
+    fi
+    param="$param --stream-endian=$g_stream_endian --frame-endian=$g_frame_endian"
+    param="$param --pixelj=$g_pixel_just"
+    param="$param --slice-height=$g_slice_height"
+    param="$param --enable-slice-intr=$g_enable_slice_intr"
+    param="$param --enable-tiledMode=$g_tiled_mode"
+    param="$param --bs-size=$g_bs_size"
+    param="$param --rotation=$g_rotation"
+    param="$param --mirror=$g_mirror"
+    g_func_ret_str="$param"
+}
+
+################################################################################
+# Parse arguments                                                              #
+################################################################################
+OPTSTRING="-o hw: -l enable-random,bin-dir:,cfg-dir:,yuv-dir:"
+OPTSTRING="${OPTSTRING},stream-endian:,frame-endian:"
+OPTSTRING="${OPTSTRING},slice-height:,enable-slice-intr:,bs-size:,output:,input:"
+OPTSTRING="${OPTSTRING},enable-tiledMode:"
+OPTSTRING="${OPTSTRING},12bit,pixelj:"
+OPTSTRING="${OPTSTRING},rotation:,mirror:"
+
+OPTS=`getopt $OPTSTRING -- "$@"`
+
+if [ $? -ne 0 ]; then
+    exit 1
+fi
+
+eval set -- "$OPTS"
+
+while true; do
+    case "$1" in
+        -h)
+            help
+            exit 1
+            shift;;
+        --bin-dir)
+            bin_dir_user=$2
+            shift 2;;
+        --enable-random)
+            g_random_test=1
+            shift;;
+        --cfg-dir)
+            cfg_dir_user=$2
+            shift 2;;
+        --yuv-dir)
+            yuv_dir_user=$2
+            shift 2;;
+        --12bit)
+            jpeg_12bit=1
+            shift;;
+        --pixelj)
+            default_pixelj="$2"
+            shift 2;;
+        --enable-tiledMode)
+            g_tiled_mode=$2
+            shift 2;;
+        --stream-endian)
+            default_stream_endian="$2"
+            shift 2;;
+        --frame-endian)
+            default_frame_endian="$2"
+            shift 2;;
+        --slice-height)
+            default_slice_height="$2"
+            shift 2;;
+        --enable-slice-intr)
+            default_slice_int="$2"
+            shift 2;;
+        --rotation)
+            default_rotation="$2"
+            shift 2;;
+        --mirror)
+            default_mirror="$2"
+            shift 2;;
+        --bs-size)
+            default_bs_size="$2"
+            shift 2;;
+        --output)
+            output_path="$2"
+            shift 2;;
+        --input)
+            streamset_path="$2"
+            shift 2;;
+        --)
+            shift
+            break;;
+    esac
+done
+
+shift $(($OPTIND - 1))
+
+if [ "$simulation" == "true" ]; then
+    ACLK_MIN=160
+    ACLK_MAX=300
+    CCLK_MIN=160
+    CCLK_MAX=300
+    DEFAULT_ACLK=200
+    DEFAULT_CCLK=200
+    test_exec="./runit"
+else
+    DEFAULT_ACLK=20
+    DEFAULT_CCLK=20
+    test_exec="./jpg_enc_test"
+fi
+
+if [ ! -f ./$test_exec ] ; then
+    echo " $test_exec file doesn't exist";
+    exit 1
+fi
+
+if [ ! -z $yuv_dir_user ]; then
+    yuv_dir="$yuv_dir_user"
+fi
+if [ ! -z $cfg_dir_user ]; then
+    cfg_dir="$cfg_dir_user"
+fi
+if [ ! -z $bin_dir_user ]; then
+    bin_dir="$bin_dir_user"
+fi
+
+
+
+# SET DEFAULT VALUES
+if [ "$g_random_test" != "1" ]; then
+    [ ! -z $default_aclk ]          || default_aclk=$DEFAULT_ACLK
+    [ ! -z $default_cclk ]          || default_cclk=$DEFAULT_CCLK
+    [ ! -z $default_stream_endian ] || default_stream_endian=0
+    [ ! -z $default_frame_endian ]  || default_frame_endian=0
+    [ ! -z $default_pixelj ]        || default_pixelj=0
+    [ ! -z $default_rotation ]      || default_rotation=0
+    [ ! -z $default_mirror ]        || default_mirror=0
+    [ ! -z $default_slice_int ]     || default_slice_int=0
+    [ ! -z $default_slice_height ]  || default_slice_height=0
+    [ ! -z $default_bs_size ]       || default_bs_size=$DEFAULT_BS_SIZE
+    [ ! -z $default_tiled_mode ]    || default_tiled_mode=0
+else
+    # tiled option is not random value. It depends on a cfg name.
+    default_tiled_mode=0
+fi
+
+if [ -z $streamset_path ]; then
+    streamset_path=$1
+fi
+streamset_file=`basename ${streamset_path}`
+
+################################################################################
+# count stream number                                                          #
+################################################################################
+cfg_file_array=()
+ext="${streamset_file##*.}"
+if [ "$ext" == "cfg" ]; then
+    cfg_file_array[0]="$streamset_path"
+else
+    if [ ! -e "${streamset_path}" ]; then
+        echo "No such file: ${streamset_path}"
+        exit 1
+    fi
+    parse_streamset_file $streamset_path cfg_file_array
+fi
+
+num_of_cfgs=${#cfg_file_array[@]}
+
+count=1
+success_count=0
+failure_count=0
+remain_count=${num_of_cfgs}
+basedir=${basedir//\/}  # remove last delimeter
+
+################################################################################
+# make log info
+################################################################################
+mkdir -p temp
+mkdir -p output
+mkdir -p log/encoder_conformance
+conf_log_path="log/encoder_conformance/${streamset_file}.log"
+conf_err_log_path="log/encoder_conformance/${streamset_file}_error.log"
+temp_log_path="./temp/temp.log"
+# truncate contents of log file
+echo "" > $conf_log_path
+echo "" > $conf_err_log_path
+echo "" > $temp_log_path
+beginTime=$(date +%s%N)
+
+################################################################################
+# read cmd file.                                                               #
+################################################################################
+for (( c=0; c< $num_of_cfgs ; c++ )) do
+    line=${cfg_file_array[$c]}
+    cfg="${line}"
+    cfg_path="${cfg_dir}/${line}"
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+    log_conf "[${count}/${num_of_cfgs}] ${cfg_path}" ${temp_log_path}
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+
+    if [ ! -f $cfg_path ]; then
+        log_conf "Not found $cfg_path" $conf_log_path
+        log_conf "[RESULT] FAILURE" $conf_log_path
+        echo "Not found $stream" >> $conf_err_log_path
+        echo "[RESULT] FAILURE" >> $conf_err_log_path
+        cat $temp_log_path >> $conf_log_path
+        failure_count=$(($failure_count + 1))
+        remain_count=$(($remain_count - 1))
+        count=$(($count + 1))
+        continue
+    fi
+
+    ################################################################################
+    # read from cfg file name                                                      #
+    ################################################################################
+    if [[ $cfg == *"12b"* ]]; then
+        echo "set jpeg_12bit from cfg file name"
+        jpeg_12bit=1
+    fi
+    if [[ $cfg == *"tiled"* ]]; then
+        echo "set g_tiled_mode from cfg file name"
+        default_tiled_mode=1
+    fi
+
+    result=0
+################################################################################
+# make argc & argv parameter                                                   #
+################################################################################
+    if [ $result -eq 0 ]; then
+        generate_parameters $cfg_path
+        build_test_param
+        test_param="$g_func_ret_str"
+
+################################################################################
+# Golden Data                                                                  #
+################################################################################
+        golden_path="output_refc.jpg"
+        generate_golden_stream $line $golden_path
+        result=$?
+
+################################################################################
+# print information                                                            #
+################################################################################
+        if [ $result -eq 0 ]; then
+            log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+            log_conf "RANDOM TEST    : ${ON_OFF[$g_random_test]}" $temp_log_path
+            log_conf "ENDIAN         : STREAM($g_stream_endian) FRAME($g_frame_endian)" $temp_log_path
+            log_conf "STANDARD       : JPEG" $temp_log_path
+            log_conf "PIXEL JUST.    : ${JUSTIFY_NAME[$g_pixel_just]}" $temp_log_path
+            log_conf "TILED MODE     : ${ON_OFF[$g_tiled_mode]}" $temp_log_path
+            log_conf "WIDTH          : $cfg_width" $temp_log_path
+            log_conf "HEIGHT         : $cfg_height" $temp_log_path
+            log_conf "SLICE_HEIGHT   : $g_slice_height" $temp_log_path
+            log_conf "EN_SLICE_INTR  : $g_enable_slice_intr" $temp_log_path
+            log_conf "BS SIZE        : $g_bs_size" $temp_log_path
+            log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+            if [ -e $output_path ]; then
+                rm -f $output_path
+            fi
+            cmd="$test_exec --output=$output_path --cfg-dir=$cfg_dir --yuv-dir=$yuv_dir $test_param --input=$cfg"
+            if [ "$simulation" == "true" ]; then
+                cmd="$cmd $g_w_param $g_fsdb_param --TestRunner=1"
+            fi
+            log_conf "$cmd" $temp_log_path
+            cat $temp_log_path >> $conf_log_path
+
+            if [ "$simulation" == "true" ]; then
+                $cmd 2>&1 | tee -a $conf_log_path
+            else
+				exit
+                $cmd
+            fi
+            log_conf "---------------- COMPARE ------------------" $conf_log_path
+            log_conf "cmp $output_path output_refc.jpg" $conf_log_path
+            if [ "$simulation" == "true" ]; then
+                # For log messages.
+                cmp $output_path output_refc.jpg 2>&1 | tee -a $conf_log_path > /dev/null #save the log
+            fi
+            cmp $output_path output_refc.jpg                                          #get the result & show log
+            if [ "$?" != "0" ]; then
+                log_conf "------- COMPARE FAIL--------------" $conf_log_path
+                result=1
+            else
+                log_conf "------- COMPARE SUCCESS-----------" $conf_log_path
+            fi
+        fi
+    else
+        cat $temp_log_path >> $conf_log_path
+    fi
+
+    if [ $result -eq 0 ]; then
+        log_conf "[RESULT] SUCCESS" $conf_log_path
+        success_count=$(($success_count + 1))
+    else
+        cat ./ErrorLog.txt >> $conf_log_path
+        log_conf "[RESULT] FAILURE" $conf_log_path
+        failure_count=$(($failure_count + 1))
+        cat $temp_log_path >> $conf_err_log_path
+        cat ./ErrorLog.txt >> $conf_err_log_path
+        echo "[RESULT] FAILURE" >> $conf_err_log_path
+        if [ $result -eq 10 ]; then
+            echo "Abnormal exit!!!"
+            break
+        fi
+    fi
+    remain_count=$(($remain_count - 1))
+    count=$(($count + 1))
+    # clear temp log
+    echo "" > $temp_log_path
+done
+
+################################################################################
+# Create Test Log                                                              #
+################################################################################
+endTime=$(date +%s%N)
+elapsed=$((($endTime - $beginTime) / 1000000000))
+elapsedH=$(($elapsed / 3600))
+elapsedS=$(($elapsed % 60))
+elapsedM=$(((($elapsed - $elapsedS) / 60) % 60))
+if [ "$((elapsedS / 10))" == "0" ]; then elapsedS="0${elapsedS}" ;fi
+if [ "$((elapsedM / 10))" == "0" ]; then elapsedM="0${elapsedM}" ;fi
+if [ "$((elapsedH / 10))" == "0" ]; then elapsedH="0${elapsedH}" ;fi
+
+if [ $elapsed -le 60 ]; then
+    time_hms="{color:red}*${elapsedH}:${elapsedM}:${elapsedS}*{color}"
+else
+    time_hms="${elapsedH}:${elapsedM}:${elapsedS}"
+fi
+
+log_filename=$(basename $conf_log_path)
+log_err_filename=$(basename $conf_err_log_path)
+if [ "$failure_count" == "0" ] && [ $num_of_cfgs != 0 ]; then
+    pass=${PASS}
+    rm $conf_err_log_path
+    log_err_filename=""
+else
+    pass=${FAIL}
+fi
+
+wiki_log="| $streamset_file | $num_of_cfgs | $success_count | $failure_count | $remain_count | $log_filename | ${log_err_filename} | $pass | $time_hms | | | |"
+
+echo $wiki_log
+echo $wiki_log >> $wiki_log_file
+
+if [ "$num_of_cfgs" == "0" ]; then
+    echo "num_of_cfgs: $num_of_cfgs = exit 1"
+    exit 1
+fi
+
+exit $failure_count

+ 556 - 0
soft_3rdpart/codaj12/TestRunnerCodaJ12Multi.sh

@@ -0,0 +1,556 @@
+#!/bin/bash
+
+source TestRunnerCommon.sh
+
+# Global varaibles for encoder options
+
+enable_sync=0
+wiki_log_file="./log/confluence.log"
+instance_num=0
+
+DEFAULT_BS_SIZE=5242880    # 5MB
+MIN_BS_SIZE=8192           # 8KB
+
+simulation="false"
+
+################################################################################
+# Initialize parameter variables                                               #
+################################################################################
+
+function help {
+    echo ""
+    echo "-------------------------------------------------------------------------------"
+    echo "Chips&Media conformance Tool v2.0"
+    echo "All copyright reserved by Chips&Media"
+    echo "-------------------------------------------------------------------------------"
+    echo "$0 OPTION --input=cfg1,cfg2,... --instance-num=n"
+    echo "-h                        help"
+    echo "--enable-random           It generates random parameters"
+    echo "--bin-dir                 ref-c directory, default: ../../../design/ref_c/bin/Linux"
+    echo "--cfg-dir                 base directory of encoder configuration files. default: ../../../fpga/board/jpgcfg_v20"
+    echo "--yuv-dir                 base directory storing YUV. default: ./yuv"
+    echo "--enable-tiledMode        enable tiled mode"
+    echo "--stream-endian           ENDIAN  bitstream endianness. refer to datasheet Chapter 4."
+    echo "--frame-endian            ENDIAN   pixel endianness of 16bit input source. refer to datasheet Chapter 4."
+    echo "--slice-height            the vertical height of a slice. multiple of 16 for 420, multiple of 8 for others"
+    echo "--enable-slice-intr       enable get the interrupt at every slice encoded"
+    echo "--pixelj                  16bit-pixel justification. 0(default) - msb justified, 1 - lsb justified in little-endianness"
+    echo "--bs-size                 bitstream buffer size in byte"
+    echo "--instance-num            The number of instances"
+}
+
+function generate_parameters {
+    local input_file=$1
+    local is_encoder=$2
+    local ext="${input_file##%.}"
+
+    if [ "$is_encoder" == "true" ]; then
+        read_cfg $input_file
+    else
+        get_jpeg_info $input_file $jpeg_12bit
+    fi
+
+    if [ "$g_random_test" == "1" ] || [ "$txt_param_switch" == "1" ]; then
+        g_stream_endian=$(gen_val 0 3 $stream_endian_temp)
+        if [ "$jpeg_12bit" == "1" ]; then
+            g_frame_endian=$(gen_val 0 7 $frame_endian_temp)
+        else
+            g_frame_endian=$(gen_val 0 3 $frame_endian_temp)
+        fi
+        slice_random=$(gen_val 0 1) # 0: disable slice done, 1: enable slice_done
+        if [ "$slice_random" == "1" ] || [ "$slice_height_temp" != "0" ]; then
+            if [ "$is_encoder" == "true" ]; then
+                g_slice_height=$(gen_valid_slice_height $cfg_width $cfg_height $cfg_img_format $slice_height_temp)
+            else
+                pic_height_in_8=$(($jpg_height/8))
+                if [ -z $slice_height_temp ]; then
+                    g_slice_height=$(gen_val 0 $pic_height_in_8 $slice_height_temp)
+                    g_slice_height=$(($g_slice_height * 8))
+                else
+                    g_slice_height=$slice_height_temp
+                fi
+            fi
+            if [ "$g_slice_height" != "0" ]; then
+                g_enable_slice_intr=$(gen_val 0 1 $g_enable_slice_intr_temp)
+            else
+                g_enable_slice_intr=0
+            fi
+        else
+            g_slice_height=0
+            g_enable_slice_intr=0
+        fi
+
+        g_pixel_just=$(gen_val 0 1 $pixel_just_temp)
+        g_bs_size=$(gen_val $MIN_BS_SIZE $DEFAULT_BS_SIZE $bs_size_temp)
+        g_bs_size=$((($g_bs_size + 4095) & ~4095))
+        g_tiled_mode=$(gen_val 0 0 $g_tiled_mode_temp)
+    else
+        g_stream_endian=$(gen_val 0 0 $stream_endian_temp)
+        g_frame_endian=$(gen_val 0 0 $frame_endian_temp)
+        if [ "$is_encoder" == "true" ]; then
+            g_slice_height=$(gen_valid_slice_height $cfg_width $cfg_height $cfg_img_format $slice_height_temp)
+        else
+            pic_height_in_8=$(($jpg_height/8))
+            if [ -z $slice_height_temp ]; then
+                g_slice_height=$(gen_val 0 $pic_height_in_8 $slice_height_temp)
+                g_slice_height=$(($g_slice_height * 8))
+            else
+                g_slice_height=$slice_height_temp
+            fi
+        fi
+        g_enable_slice_intr=$(gen_val 0 0 $g_enable_slice_intr_temp)
+        g_pixel_just=$(gen_val 0 0 $pixel_just_temp)
+        g_bs_size=$(gen_val $DEFAULT_BS_SIZE $DEFAULT_BS_SIZE $bs_size_temp)
+        g_bs_size=$((($g_bs_size + 4095) & ~4095))
+        g_tiled_mode=$(gen_val 0 0 $g_tiled_mode_temp)
+    fi
+}
+
+################################################################################
+# Parse arguments                                                              #
+################################################################################
+OPTSTRING="-o e:hw: -l input:"
+OPTSTRING="${OPTSTRING},enable-random,bin-dir:,cfg-dir:,yuv-dir:"
+OPTSTRING="${OPTSTRING},instance-num:,12bit:"
+OPTSTRING="${OPTSTRING},stream-endian:,frame-endian:,output:"
+OPTSTRING="${OPTSTRING},slice-height:,enable-slice-intr:,pixelj:,bs-size:,enable-tiledMode:"
+
+OPTS=`getopt $OPTSTRING -- "$@"`
+
+if [ $? -ne 0 ]; then
+    exit 1
+fi
+
+eval set -- "$OPTS"
+
+while true; do
+    case "$1" in
+        -h)
+            help
+            exit 1
+            shift;;
+        -e)
+            in_comp_param="$2"
+            shift 2;;
+        --bin-dir)
+            bin_dir_user=$2
+            shift 2;;
+        --enable-random)
+            g_random_test=1
+            shift;;
+        --cfg-dir)
+            cfg_dir_user=$2
+            shift 2;;
+        --input)
+            input_param=$2
+            shift 2;;
+        --yuv-dir)
+            yuv_dir_user=$2
+            shift 2;;
+            #shift 2;;
+        --instance-num)
+            instance_num="$2"
+            shift 2;;
+        --12bit)
+            jpeg_12bit_multi=$2
+            shift 2;;
+        --enable-tiledMode)
+            g_tiled_mode_multi=$2
+            shift 2;;
+        --stream-endian)
+            stream_endian_multi="$2"
+            shift 2;;
+        --frame-endian)
+            frame_endian_multi="$2"
+            shift 2;;
+        --slice-height)
+            slice_height_multi="$2"
+            shift 2;;
+        --enable-slice-intr)
+            g_enable_slice_intr_multi="$2"
+            shift 2;;
+        --pixelj)
+            pixel_just_multi="$2"
+            shift 2;;
+        --bs-size)
+            bs_size_multi="$2"
+            shift 2;;
+        --output)
+            output_multi="$2"
+            shift 2;;
+        --)
+            shift
+            break;;
+    esac
+done
+
+shift $(($OPTIND - 1))
+
+yuv_dir="./yuv"
+#bin_dir="../../../design/ref_c/bin/Linux"
+bin_dir="./"
+#cfg_dir="../../../fpga/board/jpgcfg_v20"
+cfg_dir="./cfg"
+if [ "$simulation" == "true" ]; then
+    ACLK_MIN=160
+    ACLK_MAX=300
+    CCLK_MIN=160
+    CCLK_MAX=300
+    DEFAULT_ACLK=200
+    DEFAULT_CCLK=200
+    test_exec="./runit"
+    g_random_test=0
+else
+    DEFAULT_ACLK=20
+    DEFAULT_CCLK=20
+    test_exec="./multi_instance_test"
+fi
+if [ -z $aclk_freq_temp ]; then
+    g_aclk=$DEFAULT_ACLK
+else
+    g_aclk=$aclk_freq_temp
+fi
+if [ -z $cclk_freq_temp ]; then
+    g_cclk=$DEFAULT_CCLK
+else
+    g_cclk=$cclk_freq_temp
+fi
+if [ ! -z $yuv_dir_user ]; then
+    yuv_dir="$yuv_dir_user"
+fi
+if [ ! -z $cfg_dir_user ]; then
+    cfg_dir="$cfg_dir_user"
+fi
+if [ ! -z $bin_dir_user ]; then
+    bin_dir="$bin_dir_user"
+fi
+tiled_exec="./tiled_mode"
+
+if [ ! -f ./$test_exec ] ; then
+    echo " $test_exec file doesn't exist";
+    exit 1
+fi
+
+################################################################################
+# make log info
+################################################################################
+mkdir -p temp
+mkdir -p output
+mkdir -p log/multi_conformance
+if [ $simulation == "true" ]; then
+    conf_log_path="simv.log"
+    conf_err_log_path="simv_error.log"
+else
+    conf_log_path="log/multi_conformance/${streamset_file}.log"
+    conf_err_log_path="log/multi_conformance/${streamset_file}_error.log"
+fi
+temp_log_path="./temp/temp.log"
+echo "" > $conf_log_path
+echo "" > $conf_err_log_path
+echo "" > $temp_log_path
+beginTime=$(date +%s%N)
+
+output=()
+golden=()
+
+################################################################################
+# Add test param                                                               #
+# Options of the each instance are seperated by ","                            #
+################################################################################
+test_param=""
+comp_param=""
+for ((i=0;i<$instance_num;i++)); do
+    #######################
+    # separate parameters #
+    #######################
+    g_tiled_mode_temp=0
+    jpeg_12bit=0
+    if [ -n "$input_param" ]; then
+        filename=$(echo ${input_param} | cut -d',' -f$(($i+1)))
+        ext=${filename##*.}
+        ext=$(tr '[:upper:]' '[:lower:]' <<< $ext)
+        if [ "$ext" == "cfg" ]; then
+            is_encoder="true"
+            input_path=${cfg_dir}/${filename}
+            refc_exec="Nieuport_JpgEnc"
+            output[$i]="instance_${i}_output.jpg"
+            golden[$i]="output_refc_${i}.jpg"
+        else
+            is_encoder="false"
+            input_path="$filename"
+            refc_exec="Nieuport_JpgDec"
+            output[$i]="instance_${i}_output.yuv"
+            golden[$i]="output_refc_${i}.yuv"
+        fi
+        rm -f ${output[$i]}
+        rm -f ${golden[$i]}
+        stream[$i]=$filename
+
+        if [ "$comp_param" != "" ]; then
+            comp_param="${comp_param},"
+        fi
+        if [ "$is_encoder" == "true" ]; then
+            comp_param="${comp_param}0"
+        else
+            comp_param="${comp_param}1"
+        fi
+    fi
+    if [ -n "$output_multi" ]; then
+        output[$i]=$(echo ${output_multi} | cut -d',' -f$(($i+1)))
+    fi
+    if [ -n "$stream_endian_multi" ]; then
+        stream_endian_temp=$(echo ${stream_endian_multi} | cut -d',' -f$(($i+1)))
+    fi
+    if [ -n "$frame_endian_multi" ]; then
+        frame_endian_temp=$(echo ${frame_endian_multi} | cut -d',' -f$(($i+1)))
+    fi
+    if [ -n "$slice_height_multi" ]; then
+        slice_height_temp=$(echo ${slice_height_multi} | cut -d',' -f$(($i+1)))
+    fi
+    if [ -n "$g_enable_slice_intr_multi" ]; then
+        g_enable_slice_intr_temp=$(echo ${g_enable_slice_intr_multi} | cut -d',' -f$(($i+1)))
+    fi
+    if [ -n "$pixel_just_multi" ]; then
+        pixel_just_temp=$(echo ${pixel_just_multi} | cut -d',' -f$(($i+1)))
+    fi
+    if [ -n "$bs_size_multi" ]; then
+        bs_size_temp=$(echo ${bs_size_multi} | cut -d',' -f$(($i+1)))
+    fi
+    if [ -n "$g_tiled_mode_multi" ]; then
+        g_tiled_mode_temp=$(echo ${g_tiled_mode_multi} | cut -d',' -f$(($i+1)))
+    fi
+    if [ -n "$jpeg_12bit_multi" ]; then
+        jpeg_12bit=$(echo ${jpeg_12bit_multi} | cut -d',' -f$(($i+1)))
+    fi
+
+    ################################################################################
+    # read from cfg file name                                                      #
+    ################################################################################
+    if [[ $filename == *"12b"* ]]; then
+        echo "set jpeg_12bit from cfg file name"
+        jpeg_12bit=1
+    fi
+    if [[ $filename == *"tiled"* ]]; then
+        echo "set g_tiled_mode from cfg file name"
+        g_tiled_mode_temp=1
+    fi
+
+    ################################################################################
+    # make argc & argv parameter                                                   #
+    ################################################################################
+    generate_parameters $input_path $is_encoder
+
+    if [ "$is_encoder" == "true" ]; then
+        ################################################################################
+        # Create Input YUV data for tiledMode                                          #
+        ################################################################################
+        if [ "$g_tiled_mode" == "1" ]; then
+           generate_input_yuv ${input_path}
+           result=$?
+
+           if [ "$result" != "0" ]; then
+               log_conf "failed to create yuv file $input_path" $conf_log_path
+               log_conf "[RESULT] FAILURE" $conf_log_path
+               echo "failed to create yuv file $input_path" >> $conf_err_log_path
+               echo "[RESULT] FAILURE" >> $conf_err_log_path
+               continue
+           fi
+        fi
+    fi
+
+    ################################################################################
+    # Golden Data                                                                  #
+    ################################################################################
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+    if [ "$is_encoder" == "true" ]; then
+        generate_golden_stream $filename ${golden[$i]}
+    else
+        if [ "$jpeg_12bit" == "1" ]; then
+            g_jpeg_12bit="true"
+        else
+            g_jpeg_12bit="false"
+        fi
+        generate_golden_yuv $input_path ${golden[$i]}
+    fi
+    result=$?
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+    if [ $result -ne 0 ]; then
+        exit $result
+    fi
+
+    ################################################################################
+    # make test param
+    ################################################################################
+    is_encoder[$i]=0 #encoder
+    if [ "$i" = "0" ]; then
+        codec_std_test_param="${is_encoder[$i]}"
+        stream_test_param="${filename}"
+        if [ -n ${output[$i]} ]; then
+            output_test_param="${output[$i]}"
+        fi
+        stream_endian_test_param="${g_stream_endian}"
+        frame_endian_test_param="${g_frame_endian}"
+        bs_size_test_param="${g_bs_size}"
+        slice_height_test_param="${g_slice_height}"
+        slice_intr_test_param="${g_enable_slice_intr}"
+        tiled_mode_test_param="${g_tiled_mode}"
+        jpeg_12bit_test_param="${jpeg_12bit}"
+        pixelj_test_param="${g_pixel_just}"
+    else
+        codec_std_test_param="${codec_std_test_param},${is_encoder[$i]}"
+        stream_test_param="${stream_test_param},${filename}"
+        if [ -n ${output[$i]} ]; then
+            output_test_param="${output_test_param},${output[$i]}"
+        fi
+        stream_endian_test_param="${stream_endian_test_param},${g_stream_endian}"
+        frame_endian_test_param="${frame_endian_test_param},${g_frame_endian}"
+        bs_size_test_param="${bs_size_test_param},${g_bs_size}"
+        slice_height_test_param="${slice_height_test_param},${g_slice_height}"
+        slice_intr_test_param="${slice_intr_test_param},${g_enable_slice_intr}"
+        tiled_mode_test_param="${tiled_mode_test_param},${g_tiled_mode}"
+        jpeg_12bit_test_param="${jpeg_12bit_test_param},${jpeg_12bit}"
+        pixelj_test_param="${pixelj_test_param},${g_pixel_just}"
+    fi
+
+################################################################################
+# print information                                                            #
+################################################################################
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+    log_conf "RANDOM TEST    : ${ON_OFF[$g_random_test]}" $temp_log_path
+    log_conf "INSTANCE NUM   : $i" $temp_log_path
+    log_conf "CFG            : $filename " $temp_log_path
+    log_conf "ENDIAN         : STREAM($g_stream_endian) FRAME($g_frame_endian)" $temp_log_path
+    log_conf "STANDARD       : JPEG" $temp_log_path
+    log_conf "CBCR interleave: ${ON_OFF[$g_cbcr_interleave]}" $temp_log_path
+    log_conf "PIXEL JUST.    : ${JUSTIFY_NAME[$g_pixel_just]}" $temp_log_path
+    log_conf "TILED MODE     : ${ON_OFF[$g_tiled_mode]}" $temp_log_path
+    log_conf "WIDTH          : $cfg_width" $temp_log_path
+    log_conf "HEIGHT         : $cfg_height" $temp_log_path
+    log_conf "SLICE_HEIGHT   : $g_slice_height" $temp_log_path
+    log_conf "EN_SLICE_INTR  : $g_enable_slice_intr" $temp_log_path
+    log_conf "BS SIZE        : $g_bs_size" $temp_log_path
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+done
+
+if [ "$in_comp_param" != "" ]; then
+    comp_param="$in_comp_param"
+fi
+
+test_param="-e ${comp_param} $g_w_param $g_fsdb_param $g_ius_param"
+test_param="${test_param} --instance-num=${instance_num} --cfg-dir=$cfg_dir --yuv-dir=$yuv_dir"
+test_param="${test_param} --stream-endian=${stream_endian_test_param}"
+test_param="${test_param} --frame-endian=${frame_endian_test_param} --bs-size=${bs_size_test_param}"
+test_param="${test_param} --pixelj=${pixelj_test_param}"
+test_param="${test_param} --slice-height=${slice_height_test_param}"
+test_param="${test_param} --enable-slice-intr=${slice_intr_test_param}"
+test_param="${test_param} --enable-tiledMode=${tiled_mode_test_param}"
+test_param="${test_param} --input=${stream_test_param} --output=${output_test_param}"
+if [ "$simulation" == "true" ]; then
+    test_param="${test_param} --TestRunner=1"
+fi
+
+success_count=0
+failure_count=0
+################################################################################
+################################################################################
+# Test Mode Thread                                                             #
+################################################################################
+################################################################################
+result=0
+log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+log_conf "MultiInstance test : Thread" ${temp_log_path}
+log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+for ((i=0;i<$instance_num;i++)); do
+    log_conf "[${i}/${instance_num}] ${stream[$i]}" ${temp_log_path}
+    if [ -e ${output[$i]} ]; then
+        rm -rf ${output[$i]}
+    fi
+done
+log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+cat $temp_log_path >> $conf_log_path
+
+echo "$test_exec $test_param"
+
+if [ "$simulation" == "true" ]; then
+    $test_exec $test_param 2>&1 | tee -a $conf_log_path
+else
+    echo "$test_exec $test_param"
+	exit #samin
+    #$test_exec $test_param
+fi
+
+if [ $result -eq 0 ]; then
+    log_conf "---------------- COMPARE ------------------" $conf_log_path
+    for ((i=0;i<$instance_num;i++)); do
+        log_conf "cmp ${output[$i]} ${golden[$i]}"  $conf_log_path
+        cmp ${output[$i]} ${golden[$i]} 2>&1 | tee -a $conf_log_path > /dev/null #save the log
+        cmp ${output[$i]} ${golden[$i]} #get the result & show log
+        if [ "$?" != "0" ]; then
+            log_conf "[RESULT] COMPARE FAIL" $conf_log_path
+            result=1
+        fi
+    done
+    if [ $result -eq 0 ]; then
+        log_conf "[RESULT] SUCCESS" $conf_log_path
+        success_count=$(($success_count + 1))
+    fi
+fi
+if [ $result -eq 1 ]; then
+    log_conf "[RESULT] FAILURE" $conf_log_path
+    failure_count=$(($failure_count + 1))
+    cat $temp_log_path >> $conf_err_log_path
+    cat ./ErrorLog.txt >> $conf_err_log_path
+    echo "[RESULT] FAILURE" >> $conf_err_log_path
+    if [ $result -eq 10 ]; then
+        echo "Abnormal exit!!!"
+        break
+    fi
+fi
+
+echo "TEST_CONDITION: $0 $test_param"
+
+# clear temp log
+echo "" > $temp_log_path
+
+
+
+################################################################################
+# Create Test Log                                                              #
+################################################################################
+endTime=$(date +%s%N)
+elapsed=$((($endTime - $beginTime) / 1000000000))
+elapsedH=$(($elapsed / 3600))
+elapsedS=$(($elapsed % 60))
+elapsedM=$(((($elapsed - $elapsedS) / 60) % 60))
+if [ "$((elapsedS / 10))" == "0" ]; then elapsedS="0${elapsedS}" ;fi
+if [ "$((elapsedM / 10))" == "0" ]; then elapsedM="0${elapsedM}" ;fi
+if [ "$((elapsedH / 10))" == "0" ]; then elapsedH="0${elapsedH}" ;fi
+
+if [ $elapsed -le 60 ]; then
+    time_hms="{color:red}*${elapsedH}:${elapsedM}:${elapsedS}*{color}"
+else
+time_hms="${elapsedH}:${elapsedM}:${elapsedS}"
+fi
+
+log_filename=$(basename $conf_log_path)
+log_err_filename=$(basename $conf_err_log_path)
+if [ "$failure_count" == "0" ] && [ "$instance_num" != "0" ]; then
+    pass=${PASS}
+    rm $conf_err_log_path
+    log_err_filename=""
+else
+    pass=${FAIL}
+fi
+
+wiki_log="| $streamset_file | 1 | $success_count | $failure_count | 0 | $log_filename | ${log_err_filename} | $pass | $time_hms | | | Inst Num = $instance_num |"
+
+echo $wiki_log
+echo $wiki_log >> $wiki_log_file
+
+if [ "$instance_num" == "0" ]; then
+    echo "instance_num: $instance_num = exit 1"
+    exit 1
+fi
+
+exit $failure_count
+

+ 639 - 0
soft_3rdpart/codaj12/TestRunnerCommon.sh

@@ -0,0 +1,639 @@
+###############################################################################
+# COMMON DATA
+###############################################################################
+ON_OFF=(
+    "OFF"
+    "ON"
+)
+
+YUV_FORMAT_NAME=(
+    "AUTO"
+    "YUV420"
+    "YUV422"
+    "YUV444"
+    "YUV400"
+)
+
+ENDIAN_NAME=(
+    "VDI_64BIT_LE"
+    "VDI_64BIT_BE"
+    "VDI_32BIT_LE"
+    "VDI_32BIT_BE"
+)
+
+MIRROR_NAME=(
+    "NONE"
+    "VERTICAL"
+    "HORIZONTAL"
+    "BOTH"
+)
+
+JUSTIFY_NAME=(
+    "MSB_JUSTFIED"
+    "LSB_JUSTFIED"
+)
+
+YUV_PACKING_NAME=(
+    "PLANAR"
+    "SEMI-PLANAR(CbCr)"
+    "SEMI-PLANAR(CrCb)"
+    "YUYV"
+    "UYVY"
+    "YVYU"
+    "VYUY"
+    "444 PACK(8BIT)"
+    "PPM(12BIT)"
+)
+
+SCALEDOWN_NAME=(
+    "NONE"
+    "1/2"
+    "1/4"
+    "1/8"
+)
+
+
+PASS="PASS"
+FAIL="FAIL"
+PASS="{color:green}*PASS*{color}"
+FAIL="{color:red}*FAIL*{color}"
+
+###############################################################################
+# GLOBAL VARIABLES
+###############################################################################
+g_fpga_reset=0                       # 1 : reset fpga every time
+g_jpeg_12bit="false"
+
+######################## COMMON VARAIABLES FOR DECODER ########################
+g_yuv_fmt_list=("${YUV_FORMAT_LIST[@]}")
+g_match_mode=1                        # 0 - nomatch, 1 - yuv
+g_aclk=20
+g_cclk=20
+g_secondary_axi=0
+g_stream_endian=0
+g_frame_endian=0
+g_tiled_mode=0
+g_cbcr_format=0                         # 0 - none, 1 - NV12, 2 - NV21
+g_fake_test=0
+
+########################## VARAIABLES FOR PPU #################################
+g_rotation=0
+g_mirror=0
+
+
+###############################################################################
+cmodel_pn_val="" # planar format
+cmodel_pk_val="" # packed format
+cmodel_nv_val="" # semi-planar
+
+###############################################################################
+# GLOBAL FUNCTIONS
+###############################################################################
+# get_random start end
+# generate constraint random value with @start end @end.
+#
+function get_random {
+    start=$1
+    end=$2
+    size=$(($end - $start + 1))
+    val2=$RANDOM
+    val1=$(($val2 % size))
+    val=$(($start + $val1%$size))
+    echo "$val"
+}
+
+function gen_val {
+    local min_val=$1
+    local max_val=$2
+    local default_val=$3
+    local val
+
+    if [ -z $default_val ] || [ "$default_val" == "-99" ]; then
+        # Generate random value
+        val=$(get_random $min_val $max_val)
+    else
+        val=$default_val
+    fi
+    
+    echo "$val"
+}
+
+function gen_val_angle {
+    local default_val=$1
+    local val
+
+    if [ -z $default_val ] || [ "$default_val" == "-99" ]; then
+        val=$(($(get_random 0 3)*90))
+    else
+        val=$default_val
+    fi
+
+    echo "$val"
+}
+
+function gen_yuv_pack_12bit {
+    local yuv_format=$1
+    local default=$2
+    local val
+
+    case $yuv_format in
+    0)  # No conversion
+        val=0;;
+    1)  # YUV420, 3 for ppm format
+        val=$(gen_val 1 3 $default)
+        if [ "$val" == "3" ]; then
+            val=8 # PPM
+        fi
+        ;;
+    2)  # YUV422
+        val=$(gen_val 1 8 $default)
+        if [ "$val" == "7" ]; then
+            # 7 - YUV444 pack mode for 8bit yuv
+            val=8
+        fi
+        ;;
+    3)  # YUV444, 3 for ppm format
+        val=$(gen_val 1 3 $default)
+        if [ "$val" == "3" ]; then
+            val=8
+        fi
+        ;;
+    4)  # YUV400, 1 for ppm format
+        val=$(gen_val 0 1 $default)
+        if [ "$val" == "1" ]; then
+            val=8
+        fi
+        ;;
+    *)  echo "Unknown yuv_format: $yuv_format"
+        exit;;
+    esac
+
+    echo "$val"
+}
+
+function gen_yuv_pack_8bit {
+    local yuv_format=$1
+    local default=$2
+    local val
+
+    case $yuv_format in
+    0)  # No conversion
+        val=0;;
+    1)  # YUV420 
+        val=$(gen_val 1 2 $default)
+        ;;
+    2)  # YUV422
+        val=$(gen_val 1 6 $default)
+        ;;
+    3)  # YUV444, 3 for YUV444 pack
+        val=$(gen_val 1 3 $default)
+        if [ "$val" == "3" ]; then
+            val="7"
+        fi
+        ;;
+    4)  # YUV400
+        val=0
+        ;;
+    *)  echo "Unknown yuv_format: $yuv_format"
+        exit 1;;
+    esac
+
+    echo "$val"
+}
+
+function gen_yuv_pack {
+    local yuv_12bit=$1
+    local yuv_format=$2
+    local default=$3
+    local val
+
+    if [ "$yuv_12bit" == "1" ]; then
+        val=$(gen_yuv_pack_12bit $yuv_format $default)
+    else
+        val=$(gen_yuv_pack_8bit $yuv_format $default)
+    fi
+
+    echo "$val"
+}
+
+
+# log_conf log_message log_file
+# write @log_message to @log_file
+#
+function log_conf {
+    echo "$1" | tee -a "$2"
+}
+
+# parse_streamset_file streamset_path *array
+# - parse streamset file and store data into @g_stream_file_array
+# 
+function parse_streamset_file {
+    local f="$1"
+    local index=0
+    local line=""
+    while read -r line || [ -n "$line" ]; do
+        line="${line#*( )}"         # remove front whitespace
+        line="${line%%[ $'\t']*}"   # remove start of whitespace
+        line="${line//\\//}"        # replace backslash to slash
+        line="${line/$'\r'/}"       # remove carriage return
+        firstchar=${line:0:1}
+        case "$firstchar" in
+            "@") break;;        # exit flag
+            "#") continue;;     # comment
+            ";") continue;;     # comment
+            "")  continue;;     # comment
+            *)
+        esac
+        eval $2[$index]="$line"
+        index=$(($index + 1))
+    done < $f
+}
+
+function convert_fmt_val_for_cmodel {
+    local subsample=$1
+    local orig_subsample=$2
+    local ordering=$3
+
+    ordering=$(tr '[:upper:]' '[:lower:]' <<< $ordering)
+    cmodel_pn_val=0
+    cmodel_pk_val=0
+    cmodel_nv_val=0
+
+    if [ "$ordering" == "none" ]; then
+        case $subsample in
+        420)   cmodel_pn_val=0;;
+        422)   cmodel_pn_val=1;;
+        444)   cmodel_pn_val=3;;
+        *)     cmodel_pn_val=5;;
+        esac
+    else
+        if [ "$ordering" == "nv12" ] || [ "$ordering" == "nv21" ]; then
+            if [ "$subsample" == "none" ]; then
+                cmodel_pn_val=5
+
+                if [ "$ordering" == "nv12" ]; then
+                    cmodel_pk_val=1
+                else
+                    cmodel_pk_val=2
+                fi
+            else
+                case $subsample in
+                400)   cmodel_pn_val=4;;
+                420)   cmodel_pn_val=0;;
+                422)   cmodel_pn_val=1;;
+                440)   cmodel_pn_val=2;;
+                444)   cmodel_pn_val=3;;
+                esac
+
+                if [ "$ordering" == "nv12" ]; then
+                    cmodel_nv_val=1
+                else
+                    cmodel_nv_val=2
+                fi
+            fi
+        else
+            case $ordering in
+            yuyv)   cmodel_pn_val=1
+                    cmodel_pk_val=3;;
+            uyvy)   cmodel_pn_val=1
+                    cmodel_pk_val=4;;
+            yvyu)   cmodel_pn_val=1
+                    cmodel_pk_val=5;;
+            vyuy)   cmodel_pn_val=1
+                    cmodel_pk_val=6;;
+            ayuv)   cmodel_pn_val=3
+                    cmodel_pk_val=7;;
+            esac
+        fi
+    fi
+
+    if [ "$g_tiled_mode" == "1" ]; then
+        if [ "$cmodel_pn_val" == "5" ]; then
+            # no conversion
+            cmodel_nv_val=0
+            cmodel_pk_val=1
+        fi
+    fi
+}
+
+function convert_fmt_val_for_refsw {
+    local fmt=$1
+    local srcsample=$2
+    g_subsample="none"
+    g_ordering="none"
+    case $fmt in
+    420p)   g_subsample="420";;
+    422p)   g_subsample="422";;
+    444p)   g_subsample="444";;
+    nv12)   if [ "$srcsample" != "420" ]; then
+                g_subsample="420"
+            fi
+            g_ordering="nv12";;
+    nv21)   if [ "$srcsample" != "420" ]; then
+                g_subsample="420"
+            fi
+            g_ordering="nv21";;
+    nv16)   if [ "$srcsample" != "422" ]; then
+                g_subsample="422"
+            fi
+            g_ordering="nv12";;
+    nv61)   if [ "$srcsample" != "422" ]; then
+                g_subsample="422"
+            fi
+            g_ordering="nv21";;
+    nv16v)  g_ordering="nv12";;
+    nv61v)  g_ordering="nv21";;
+    nv24)   if [ "$srcsample" != "444" ]; then
+                g_subsample="444"
+            fi
+            g_ordering="nv12";;
+    nv42)   if [ "$srcsample" != "444" ]; then
+                g_subsample="444"
+            fi
+            g_ordering="nv21";;
+    yuyv)   g_ordering="yuyv";;
+    uyvy)   g_ordering="uyvy";;
+    yvyu)   g_ordering="yvyu";;
+    vyuy)   g_ordering="vyuy";;
+    ayuv)   g_ordering="ayuv";;
+    esac
+}
+
+function generate_golden_stream {
+    local input=$1
+    local output=$2
+    local exec_path="${bin_dir}/${refc_exec}"
+    local param=""
+    local cmd=""
+
+    if [ "$jpeg_12bit" == "1" ]; then
+        param="-u"
+    fi
+
+    # ref_c do not support tiled mode.
+    # In case of tiled mode, ref_c output data is same with linear mode.
+    if [ "$g_tiled_mode" == "1" ]; then
+        input=$(echo $input | sed 's/_tiled//g')
+    fi
+
+    param="$param -i $input -o ${output}"
+    param="$param -g $(($g_mirror<<2 | $g_rotation/90))"
+    param="$param -m 1 -ps $yuv_dir -pc $cfg_dir"
+    if [ "$g_slice_height" ]; then
+        param="$param -sh $g_slice_height"
+    fi
+    cmd="$exec_path $param"
+    echo "$cmd"
+
+    $cmd
+
+    return $?
+}
+
+function generate_golden_yuv {
+    local input=$1
+    local output=$2
+    local exec_path="${bin_dir}/${refc_exec}"
+    local param=""
+    local cmd=""
+
+    if [ "$g_jpeg_12bit" == "true" ]; then
+        param="-u"
+    fi
+    if [ "$cmodel_pn_val" != "" ]; then
+        param="$param -pn $cmodel_pn_val" 
+    fi
+    if [ "$cmodel_pk_val" != "" ]; then
+        param="$param -pk $cmodel_pk_val"
+    fi
+    if [ "$cmodel_nv_val" != "" ]; then
+        param="$param -v $cmodel_nv_val"
+    fi
+    param="$param -i $input -o $output"
+    param="$param -g $(($g_mirror<<2 | $g_rotation/90))"
+    if [ "$g_scale_h" != "" ]; then
+        param="$param -sx $g_scale_h"
+    fi
+    if [ "$g_scale_v" != "" ]; then
+        param="$param -sy $g_scale_v"
+    fi
+    if [ "$g_pixel_just" == "1" ]; then
+        param="$param -z"
+    fi
+
+    cmd="$exec_path $param -c"
+    echo "$cmd"
+    $cmd
+
+    return $?
+}
+
+function generate_input_yuv {
+    local input_cfg=$1
+    local param=""
+    local cmd=""
+    local bit_depth=0
+    local input_yuv=""
+    local _srcyuv=""
+    local _width=0
+    local _height=0
+    local _format=0
+    local _name=""
+    local _firstchar=""
+    
+    # Parse input cfg file.
+    while read cfg_line; do
+        _firstchar=${cfg_line:0:1}
+        case "$_firstchar" in
+            "#") continue;;     # comment
+            ";") continue;;     # comment
+            "")  continue;;
+        esac
+        _name=$(echo ${cfg_line} | cut -d' ' -f1)
+        if [ "$_name" = "YUV_SRC_IMG" ]; then
+            _srcyuv=$(echo ${cfg_line} | cut -d' ' -f2)
+        elif [ "$_name" = "PICTURE_WIDTH" ]; then
+            _width=$(echo ${cfg_line} | cut -d' ' -f2)
+        elif [ "$_name" = "PICTURE_HEIGHT" ]; then
+            _height=$(echo ${cfg_line} | cut -d' ' -f2)
+        elif [ "$_name" = "IMG_FORMAT" ]; then
+            _format=$(echo ${cfg_line} | cut -d' ' -f2)
+        fi
+    done < $input_cfg
+
+    # Check the file exist
+    echo "${yuv_dir}/${_srcyuv}"
+    if [ -f "${yuv_dir}/${_srcyuv}" ]; then
+        echo "File exist : ${yuv_dir}/${_srcyuv}"
+        return 0
+    fi
+
+    # Copy lenear yuv
+    input_yuv=$(echo $_srcyuv | sed 's/_tiled//g')
+    cp "${yuv_dir}/${input_yuv}" ./
+
+    if [ "$jpeg_12bit" == "1" ]; then
+        bit_depth="16"
+    else
+        bit_depth="8"
+    fi
+
+    param="-i ${input_yuv} -o ${_srcyuv} --width=${_width} --height=${_height} --bit-depth=${bit_depth} --format=${_format} --map-type=1"
+
+    # Execute tiled_mode program
+    if [ "$simulation" == "true" ]; then
+        gcc -o $tiled_exec ../../../fpga/board/ref-sw/tools/tiled_mode.c
+    else
+        gcc -o $tiled_exec tools/tiled_mode.c
+    fi
+    cmd="$tiled_exec $param"
+    echo "$cmd"
+
+    $cmd
+    result=$?
+
+    if [ "$result" != "0" ]; then
+        return 1
+    fi
+
+    cp "${_srcyuv}" "${yuv_dir}/${_srcyuv}"
+    return 0
+}
+
+# string get_stream_path(cfgfile)
+function generate_golden_stream_path {
+    local cfgfile=$1
+
+    streamset_name=$(basename $streamset_path)
+    temp=`expr match "$streamset_name" '.*\(_[0-9]*\.cmd\)'`
+    if [ "$temp" != "" ]; then
+        streamset_name="${streamset_name%_[0-9]*\.cmd}.cmd"
+    fi
+    echo "streamset_name: $streamset_name"
+    path="${stream_dir}/$codec_dir/$streamset_name"
+    cfgname=$(basename $cfgfile)
+    if [ ! -d "$path" ]; then
+        mkdir -p "$path"
+    fi
+
+    path="$path/${cfgname}_0.$ext"
+
+    g_func_ret_str=$path
+}
+
+function read_cfg {
+    local cfg=$1
+    if [ -f ${cfg} ]; then
+        while read line2; do
+            # remove right comment
+            line2=$(echo $line2 | tr -d '\n')
+            line2=$(echo $line2 | tr -d '\r')
+            line2="${line2%%\#*}"
+    
+            attr=$(echo $line2 | cut -d' ' -f1)
+            attr=$(echo $attr | tr -d ' ')
+    
+            value=$(echo $line2 | cut -d' ' -f2)
+            #echo "attr=$attr, value=$value"
+    
+            case "$attr" in
+                PICTURE_WIDTH)  cfg_width="$value";;
+                PICTURE_HEIGHT) cfg_height="$value";;
+                IMG_FORMAT)     cfg_img_format="$value";;
+                *) ;;
+            esac
+        done < $cfg
+    else
+        echo "File is not exist ($cfg)"
+        exit 1
+    fi
+}
+
+function get_jpeg_info {
+    local format=""
+    local cmd="${bin_dir}/${refc_exec} -i $1 -m 1" 
+
+    if [ "$2" == "1" ]; then
+        cmd="$cmd -u"
+    fi
+    $cmd > result.txt
+    while read line; do
+        line=$(echo $line | tr -d '\n')
+        line=$(echo $line | tr -d '\r')
+        line="${line%%\#*}"
+        attr=$(echo $line | cut -d':' -f1)
+        attr=$(echo $attr | tr -d ' ')
+        value=$(echo $line | cut -d':' -f2-)
+        value=$(echo $value | tr -d ' ')
+        value="${value//:/}"
+        if [ "$attr" == "OutputYUVformat" ]; then
+            jpg_format="$value"
+            break
+        elif [ "$attr" == "Pictureconfig" ]; then
+            value=${value%@*}    
+            jpg_width=$(echo $value | cut -d'x' -f1)
+            jpg_height=$(echo $value | cut -d'x' -f2)
+        fi
+    done < result.txt
+
+    echo "$format"
+}
+
+
+function gen_valid_slice_height {
+    local pic_width=$1
+    local pic_height=$2
+    local fmt=$3
+    local default=$4
+    local temp=0
+    local sample_factor_x=1
+    local sample_factor_y=1
+    local mcu_height=8
+    local slice_height=0
+    local num_mcu_h=0
+
+    if [ ! -z $default ] && [ "$default" != "-99" ]; then
+        echo "$default"
+        return
+    fi
+
+    case $fmt in
+    0) # YUV420
+       sample_factor_x=2
+       sample_factor_y=2
+       mcu_height=16;;
+    1) # YUV422
+       sample_factor_x=2
+       mcu_height=8;;
+    2) # YUV440
+       sample_factor_y=2
+       mcu_height=16;;
+    4) # YUV400
+       mcu_height=32;;
+    *) ;;
+    esac
+    num_mcu_h=$(($pic_height/$mcu_height))
+
+    mcu_num_x_fac=$(($sample_factor_x * 8))
+    mcu_num_y_fac=$(($sample_factor_y * 8))
+    mcu_num_w=$((($pic_width+($mcu_num_x_fac-1))/$mcu_num_x_fac))
+
+    temp=$(gen_val 1 $(($pic_height / $mcu_height)) $default)
+    while [ $temp -gt 0 ] ; do
+        slice_height=$(($temp * $mcu_height))
+        s_mcu_num_h=$((($slice_height+($mcu_num_y_fac-1))/$mcu_num_y_fac))
+        total_mcu_in_slice=$(($mcu_num_w * $s_mcu_num_h))
+        if [ $total_mcu_in_slice -lt 65536 ]; then
+            # A value of restart interval should be less than 65536
+            break
+        fi
+        temp=$(gen_val 1 $(($pic_height / $mcu_height)) $default)
+    done
+
+    if [ "$slice_height" == "$pic_height" ]; then
+        slice_height=$(($slice_height - $mcu_height))
+    fi
+
+    echo "$slice_height"
+}
+

+ 0 - 0
soft_3rdpart/codaj12/TestRunnerParamCodaJ12Dec.txt


+ 0 - 0
soft_3rdpart/codaj12/TestRunnerParamCodaJ12Enc.txt


+ 21 - 0
soft_3rdpart/codaj12/build_ffmpeg.sh

@@ -0,0 +1,21 @@
+#!/bin/sh
+cmd=$1
+PWD=`pwd`
+FFMPEG=${PWD}/ffmpeg
+FFMPEG_SRC=${FFMPEG}/src
+FFMPEG_INC=${FFMPEG}/include
+FFMPEG_LIB=${FFMPEG}/lib
+FFMPEG_BIN=${FFMPEG}/bin
+FFMPEG_SHARE=${FFMPEG}/share
+FFMPEG_VERSION="2.1.8"
+CPU_CORE=`cat /proc/cpuinfo |grep "processor"|wc -l`
+
+if [ $1 == "clean" ];then   #clean
+	rm -rf $FFMPEG_INC $FFMPEG_LIB $FFMPEG_BIN $FFMPEG_SHARE $FFMPEG_SRC/ffmpeg-${FFMPEG_VERSION}
+else     					#build
+	cd $FFMPEG_SRC
+	tar -xvf ffmpeg-${FFMPEG_VERSION}.tar.gz
+	cd ffmpeg-${FFMPEG_VERSION}
+	./config_ffmpeg_riscv.sh
+	make -j${CPU_CORE} && make install
+fi

+ 50 - 0
soft_3rdpart/codaj12/build_for_riscv.sh

@@ -0,0 +1,50 @@
+#!/bin/bash
+jpu_path=`pwd`
+#output="../../work/buildroot_initramfs_sysroot"
+output="./jpu_driver"
+jpu_driver=${jpu_path}/jdi/linux/driver
+jpu_env=${jpu_driver}/build_env_setup_riscv.sh
+obj_jpu=$output
+obj_jpu_driver=${obj_jpu}/driver
+
+#set env
+#source $jpu_env
+
+#mkdir
+if [ ! -d $obj_jpu ];then
+	mkdir -p $obj_jpu
+fi
+if [ ! -d $obj_jpu_driver ];then
+	mkdir -p $obj_jpu_driver
+fi
+
+#cp test files
+cp -rdvp ${jpu_path}/script/* ${obj_jpu}/
+cp -rdvp ${jpu_path}/cfg $obj_jpu
+cp -rdvp ${jpu_path}/yuv $obj_jpu
+cp -rdvp ${jpu_path}/stream $obj_jpu
+cp -dvp ${jpu_driver}/load.sh $obj_jpu_driver
+cp -dvp ${jpu_driver}/unload.sh $obj_jpu_driver
+
+#make linux driver
+cd $jpu_driver
+source build_env_setup_riscv.sh
+make clean
+make
+
+#make multi_instance
+cd $jpu_path
+make clean
+make MAKECMDGOALS=multi USE_FFMPEG=no
+cp ${jpu_path}/multi_instance_test $obj_jpu
+
+#make decoder/encoder
+make clean
+make USE_FFMPEG=no
+cp ${jpu_path}/jpg_enc_test ${jpu_path}/jpg_dec_test $obj_jpu
+
+#cp driver
+cp ${jpu_driver}/jpu.ko $obj_jpu_driver
+cp -rdvp jpu_driver ../../work/buildroot_initramfs_sysroot/root/
+
+

+ 62 - 0
soft_3rdpart/codaj12/cfg/HuffmanTable01.cfg

@@ -0,0 +1,62 @@
+// DC index 0 (Luminance DC) Bits
+00 01 05 01 01 01 01 01
+01 00 00 00 00 00 00 00
+// DC index 0 (Luminance DC) HuffValue
+00 01 02 03 04 05 06 07
+08 09 0A 0B
+// AC index 0 (Luminance AC) Bits
+00 02 01 03 03 02 04 03
+05 05 04 04 00 00 01 7D
+// AC index 0 (Luminance AC) HuffValue
+01 02 03 00 04 11 05 12
+21 31 41 06 13 51 61 07
+22 71 14 32 81 91 A1 08
+23 42 B1 C1 15 52 D1 F0
+24 33 62 72 82 09 0A 16
+17 18 19 1A 25 26 27 28
+29 2A 34 35 36 37 38 39
+3A 43 44 45 46 47 48 49
+4A 53 54 55 56 57 58 59
+5A 63 64 65 66 67 68 69
+6A 73 74 75 76 77 78 79
+7A 83 84 85 86 87 88 89
+8A 92 93 94 95 96 97 98
+99 9A A2 A3 A4 A5 A6 A7
+A8 A9 AA B2 B3 B4 B5 B6
+B7 B8 B9 BA C2 C3 C4 C5
+C6 C7 C8 C9 CA D2 D3 D4
+D5 D6 D7 D8 D9 DA E1 E2
+E3 E4 E5 E6 E7 E8 E9 EA
+F1 F2 F3 F4 F5 F6 F7 F8
+F9 FA
+// DC index 1 (Chrominance DC) Bits
+00 03 01 01 01 01 01 01
+01 01 01 00 00 00 00 00
+// DC index 1 (Chrominance DC) HuffValue
+00 01 02 03 04 05 06 07
+08 09 0A 0B
+// AC index 1 (Chrominance AC) Bits
+00 02 01 02 04 04 03 04
+07 05 04 04 00 01 02 77
+// AC index 1 (Chrominance AC)) HuffValue
+00 01 02 03 11 04 05 21
+31 06 12 41 51 07 61 71
+13 22 32 81 08 14 42 91
+A1 B1 C1 09 23 33 52 F0
+15 62 72 D1 0A 16 24 34
+E1 25 F1 17 18 19 1A 26
+27 28 29 2A 35 36 37 38
+39 3A 43 44 45 46 47 48
+49 4A 53 54 55 56 57 58
+59 5A 63 64 65 66 67 68
+69 6A 73 74 75 76 77 78
+79 7A 82 83 84 85 86 87
+88 89 8A 92 93 94 95 96
+97 98 99 9A A2 A3 A4 A5
+A6 A7 A8 A9 AA B2 B3 B4
+B5 B6 B7 B8 B9 BA C2 C3
+C4 C5 C6 C7 C8 C9 CA D2
+D3 D4 D5 D6 D7 D8 D9 DA
+E2 E3 E4 E5 E6 E7 E8 E9
+EA F2 F3 F4 F5 F6 F7 F8
+F9 FA

+ 84 - 0
soft_3rdpart/codaj12/cfg/HuffmanTable01_ES.cfg

@@ -0,0 +1,84 @@
+// DC index 0 (Luminance DC) Bits
+00 02 03 01 00 03 01 01
+01 01 00 00 00 00 00 00
+// DC index 0 (Luminance DC) HuffValue
+08 09 06 07 0A 05 03 04
+0B 02 00 01 0C
+// AC index 0 (Luminance AC) Bits
+00 01 04 02 02 02 01 04
+01 02 00 01 00 01 00 EB
+// AC index 0 (Luminance AC) HuffValue
+02 01 03 04 05 06 07 08
+12 09 11 13 00 14 21 22
+15 0a 23 31 16 32 17 24
+33 41 18 25 42 51 0b 26
+19 43 52 61 35 62 71 0c
+0d 0e 0f 10 1a 1b 1c 1d
+1e 1f 20 27 28 29 2a 2b
+2c 2d 2e 2f 30 34 36 37
+38 39 3a 3b 3c 3d 3e 3f
+40 44 45 46 47 48 49 4a
+4b 4c 4d 4e 4f 50 53 54
+55 56 57 58 59 5a 5b 5c
+5d 5e 5f 60 63 64 65 66
+67 68 69 6a 6b 6c 6d 6e
+6f 70 72 73 74 75 76 77
+78 79 7a 7b 7c 7d 7e 7f
+80 81 82 83 84 85 86 87
+88 89 8a 8b 8c 8d 8e 8f
+90 91 92 93 94 95 96 97
+98 99 9a 9b 9c 9d 9e 9f
+a0 a1 a2 a3 a4 a5 a6 a7
+a8 a9 aa ab ac ad ae af
+b0 b1 b2 b3 b4 b5 b6 b7
+b8 b9 ba bb bc bd be bf
+c0 c1 c2 c3 c4 c5 c6 c7
+c8 c9 ca cb cc cd ce cf
+d0 d1 d2 d3 d4 d5 d6 d7
+d8 d9 da db dc dd de df
+e0 e1 e2 e3 e4 e5 e6 e7
+e8 e9 ea eb ec ed ee ef
+f0 f1 f2 f3 f4 f5 f6 f7
+f8 f9 fa fb fc fd fe ff
+// DC index 1 (Chrominance DC) Bits
+00 02 02 02 03 01 01 01
+01 00 00 00 00 00 00 00
+// DC index 1 (Chrominance DC) HuffValue
+06 07 05 08 04 09 02 03
+0A 01 0B 00 0C
+// AC index 1 (Chrominance AC) Bits
+00 01 03 02 05 01 05 05
+03 07 04 04 03 04 06 CB
+// AC index 1 (Chrominance AC)) HuffValue
+01 02 03 11 04 21 00 05
+06 12 31 41 07 13 22 51
+61 08 14 32 71 81 42 91
+a1 09 15 23 52 b1 c1 f0
+16 62 d1 e1 0a 24 72 f1
+17 82 92 33 43 53 b2 0b
+0c 18 35 a2 c2 0d 0e 0f
+10 19 1a 1b 1c 1d 1e 1f
+20 25 26 27 28 29 2a 2b
+2c 2d 2e 2f 30 34 36 37
+38 39 3a 3b 3c 3d 3e 3f
+40 44 45 46 47 48 49 4a
+4b 4c 4d 4e 4f 50 54 55
+56 57 58 59 5a 5b 5c 5d
+5e 5f 60 63 64 65 66 67
+68 69 6a 6b 6c 6d 6e 6f
+70 73 74 75 76 77 78 79
+7a 7b 7c 7d 7e 7f 80 83
+84 85 86 87 88 89 8a 8b
+8c 8d 8e 8f 90 93 94 95
+96 97 98 99 9a 9b 9c 9d
+9e 9f a0 a3 a4 a5 a6 a7
+a8 a9 aa ab ac ad ae af
+b0 b3 b4 b5 b6 b7 b8 b9
+ba bb bc bd be bf c0 c3
+c4 c5 c6 c7 c8 c9 ca cb
+cc cd ce cf d0 d2 d3 d4
+d5 d6 d7 d8 d9 da db dc
+dd de df e0 e2 e3 e4 e5
+e6 e7 e8 e9 ea eb ec ed
+ee ef f2 f3 f4 f5 f6 f7
+f8 f9 fa fb fc fd fe ff

+ 18 - 0
soft_3rdpart/codaj12/cfg/QuantTable00.cfg

@@ -0,0 +1,18 @@
+; Quality 0 Luma
+14 11 11 1A 12 1A 29 18
+18 29 33 27 20 27 33 27
+1C 1C 1C 1C 27 22 17 17
+17 17 17 22 11 0C 0C 0C
+0C 0C 0C 11 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+; Quality 0 Chroma
+15 1A 1A 21 1D 21 22 18
+18 22 14 0E 0E 0E 14 14
+0E 0E 0E 0E 14 11 0C 0C
+0C 0C 0C 11 11 0C 0C 0C
+0C 0C 0C 11 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C

+ 18 - 0
soft_3rdpart/codaj12/cfg/QuantTable01.cfg

@@ -0,0 +1,18 @@
+; Quality 1 Luma
+0C 08 08 08 09 08 0C 09
+09 0C 11 0B 0A 0B 11 15
+0F 0C 0C 0F 15 18 13 13
+15 13 13 18 11 0C 0C 0C
+0C 0C 0C 11 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+; Quality 1 Chroma
+0D 0B 0B 0D 0E 0D 10 0E
+0E 10 14 0E 0E 0E 14 14
+0E 0E 0E 0E 14 11 0C 0C
+0C 0C 0C 11 11 0C 0C 0C
+0C 0C 0C 11 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C

+ 18 - 0
soft_3rdpart/codaj12/cfg/QuantTable02.cfg

@@ -0,0 +1,18 @@
+; Quality 3 Luma
+06 04 04 04 05 04 06 05
+05 06 09 06 05 06 09 0B
+08 06 06 08 0B 0C 0A 0A
+0B 0A 0A 0C 10 0C 0C 0C
+0C 0C 0C 10 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+; Quality 3 Chroma
+07 07 07 0D 0C 0D 18 10
+10 18 14 0E 0E 0E 14 14
+0E 0E 0E 0E 14 11 0C 0C
+0C 0C 0C 11 11 0C 0C 0C
+0C 0C 0C 11 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C
+0C 0C 0C 0C 0C 0C 0C 0C

+ 18 - 0
soft_3rdpart/codaj12/cfg/QuantTableEX_23.cfg

@@ -0,0 +1,18 @@
+; Quality 23 Luma
+0023 0018 0016 0023 0034 0057 006f 0084
+001a 001a 001e 0029 0038 007e 0082 0077
+001e 001c 0023 0034 0057 007c 0096 007a
+001e 0025 0030 003f 006f 00bd 00ae 0087
+0027 0030 0050 007a 0094 00ed 00e0 00a7
+0034 004c 0077 008b 00b0 00e2 00f5 00c8
+006a 008b 00a9 00bd 00e0 0107 0104 00db
+009c 00c8 00ce 00d5 00f3 00d9 00e0 00d7
+; Quality 23 Chroma
+0025 0027 0034 0066 00d7 00d7 00d7 00d7
+0027 002e 0038 008f 00d7 00d7 00d7 00d7
+0034 0038 007a 00d7 00d7 00d7 00d7 00d7
+0066 008f 00d7 00d7 00d7 00d7 00d7 00d7
+00d7 00d7 00d7 00d7 00d7 00d7 00d7 00d7
+00d7 00d7 00d7 00d7 00d7 00d7 00d7 00d7
+00d7 00d7 00d7 00d7 00d7 00d7 00d7 00d7
+00d7 00d7 00d7 00d7 00d7 00d7 00d7 00d7

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI400_qcif_inI400.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_I400.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  4
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 34 - 0
soft_3rdpart/codaj12/cfg/outI400_qcif_inI400_12b.cfg

@@ -0,0 +1,34 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_I400_12b.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  4
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTableEX_23.cfg
+QMATRIX_PREC0               1
+QMATRIX_PREC1               1
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01_ES.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI400_qcif_inUYVY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_UYVY.yuv
+FRAME_FORMAT                 4
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  4
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI400_qcif_inVYUY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_VYUY.yuv
+FRAME_FORMAT                 6
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  4
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI400_qcif_inYUYV.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YUYV.yuv
+FRAME_FORMAT                 3
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  4
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI400_qcif_inYVYU.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YVYU.yuv
+FRAME_FORMAT                 5
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  4
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI420_cif_inNV12.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  mobile_cif_NV12.yuv
+FRAME_FORMAT                 1
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                352
+PICTURE_HEIGHT               288
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  0
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI420_cif_inNV12_tiled.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  mobile_cif_NV12_tiled.yuv
+FRAME_FORMAT                 1
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                352
+PICTURE_HEIGHT               288
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  0
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI420_qcif_inI420.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_I420.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  0
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 34 - 0
soft_3rdpart/codaj12/cfg/outI420_qcif_inI420_12b.cfg

@@ -0,0 +1,34 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_I420_12b.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  0
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTableEX_23.cfg
+QMATRIX_PREC0               1
+QMATRIX_PREC1               1
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01_ES.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI420_qcif_inNV12.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_NV12.yuv
+FRAME_FORMAT                 1
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  0
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI420_qcif_inNV21.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_NV21.yuv
+FRAME_FORMAT                 2
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  0
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI420_qcif_inUYVY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_UYVY.yuv
+FRAME_FORMAT                 4
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI420_qcif_inVYUY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_VYUY.yuv
+FRAME_FORMAT                 6
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI420_qcif_inYUYV.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YUYV.yuv
+FRAME_FORMAT                 3
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI420_qcif_inYVYU.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YVYU.yuv
+FRAME_FORMAT                 5
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI422_qcif_inI422.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_I422.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 34 - 0
soft_3rdpart/codaj12/cfg/outI422_qcif_inI422_12b.cfg

@@ -0,0 +1,34 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_I422_12b.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTableEX_23.cfg
+QMATRIX_PREC0               1
+QMATRIX_PREC1               1
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01_ES.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI422_qcif_inNV16.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_NV16.yuv
+FRAME_FORMAT                 1
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI422_qcif_inNV16_tiled.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_NV16_tiled.yuv
+FRAME_FORMAT                 1
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI422_qcif_inNV61.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_NV61.yuv
+FRAME_FORMAT                 2
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI422_qcif_inUYVY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_UYVY.yuv
+FRAME_FORMAT                 4
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI422_qcif_inVYUY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_VYUY.yuv
+FRAME_FORMAT                 6
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI422_qcif_inYUYV.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YUYV.yuv
+FRAME_FORMAT                 3
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI422_qcif_inYVYU.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YVYU.yuv
+FRAME_FORMAT                 5
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  1
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI440_qcif_in16NV.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_16NV.yuv
+FRAME_FORMAT                 1
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  2
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI440_qcif_in61NV.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_61NV.yuv
+FRAME_FORMAT                 2
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  2
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI440_qcif_inI440.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_I440.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  2
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 34 - 0
soft_3rdpart/codaj12/cfg/outI440_qcif_inI440_12b.cfg

@@ -0,0 +1,34 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_I440_12b.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  2
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTableEX_23.cfg
+QMATRIX_PREC0               1
+QMATRIX_PREC1               1
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01_ES.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI440_qcif_inUYVY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_UYVY.yuv
+FRAME_FORMAT                 4
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  2
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI440_qcif_inVYUY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_VYUY.yuv
+FRAME_FORMAT                 6
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  2
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI440_qcif_inYUYV.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YUYV.yuv
+FRAME_FORMAT                 3
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  2
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI440_qcif_inYVYU.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YVYU.yuv
+FRAME_FORMAT                 5
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  2
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_3840_2160_inI444.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  pic_3840_2160_I444.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                3840
+PICTURE_HEIGHT               2160
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_4608_3456_inI444.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  pic_4608_3456_I444.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                4608
+PICTURE_HEIGHT               3456
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_cif_inNV24.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  mobile_cif_NV24.yuv
+FRAME_FORMAT                 1
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                352
+PICTURE_HEIGHT               288
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_cif_inNV24_tiled.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  mobile_cif_NV24_tiled.yuv
+FRAME_FORMAT                 1
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                352
+PICTURE_HEIGHT               288
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_qcif_inI444.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_I444.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_qcif_inNV24.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_NV24.yuv
+FRAME_FORMAT                 1
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_qcif_inNV42.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_NV42.yuv
+FRAME_FORMAT                 2
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_qcif_inUYVY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_UYVY.yuv
+FRAME_FORMAT                 4
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_qcif_inVYUY.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_VYUY.yuv
+FRAME_FORMAT                 6
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_qcif_inYUVP.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YUVP.yuv
+FRAME_FORMAT                 7
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_qcif_inYUYV.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YUYV.yuv
+FRAME_FORMAT                 3
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 32 - 0
soft_3rdpart/codaj12/cfg/outI444_qcif_inYVYU.cfg

@@ -0,0 +1,32 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  stefan_qcif_YVYU.yuv
+FRAME_FORMAT                 5
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                176
+PICTURE_HEIGHT               144
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTable02.cfg
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01.cfg

+ 34 - 0
soft_3rdpart/codaj12/cfg/outI444_vga_inI444_12b.cfg

@@ -0,0 +1,34 @@
+;-----------------------------------------------------------------
+; Configuration File for MJPEG BP @ Encoder
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+;----------------------------
+; Sequence PARAMETERs
+;----------------------------
+; source YUV image file
+YUV_SRC_IMG                  foreman_vga_I444_12b.yuv
+FRAME_FORMAT                 0
+                            ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
+                            ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
+PICTURE_WIDTH                640
+PICTURE_HEIGHT               480
+FRAME_RATE					30
+FRAME_NUMBER_ENCODED         1
+                            ; number of frames to be encoded (#>0)
+;---------------------------------------
+; MJPEG Encodeing PARAMETERs
+;---------------------------------------
+VERSION_ID					3
+RESTART_INTERVAL			0
+IMG_FORMAT                  3
+                            ; Source Format (0 : 4:2:0, 1 : 4:2:2, 2 : 4:4:0, 3 : 4:4:4, 4 : 4:0:0)
+; Component Information Table
+COMPINFO_TABLE				CinfoTable420.cfg
+; QMatrix Table
+QMATRIX_TABLE				QuantTableEX_23.cfg
+QMATRIX_PREC0               1
+QMATRIX_PREC1               1
+; Huffman Table
+HUFFMAN_TABLE				HuffmanTable01_ES.cfg

+ 8 - 0
soft_3rdpart/codaj12/cmd/jpg_dec_test_12b.cmd

@@ -0,0 +1,8 @@
+enc_0_1280_720_420_ref_12b.jpg
+enc_0_176_144_400_ref_12b.jpg
+enc_0_176_144_420_ref_12b.jpg
+enc_0_176_144_422_ref_12b.jpg
+enc_0_176_144_440_ref_12b.jpg
+enc_0_176_144_444_ref_12b.jpg
+enc_0_352_288_420_ref_12b.jpg
+enc_0_640_480_420_ref_12b.jpg

+ 6 - 0
soft_3rdpart/codaj12/cmd/jpg_dec_test_8b.cmd

@@ -0,0 +1,6 @@
+enc_0_176_144_400_ref.jpg
+enc_0_176_144_420_ref.jpg
+enc_0_176_144_422_ref.jpg
+enc_0_176_144_440_ref.jpg
+enc_0_176_144_444_ref.jpg
+

+ 5 - 0
soft_3rdpart/codaj12/cmd/jpg_enc_test_12b.cmd

@@ -0,0 +1,5 @@
+outI400_qcif_inI400_12b.cfg
+outI420_qcif_inI420_12b.cfg
+outI422_qcif_inI422_12b.cfg
+outI440_qcif_inI440_12b.cfg
+outI444_vga_inI444_12b.cfg

+ 42 - 0
soft_3rdpart/codaj12/cmd/jpg_enc_test_8b.cmd

@@ -0,0 +1,42 @@
+;-----------------------------------------------------------------
+; List filenames of bitstreams to be tested.
+;
+; NOTE.
+; If a line begins with ;, the line is treated as a comment-line.
+;-----------------------------------------------------------------
+; YUV files not exist
+;-----------------------------------------------------------------
+outI400_qcif_inI400.cfg
+outI400_qcif_inUYVY.cfg
+outI400_qcif_inVYUY.cfg
+outI400_qcif_inYUYV.cfg
+outI400_qcif_inYVYU.cfg
+outI420_qcif_inI420.cfg
+outI420_qcif_inNV12.cfg
+outI420_qcif_inNV21.cfg
+outI420_qcif_inUYVY.cfg
+outI420_qcif_inVYUY.cfg
+outI420_qcif_inYUYV.cfg
+outI420_qcif_inYVYU.cfg
+outI422_qcif_inI422.cfg
+outI422_qcif_inNV16.cfg
+outI422_qcif_inNV61.cfg
+outI422_qcif_inUYVY.cfg
+outI422_qcif_inVYUY.cfg
+outI422_qcif_inYUYV.cfg
+outI422_qcif_inYVYU.cfg
+outI440_qcif_in16NV.cfg
+outI440_qcif_in61NV.cfg
+outI440_qcif_inI440.cfg
+outI440_qcif_inUYVY.cfg
+outI440_qcif_inVYUY.cfg
+outI440_qcif_inYUYV.cfg
+outI440_qcif_inYVYU.cfg
+outI444_qcif_inI444.cfg
+outI444_qcif_inNV24.cfg
+outI444_qcif_inNV42.cfg
+outI444_qcif_inUYVY.cfg
+outI444_qcif_inVYUY.cfg
+outI444_qcif_inYUVP.cfg
+outI444_qcif_inYUYV.cfg
+outI444_qcif_inYVYU.cfg

+ 41 - 0
soft_3rdpart/codaj12/codaj12Driver_buildroot.mak

@@ -0,0 +1,41 @@
+# Comment/uncomment the	following line to disable/enable debugging
+#DEBUG = y
+
+# Add your debugging flag (or not) to CFLAGS
+ifeq ($(DEBUG),y)
+  DEBFLAGS = -O	-g # "-O" is needed to expand inlines
+else
+  DEBFLAGS = -O2
+endif
+
+export ARCH=riscv
+export SUBARCH=riscv
+export CROSS_COMPILE=riscv64-buildroot-linux-gnu-
+
+DRV_PATH  := $(shell pwd)/jdi/linux/driver
+EXTRA_CFLAGS +=	$(DEBFLAGS) -I$(LDDINCDIR) -Wno-unused-function
+
+ifneq ($(KERNELRELEASE),)
+# call from kernel build system
+
+obj-m	:= jdec.o
+
+else
+
+default:
+	$(MAKE) -C $(KERNELDIR)	M=$(DRV_PATH) LDDINCDIR=$(DRV_PATH)/../include modules
+
+endif
+
+
+
+clean:
+	rm -rf $(DRV_PATH)/*.o $(DRV_PATH)/*~ $(DRV_PATH)/core $(DRV_PATH)/.depend $(DRV_PATH)/.*.cmd $(DRV_PATH)/*.ko $(DRV_PATH)/*.mod.c $(DRV_PATH)/modules.order $(DRV_PATH)/.tmp_versions $(DRV_PATH)/*.dwo $(DRV_PATH)/.*.dwo
+
+depend .depend dep:
+	$(CC) $(CFLAGS)	-M *.c > .depend
+
+
+ifeq (.depend,$(wildcard .depend))
+include	.depend
+endif

+ 148 - 0
soft_3rdpart/codaj12/codaj12_buildroot.mak

@@ -0,0 +1,148 @@
+# ----------------------------------------------------------------------
+#
+# codaj12
+#
+# ----------------------------------------------------------------------
+.PHONY: CREATE_DIR
+BUILD_CONFIGURATION := EmbeddedRiscvLinux
+PRODUCT := CODAJ12
+PRODUCT := CODDAJ12C
+
+USE_PTHREAD = yes
+USE_RTL_SIM = no
+LINT_HOME   = etc/lint
+
+UNAME = $(shell uname -a)
+ifneq (,$(findstring i386, $(UNAME)))
+    USE_32BIT = yes
+endif
+
+ifeq ($(RTL_SIM), 1)
+USE_RTL_SIM = yes
+endif
+
+REFC    := 0
+
+ifeq ($(USE_32BIT), yes)
+PLATFORM    = nativelinux
+else
+PLATFORM    = nativelinux_64bit
+endif
+
+CROSS_CC_PREFIX =
+JDI_C           = jdi/linux/jdi.c
+VDI_OSAL_C      =
+MM_C            =
+PLATFORM_FLAGS  =
+JDI_VPATH       = jdi/linux
+ifeq ("$(BUILD_CONFIGURATION)", "NonOS")
+    CROSS_CC_PREFIX = arm-none-eabi-
+    JDI_C           = jdi/nonos/jdi.c
+    VDI_OSAL_C      =
+    MM_C            = jdi/mm.c
+    USE_PTHREAD     = no
+    PLATFORM        = none
+    DEFINES         = -DLIB_C_STUB
+    PLATFORM_FLAGS  =
+    JDI_VPATH       = jdi/nonos
+    NONOS_RULE      = options_nonos.lnt
+endif
+ifeq ("$(BUILD_CONFIGURATION)", "EmbeddedLinux")
+    CROSS_CC_PREFIX = arm-none-linux-gnueabi-
+    PLATFORM        = armlinux
+endif
+
+ifeq ("$(BUILD_CONFIGURATION)", "EmbeddedRiscvLinux")
+    CROSS_CC_PREFIX = riscv64-buildroot-linux-gnu-
+    PLATFORM        = riscvlinux
+endif
+CC  = $(CROSS_CC_PREFIX)gcc
+CXX = $(CROSS_CC_PREFIX)g++
+LINKER=$(CC)
+AR  = $(CROSS_CC_PREFIX)ar
+
+INCLUDES = -I./jpuapi -I./ffmpeg/include -I./sample/helper -I./sample -I./jdi -I../
+ifeq ($(USE_RTL_SIM), yes)
+DEFINES += -DCNM_SIM_PLATFORM -DCNM_SIM_DPI_INTERFACE -DSUPPORT_DECODER
+DEFINES += -D$(PRODUCT) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
+else
+DEFINES += -D$(PRODUCT) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
+endif	# USE_SIM_PLATFORM
+DEFINES += -DUSE_FEEDING_METHOD_BUFFER
+
+CFLAGS  += -g -I. -Wno-implicit-function-declaration -Wno-format -Wl,--fatal-warning $(INCLUDES) $(DEFINES) $(PLATFORM_FLAGS)
+ifeq ($(USE_RTL_SIM), yes)
+ifeq ($(IUS), 1)
+CFLAGS  += -fPIC # ncverilog is 64bit version
+endif
+endif
+ARFLAGS += cru
+
+LDFLAGS  = $(PLATFORM_FLAGS)
+
+ifeq ($(USE_PTHREAD), yes)
+LDLIBS  += -lpthread
+endif
+LDLIBS  += -lm
+
+BUILDLIST=DECTEST
+MAKEFILE=codaj12_buildroot.mak
+DECTEST=libcodadec.so
+
+OBJDIR=obj
+ALLOBJS=*.o
+ALLDEPS=*.dep
+ALLLIBS=*.a
+RM=rm -f
+MKDIR=mkdir -p
+
+SOURCES_COMMON = jpuapi.c jpuapifunc.c jpuhelper.c jpulog.c cnm_fpga.c main_jpg_dec_test.c \
+                platform.c datastructure.c bitstreamfeeder.c bsfeeder_fixedsize_impl.c bsfeeder_buffer_impl.c\
+                $(JDI_C)             \
+                $(VDI_OSAL_C)        \
+                $(MM_C)
+
+VPATH = jdi:
+VPATH += sample:
+VPATH += sample/helper:
+VPATH += $(JDI_VPATH):jpuapi
+
+VPATH2=$(patsubst %,-I%,$(subst :, ,$(VPATH)))
+
+OBJECTNAMES_COMMON=$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES_COMMON)))
+OBJECTPATHS_COMMON=$(addprefix $(OBJDIR)/,$(notdir $(OBJECTNAMES_COMMON)))
+
+SOURCES_DECTEST = sample/main_jpg_dec_test.c
+ifeq ($(USE_RTL_SIM), yes)
+	SOURCES_DECTEST += sample/main_sim.c
+endif
+
+OBJECTNAMES_DECTEST=$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES_DECTEST)))
+OBJECTPATHS_DECTEST=$(addprefix $(OBJDIR)/,$(notdir $(OBJECTNAMES_DECTEST))) $(OBJECTPATHS_COMMON)
+
+all: $(BUILDLIST)
+
+ifeq ($(USE_RTL_SIM), yes)
+DECTEST: CREATE_DIR $(OBJECTPATHS_COMMON)
+else
+DECTEST: CREATE_DIR $(OBJECTPATHS_COMMON)
+	$(LINKER) -g -fPIC -shared -o $(DECTEST) $(LDFLAGS) -Wl,-gc-section -Wl,--start-group $(OBJECTPATHS_COMMON) $(LDLIBS) -Wl,--end-group
+endif
+
+
+-include $(OBJECTPATHS:.o=.dep)
+
+clean:
+	$(RM) $(DECTEST)
+	$(RM) $(OBJDIR)/$(ALLOBJS)
+	$(RM) $(OBJDIR)/$(ALLDEPS)
+
+CREATE_DIR:
+	-mkdir -p $(OBJDIR)
+
+obj/%.o: %.c $(MAKEFILE)
+	$(CC) -fPIC -shared $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+lint:
+	"$(LINT_HOME)/flint" -i"$(LINT_HOME)" $(DEFINES) $(INCLUDES) $(VPATH2) linux_std.lnt $(HAPS_RULE) $(NONOS_RULE)  $(SOURCES_COMMON)
+

+ 27 - 0
soft_3rdpart/codaj12/config.h

@@ -0,0 +1,27 @@
+//------------------------------------------------------------------------------
+// File: config.h
+//
+// Copyright (c) 2006, Chips & Media.  All rights reserved.
+// This file should be modified by some developers of C&M according to product version.
+//------------------------------------------------------------------------------
+
+
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WIN32) || defined(__MINGW32__)
+#	define PLATFORM_WIN32
+#elif defined(linux) || defined(__linux) || defined(ANDROID)
+#	define PLATFORM_LINUX
+#else
+#	define PLATFORM_NON_OS
+#endif
+
+
+#define API_VERSION 0x125
+
+
+
+#endif	/* __CONFIG_H__ */
+

BIN
soft_3rdpart/codaj12/ffmpeg/riscvlinux/libz.a


BIN
soft_3rdpart/codaj12/ffmpeg/src/ffmpeg-2.1.8.tar.gz


+ 131 - 0
soft_3rdpart/codaj12/jdi/jdi.h

@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2018, Chips&Media
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _JDI_HPI_H_
+#define _JDI_HPI_H_
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#ifdef USE_FEEDING_METHOD_BUFFER
+    #include "codaj12/jpuapi/jpuconfig.h"
+    #include "codaj12/jdi/mm.h"
+    #include "codaj12/jpuapi/jputypes.h"
+#else
+    #include "../jpuapi/jpuconfig.h"
+    #include "mm.h"
+    #include "jputypes.h"
+#endif
+
+
+#define MAX_JPU_BUFFER_POOL 32
+#define JpuWriteInstReg( INST_IDX, ADDR, DATA )		jdi_write_register( ((unsigned long)INST_IDX*NPT_REG_SIZE)+ADDR, DATA ) // system register write 	with instance index
+#define JpuReadInstReg( INST_IDX, ADDR )		jdi_read_register( ((unsigned long)INST_IDX*NPT_REG_SIZE)+ADDR ) // system register write 	with instance index
+#define JpuWriteReg( ADDR, DATA )                   jdi_write_register( ADDR, DATA ) // system register write
+#define JpuReadReg( ADDR )                          jdi_read_register( ADDR )           // system register write
+#define JpuWriteMem( ADDR, DATA, LEN, ENDIAN )      jdi_write_memory( ADDR, DATA, LEN, ENDIAN ) // system memory write
+#define JpuReadMem( ADDR, DATA, LEN, ENDIAN )       jdi_read_memory( ADDR, DATA, LEN, ENDIAN ) // system memory write
+
+
+typedef struct jpu_buffer_t {
+    unsigned int  size;
+    unsigned long phys_addr;
+    unsigned long base;
+    unsigned long virt_addr;
+} jpu_buffer_t;
+
+typedef struct jpu_instance_pool_t {
+    unsigned char   jpgInstPool[MAX_NUM_INSTANCE][MAX_INST_HANDLE_SIZE];
+    Int32           jpu_instance_num;
+    BOOL            instance_pool_inited;
+	void*           instPendingInst[MAX_NUM_INSTANCE];
+    jpeg_mm_t       vmem;
+} jpu_instance_pool_t;
+
+
+typedef enum {
+    JDI_LITTLE_ENDIAN = 0,
+    JDI_BIG_ENDIAN,
+    JDI_32BIT_LITTLE_ENDIAN,
+    JDI_32BIT_BIG_ENDIAN,
+} EndianMode;
+
+
+typedef enum {
+    JDI_LOG_CMD_PICRUN  = 0,
+    JDI_LOG_CMD_INIT  = 1,
+    JDI_LOG_CMD_RESET  = 2,
+    JDI_LOG_CMD_PAUSE_INST_CTRL = 3,
+    JDI_LOG_CMD_MAX
+} jdi_log_cmd;
+
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+    int jdi_probe();
+    /* @brief It returns the number of task using JDI.
+     */
+    int jdi_get_task_num();
+    int jdi_init();
+    int jdi_release();    //this function may be called only at system off.
+    jpu_instance_pool_t *jdi_get_instance_pool();
+    int jdi_allocate_dma_memory(jpu_buffer_t *vb);
+    void jdi_free_dma_memory(jpu_buffer_t *vb);
+
+    int jdi_wait_interrupt(int timeout, unsigned int addr_int_reason, unsigned long instIdx);
+    int jdi_hw_reset();
+    int jdi_wait_inst_ctrl_busy(int timeout, unsigned int addr_flag_reg, unsigned int flag);
+    int jdi_set_clock_gate(int enable);
+    int jdi_get_clock_gate();
+
+    int jdi_open_instance(unsigned long instIdx);
+    int jdi_close_instance(unsigned long instIdx);
+    int jdi_get_instance_num();
+
+
+    void jdi_write_register(unsigned long addr, unsigned long data);
+    unsigned long jdi_read_register(unsigned long addr);
+
+    int jdi_write_memory(unsigned long addr, unsigned char *data, int len, int endian);
+    int jdi_read_memory(unsigned long addr, unsigned char *data, int len, int endian);
+
+    int jdi_lock();
+    void jdi_unlock();
+    void jdi_log(int cmd, int step, int inst);
+    void jdi_flush_ddr(unsigned long start,unsigned long size,unsigned char flag);
+#define ACLK_MAX                    300
+#define ACLK_MIN                    16
+#define CCLK_MAX                    300
+#define CCLK_MIN                    16
+
+
+
+
+#if defined (__cplusplus)
+}
+#endif
+
+#endif //#ifndef _JDI_HPI_H_

+ 49 - 0
soft_3rdpart/codaj12/jdi/linux/driver/Makefile

@@ -0,0 +1,49 @@
+# Comment/uncomment the	following line to disable/enable debugging
+#DEBUG = y
+
+# Add your debugging flag (or not) to CFLAGS
+ifeq ($(DEBUG),y)
+  DEBFLAGS = -O	-g # "-O" is needed to expand inlines
+else
+  DEBFLAGS = -O2
+endif
+
+export CC="$(CROSS_COMPILE)gcc"
+export AR="$(CROSS_COMPILE)ar"
+export CXX="${CROSS_COMPILE}g++"
+export AS="${CROSS_COMPILE}as"
+export LD="${CROSS_COMPILE}ld"
+export RANLIB="${CROSS_COMPILE}ranlib"
+export READELF="${CROSS_COMPILE}readelf"
+export STRIP="${CROSS_COMPILE}strip"
+
+
+EXTRA_CFLAGS +=	$(DEBFLAGS) -I$(LDDINCDIR)
+
+ifneq ($(KERNELRELEASE),)
+# call from kernel build system
+
+obj-m	:= jpu.o
+
+else
+
+KERNELDIR := ../../../../../work/linux/
+PWD	  := $(shell pwd)
+
+default:
+	$(MAKE)	-C $(KERNELDIR)	M=$(PWD) LDDINCDIR=$(PWD)/../include modules
+
+endif
+
+
+
+clean:
+	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
+
+depend .depend dep:
+	$(CC) $(CFLAGS)	-M *.c > .depend
+
+
+ifeq (.depend,$(wildcard .depend))
+include	.depend
+endif

+ 51 - 0
soft_3rdpart/codaj12/jdi/linux/driver/Makefile.usb

@@ -0,0 +1,51 @@
+# Comment/uncomment the	following line to disable/enable debugging
+#DEBUG = y
+
+# Add your debugging flag (or not) to CFLAGS
+ifeq ($(DEBUG),y)
+  DEBFLAGS = -O	-g # "-O" is needed to expand inlines
+else
+  DEBFLAGS = -O2
+endif
+
+export CC="$(CROSS_COMPILE)gcc"
+export AR="$(CROSS_COMPILE)ar"
+export CXX="${CROSS_COMPILE}g++"
+export AS="${CROSS_COMPILE}as"
+export LD="${CROSS_COMPILE}ld"
+export RANLIB="${CROSS_COMPILE}ranlib"
+export READELF="${CROSS_COMPILE}readelf"
+export STRIP="${CROSS_COMPILE}strip"
+
+
+//EXTRA_CFLAGS +=	$(DEBFLAGS) -I$(LDDINCDIR) 
+EXTRA_CFLAGS +=	$(DEBFLAGS) -I$(LDDINCDIR)  -DCNM_FPGA_PLATFORM -DCNM_FPGA_USB_INTERFACE -DCONFIG_PM
+
+ifneq ($(KERNELRELEASE),)
+# call from kernel build system
+
+obj-m	:= jpu.o
+
+else
+
+KERNELDIR ?= ../../../../../work/linux/
+
+PWD	  := $(shell pwd)
+
+default:
+	$(MAKE)	-C $(KERNELDIR)	M=$(PWD) LDDINCDIR=$(PWD)/../include modules
+
+endif
+
+
+
+clean:
+	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
+
+depend .depend dep:
+	$(CC) $(CFLAGS)	-M *.c > .depend
+
+
+ifeq (.depend,$(wildcard .depend))
+include	.depend
+endif

+ 0 - 0
soft_3rdpart/codaj12/jdi/linux/driver/Module.symvers


+ 4 - 0
soft_3rdpart/codaj12/jdi/linux/driver/build_env_setup_android.sh

@@ -0,0 +1,4 @@
+export PATH=/home/ta/work/android_tcc-4.2.2/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH
+export ARCH=arm
+export SUBARCH=arm
+export CROSS_COMPILE=arm-eabi-

+ 8 - 0
soft_3rdpart/codaj12/jdi/linux/driver/build_env_setup_riscv.sh

@@ -0,0 +1,8 @@
+PWD=`pwd`
+RISCV_TOOLCHAIN_BASE=${PWD}/../../../../../work/buildroot_initramfs/host
+echo $RISCV_TOOLCHAIN_BASE
+export PATH=${RISCV_TOOLCHAIN_BASE}/bin:$PATH
+export LD_LIBRARY_PATH=${RISCV_TOOLCHAIN_BASE}/lib:$LD_LIBRARY_PATH
+export ARCH=riscv
+export SUBARCH=riscv
+export CROSS_COMPILE=riscv64-buildroot-linux-gnu-

+ 109 - 0
soft_3rdpart/codaj12/jdi/linux/driver/driver.dsp

@@ -0,0 +1,109 @@
+# Microsoft Developer Studio Project File - Name="driver" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) External Target" 0x0106
+
+CFG=driver - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "driver.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "driver.mak" CFG="driver - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "driver - Win32 Release" (based on "Win32 (x86) External Target")
+!MESSAGE "driver - Win32 Debug" (based on "Win32 (x86) External Target")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+
+!IF  "$(CFG)" == "driver - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Cmd_Line "NMAKE /f driver.mak"
+# PROP BASE Rebuild_Opt "/a"
+# PROP BASE Target_File "driver.exe"
+# PROP BASE Bsc_Name "driver.bsc"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Cmd_Line "nmake /f "driver.mak""
+# PROP Rebuild_Opt "/a"
+# PROP Target_File "driver.exe"
+# PROP Bsc_Name ""
+# PROP Target_Dir ""
+
+!ELSEIF  "$(CFG)" == "driver - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Cmd_Line "NMAKE /f driver.mak"
+# PROP BASE Rebuild_Opt "/a"
+# PROP BASE Target_File "driver.exe"
+# PROP BASE Bsc_Name "driver.bsc"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Cmd_Line "nmake /f "driver.mak""
+# PROP Rebuild_Opt "/a"
+# PROP Target_File "driver.exe"
+# PROP Bsc_Name ""
+# PROP Target_Dir ""
+
+!ENDIF 
+
+# Begin Target
+
+# Name "driver - Win32 Release"
+# Name "driver - Win32 Debug"
+
+!IF  "$(CFG)" == "driver - Win32 Release"
+
+!ELSEIF  "$(CFG)" == "driver - Win32 Debug"
+
+!ENDIF 
+
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\jpu.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\jpu.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# Begin Source File
+
+SOURCE=.\Makefile
+# End Source File
+# End Target
+# End Project

+ 29 - 0
soft_3rdpart/codaj12/jdi/linux/driver/driver.dsw

@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "driver"=.\driver.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+

+ 646 - 0
soft_3rdpart/codaj12/jdi/linux/driver/jmm.h

@@ -0,0 +1,646 @@
+#ifndef __CNM_JPU_MM_H__
+#define __CNM_JPU_MM_H__
+
+
+typedef unsigned long long  jmem_key_t;
+
+#define JMEM_PAGE_SIZE           (16*1024)
+#define MAKE_KEY(_a, _b)        (((jmem_key_t)_a)<<32 | _b)
+#define KEY_TO_VALUE(_key)      (_key>>32)
+
+typedef struct page_struct {
+	int             pageno;
+	unsigned long   addr;
+	int             used;
+	int             alloc_pages;
+	int             first_pageno;
+} page_t;
+
+
+typedef struct avl_node_struct {
+	jmem_key_t   key;
+	int     height;
+	page_t* page;
+	struct avl_node_struct* left;
+	struct avl_node_struct* right;
+} avl_node_t;
+
+
+typedef struct _jpu_mm_struct {
+	avl_node_t*     free_tree;
+	avl_node_t*     alloc_tree;
+	page_t*         page_list;
+	int             num_pages;
+	unsigned long   base_addr;
+	unsigned long   mem_size;
+	int             free_page_count;
+	int             alloc_page_count;
+} jpu_mm_t;
+
+
+
+#define VMEM_P_ALLOC(_x)         kmalloc(_x, GFP_KERNEL)
+#define VMEM_P_FREE(_x)          kfree(_x)
+
+#define VMEM_ASSERT(_exp)        if (!(_exp)) { printk(KERN_INFO "VMEM_ASSERT at %s:%d\n", __FILE__, __LINE__); /*while(1);*/ }
+#define VMEM_HEIGHT(_tree)       (_tree==NULL ? -1 : _tree->height)
+
+
+#define MAX(_a, _b)         (_a >= _b ? _a : _b)
+
+typedef enum {
+    LEFT,
+    RIGHT
+} rotation_dir_t;
+
+
+
+typedef struct avl_node_data_struct {
+    int     key;
+    page_t* page;
+} avl_node_data_t;
+
+static avl_node_t*
+make_avl_node(
+    jmem_key_t key,
+    page_t* page
+    )
+{
+    avl_node_t* node = (avl_node_t*)VMEM_P_ALLOC(sizeof(avl_node_t));
+    node->key     = key;
+    node->page    = page;
+    node->height  = 0;
+    node->left    = NULL;
+    node->right   = NULL;
+
+    return node;
+}
+
+
+static int
+get_balance_factor(
+    avl_node_t* tree
+    )
+{
+    int factor = 0;
+    if (tree) {
+        factor = VMEM_HEIGHT(tree->right) - VMEM_HEIGHT(tree->left);
+    }
+
+    return factor;
+}
+
+/*
+ * Left Rotation
+ *
+ *      A                      B
+ *       \                    / \
+ *        B         =>       A   C
+ *       /  \                 \
+ *      D    C                 D
+ *
+ */
+static avl_node_t*
+rotation_left(
+    avl_node_t* tree
+    )
+{
+    avl_node_t* rchild;
+    avl_node_t* lchild;
+
+    if (tree == NULL) return NULL;
+    
+    rchild = tree->right;
+    if (rchild == NULL) {
+        return tree;
+    }
+
+    lchild = rchild->left;
+    rchild->left = tree;
+    tree->right = lchild;
+
+    tree->height   = MAX(VMEM_HEIGHT(tree->left), VMEM_HEIGHT(tree->right)) + 1;
+    rchild->height = MAX(VMEM_HEIGHT(rchild->left), VMEM_HEIGHT(rchild->right)) + 1;
+
+    return rchild;
+}
+
+
+/*
+ * Reft Rotation
+ *
+ *         A                  B
+ *       \                  /  \
+ *      B         =>       D    A
+ *    /  \                     /
+ *   D    C                   C
+ *
+ */
+static avl_node_t*
+rotation_right(
+    avl_node_t* tree
+    )
+{
+    avl_node_t* rchild;
+    avl_node_t* lchild;
+
+    if (tree == NULL) return NULL;
+
+    lchild = tree->left;
+    if (lchild == NULL) return NULL;
+
+    rchild = lchild->right;
+    lchild->right = tree;
+    tree->left = rchild;
+
+    tree->height   = MAX(VMEM_HEIGHT(tree->left), VMEM_HEIGHT(tree->right)) + 1;
+    lchild->height = MAX(VMEM_HEIGHT(lchild->left), VMEM_HEIGHT(lchild->right)) + 1;
+
+    return lchild;
+}
+
+static avl_node_t*
+do_balance(
+    avl_node_t* tree
+    )
+{
+    int bfactor = 0, child_bfactor;       /* balancing factor */
+
+    bfactor = get_balance_factor(tree);
+
+    if (bfactor >= 2) {
+        child_bfactor = get_balance_factor(tree->right);
+        if (child_bfactor == 1 || child_bfactor == 0) {
+            tree = rotation_left(tree);
+        } else if (child_bfactor == -1) {
+            tree->right = rotation_right(tree->right);
+            tree        = rotation_left(tree);
+        } else {
+            printk(KERN_INFO "invalid balancing factor: %d\n", child_bfactor);
+            VMEM_ASSERT(0);
+            return NULL;
+        }
+    } else if (bfactor <= -2) {
+        child_bfactor = get_balance_factor(tree->left);
+        if (child_bfactor == -1 || child_bfactor == 0) {
+            tree = rotation_right(tree);
+        } else if (child_bfactor == 1) {
+            tree->left = rotation_left(tree->left);
+            tree       = rotation_right(tree);
+        } else {
+            printk(KERN_INFO "invalid balancing factor: %d\n", child_bfactor);
+            VMEM_ASSERT(0);
+            return NULL;
+        }
+    }
+    
+    return tree;
+}
+static avl_node_t*
+unlink_end_node(
+    avl_node_t* tree,
+    int dir,
+    avl_node_t** found_node
+    )
+{
+    avl_node_t* node;
+    *found_node = NULL;
+
+    if (tree == NULL) return NULL;
+
+    if (dir == LEFT) {
+        if (tree->left == NULL) {
+            *found_node = tree;
+            return NULL;
+        }
+    } else {
+        if (tree->right == NULL) {
+            *found_node = tree;
+            return NULL;
+        }
+    }
+
+    if (dir == LEFT) {
+        node = tree->left;
+        tree->left = unlink_end_node(tree->left, LEFT, found_node);
+        if (tree->left == NULL) {
+            tree->left = (*found_node)->right;
+            (*found_node)->left  = NULL;
+            (*found_node)->right = NULL;
+        }
+    } else {
+        node = tree->right;
+        tree->right = unlink_end_node(tree->right, RIGHT, found_node);
+        if (tree->right == NULL) {
+            tree->right = (*found_node)->left;
+            (*found_node)->left  = NULL;
+            (*found_node)->right = NULL;
+        }
+    }
+
+    tree->height = MAX(VMEM_HEIGHT(tree->left), VMEM_HEIGHT(tree->right)) + 1;
+
+    return do_balance(tree);
+}
+
+
+static avl_node_t*
+avltree_insert(
+    avl_node_t* tree,
+    jmem_key_t key,
+    page_t* page
+    )
+{
+    if (tree == NULL) {
+        tree = make_avl_node(key, page);
+    } else {
+        if (key >= tree->key) {
+            tree->right = avltree_insert(tree->right, key, page);
+        } else {
+            tree->left  = avltree_insert(tree->left, key, page);
+        }
+    }
+
+    tree = do_balance(tree);
+
+    tree->height = MAX(VMEM_HEIGHT(tree->left), VMEM_HEIGHT(tree->right)) + 1;
+
+    return tree;
+}
+
+static avl_node_t*
+do_unlink(
+    avl_node_t* tree
+    )
+{
+    avl_node_t* node;
+    avl_node_t* end_node;
+    node = unlink_end_node(tree->right, LEFT, &end_node);
+    if (node) {
+        tree->right = node;
+    } else {
+        node = unlink_end_node(tree->left, RIGHT, &end_node);
+        if (node) tree->left = node;
+    }
+
+    if (node == NULL) {
+        node = tree->right ? tree->right : tree->left;
+        end_node = node;
+    }
+
+    if (end_node) {
+        end_node->left  = (tree->left != end_node) ? tree->left : end_node->left;
+        end_node->right = (tree->right != end_node) ? tree->right : end_node->right;
+        end_node->height = MAX(VMEM_HEIGHT(end_node->left), VMEM_HEIGHT(end_node->right)) + 1;
+    } 
+
+    tree = end_node;
+
+    return tree;
+}
+
+static avl_node_t*
+avltree_remove(
+    avl_node_t* tree,
+    avl_node_t** found_node,
+    jmem_key_t key
+    )
+{
+    *found_node = NULL;
+    if (tree == NULL) {
+        printk(KERN_INFO "failed to find key %d\n", (int)key);
+        return NULL;
+    } 
+
+    if (key == tree->key) {
+        *found_node = tree;
+        tree = do_unlink(tree);
+    } else if (key > tree->key) {
+        tree->right = avltree_remove(tree->right, found_node, key);
+    } else {
+        tree->left  = avltree_remove(tree->left, found_node, key);
+    }
+
+    if (tree) tree->height = MAX(VMEM_HEIGHT(tree->left), VMEM_HEIGHT(tree->right)) + 1;
+
+    tree = do_balance(tree);
+
+    return tree;
+}
+
+void
+avltree_free(
+    avl_node_t* tree
+    )
+{
+    if (tree == NULL) return;
+    if (tree->left == NULL && tree->right == NULL) {
+        VMEM_P_FREE(tree);
+        return;
+    }
+
+    avltree_free(tree->left);
+    tree->left = NULL;
+    avltree_free(tree->right);
+    tree->right = NULL;
+}
+
+
+
+
+static avl_node_t*
+remove_approx_value(
+    avl_node_t* tree,
+    avl_node_t** found,
+    jmem_key_t key
+    )
+{
+    *found = NULL;
+    if (tree == NULL) {
+        return NULL;
+    }
+
+    if (key == tree->key) {
+        *found = tree;
+        tree = do_unlink(tree);
+    } else if (key > tree->key) {
+        tree->right = remove_approx_value(tree->right, found, key);
+    } else {
+        tree->left  = remove_approx_value(tree->left, found, key);
+        if (*found == NULL) {
+            *found = tree;
+            tree = do_unlink(tree);
+        }
+    }
+    if (tree) tree->height = MAX(VMEM_HEIGHT(tree->left), VMEM_HEIGHT(tree->right)) + 1;
+    tree = do_balance(tree);
+
+    return tree;
+}
+
+static void
+set_blocks_free(
+	jpu_mm_t *mm,
+    int pageno,
+    int npages
+    )
+{
+    int last_pageno     = pageno + npages - 1;
+    int i;
+    page_t* page;
+    page_t* last_page;
+
+    VMEM_ASSERT(npages);
+
+    if (last_pageno >= mm->num_pages) {
+        printk(KERN_INFO "set_blocks_free: invalid last page number: %d\n", last_pageno);
+        VMEM_ASSERT(0);
+        return;
+    }
+
+    for (i=pageno; i<=last_pageno; i++) {
+        mm->page_list[i].used         = 0;
+        mm->page_list[i].alloc_pages  = 0;
+        mm->page_list[i].first_pageno = -1;
+    }
+
+    page        = &mm->page_list[pageno];
+    page->alloc_pages = npages;
+    last_page   = &mm->page_list[last_pageno];    
+    last_page->first_pageno = pageno;
+
+    mm->free_tree = avltree_insert(mm->free_tree, MAKE_KEY(npages, pageno), page);
+}
+
+static void
+set_blocks_alloc(
+	jpu_mm_t *mm,
+    int pageno,
+    int npages
+    )
+{
+    int last_pageno     = pageno + npages - 1;
+    int i;
+    page_t* page;
+    page_t* last_page;
+
+    if (last_pageno >= mm->num_pages) {
+        printk(KERN_INFO "set_blocks_free: invalid last page number: %d\n", last_pageno);
+        VMEM_ASSERT(0);
+        return;
+    }
+
+    for (i=pageno; i<=last_pageno; i++) {
+        mm->page_list[i].used         = 1;
+        mm->page_list[i].alloc_pages  = 0;
+        mm->page_list[i].first_pageno = -1;
+    }
+
+    page        = &mm->page_list[pageno];
+    page->alloc_pages = npages;
+
+    last_page   = &mm->page_list[last_pageno];    
+    last_page->first_pageno = pageno;
+
+    mm->alloc_tree = avltree_insert(mm->alloc_tree, MAKE_KEY(page->addr, 0), page);
+}
+
+
+int
+jmem_init(
+	jpu_mm_t* mm, 
+	unsigned long addr,
+    unsigned long size
+    )
+{
+    int i;
+	
+	
+    mm->base_addr  = (addr+(JMEM_PAGE_SIZE-1))&~(JMEM_PAGE_SIZE-1);
+    mm->mem_size   = size&~JMEM_PAGE_SIZE;
+    mm->num_pages  = mm->mem_size/JMEM_PAGE_SIZE;
+    mm->page_list  = (page_t*)VMEM_P_ALLOC(mm->num_pages*sizeof(page_t));
+    mm->free_tree  = NULL;
+    mm->alloc_tree = NULL;
+    mm->free_page_count = mm->num_pages;
+    mm->alloc_page_count = 0;
+
+    for (i=0; i<mm->num_pages; i++) {
+        mm->page_list[i].pageno       = i;
+        mm->page_list[i].addr         = mm->base_addr + i*JMEM_PAGE_SIZE;
+        mm->page_list[i].alloc_pages  = 0;
+        mm->page_list[i].used         = 0;
+        mm->page_list[i].first_pageno = -1;
+    }
+
+    set_blocks_free(mm, 0, mm->num_pages);
+	
+    return 0;
+}
+
+int
+jmem_exit(
+	jpu_mm_t* mm
+    )
+{
+	if (mm == NULL) {
+        printk(KERN_INFO "vmem_exit: invalid handle\n");
+        return -1;
+    }
+
+    if (mm->free_tree) {
+        avltree_free(mm->free_tree);
+    }
+    if (mm->alloc_tree) {
+        avltree_free(mm->alloc_tree);
+    }
+
+    VMEM_P_FREE(mm->page_list);
+	
+	mm->base_addr  = 0;
+	mm->mem_size   = 0;
+	mm->num_pages  = 0;
+	mm->page_list  = NULL;
+	mm->free_tree  = NULL;
+	mm->alloc_tree = NULL;
+	mm->free_page_count = 0;
+	mm->alloc_page_count = 0;
+    return 0;
+}
+
+unsigned long
+jmem_alloc(
+	jpu_mm_t* mm,
+    int size,
+	unsigned long pid
+    )
+{
+    avl_node_t* node;
+    page_t*     free_page;
+    int         npages, free_size;
+    int         alloc_pageno;
+    unsigned long  ptr;
+	
+	if (mm == NULL) {
+		printk(KERN_INFO "vmem_alloc: invalid handle\n");
+		return -1;
+	}
+
+    if (size <= 0) return -1;
+
+	npages = (size + JMEM_PAGE_SIZE -1)/JMEM_PAGE_SIZE;
+
+    mm->free_tree = remove_approx_value(mm->free_tree, &node, MAKE_KEY(npages, 0));
+    if (node == NULL) {
+        return -1;
+    }
+    free_page = node->page;
+    free_size = KEY_TO_VALUE(node->key);
+
+    alloc_pageno = free_page->pageno;
+    set_blocks_alloc(mm, alloc_pageno, npages);
+    if (npages != free_size) {
+        int free_pageno = alloc_pageno + npages;
+        set_blocks_free(mm, free_pageno, (free_size-npages));
+    }
+
+    VMEM_P_FREE(node);
+
+    ptr = mm->page_list[alloc_pageno].addr;
+    mm->alloc_page_count += npages;
+    mm->free_page_count  -= npages;
+
+
+    return ptr;
+}
+
+int
+jmem_free(
+	jpu_mm_t* mm,
+    unsigned long ptr,
+	unsigned long pid
+    )
+{
+    unsigned long addr;
+    avl_node_t* found;
+    page_t* page;
+    int pageno, prev_free_pageno, next_free_pageno;
+    int prev_size, next_size;
+    int merge_page_no, merge_page_size, free_page_size;
+	
+
+	if (mm == NULL) {
+		printk(KERN_INFO "vmem_free: invalid handle\n");
+		return -1;
+	}
+
+    addr = ptr;
+
+    mm->alloc_tree = avltree_remove(mm->alloc_tree, &found, MAKE_KEY(addr, 0));
+    if (found == NULL) {
+        printk(KERN_INFO "vmem_free: 0x%08x not found\n", (int)addr);
+        VMEM_ASSERT(0);
+        return -1;
+    }
+
+    /* find previous free block */
+    page = found->page;
+    pageno = page->pageno;
+    free_page_size = page->alloc_pages;
+    prev_free_pageno = pageno-1;
+    prev_size = -1;
+    if (prev_free_pageno >= 0) {
+        if (mm->page_list[prev_free_pageno].used == 0) {
+            prev_free_pageno = mm->page_list[prev_free_pageno].first_pageno;
+            prev_size = mm->page_list[prev_free_pageno].alloc_pages;
+        }
+    }
+
+    /* find next free block */
+    next_free_pageno = pageno + page->alloc_pages;
+    next_free_pageno = (next_free_pageno == mm->num_pages) ? -1 : next_free_pageno;
+    next_size = -1;
+    if (next_free_pageno >= 0) {
+        if (mm->page_list[next_free_pageno].used == 0) {
+            next_size = mm->page_list[next_free_pageno].alloc_pages;
+        }
+    }
+    VMEM_P_FREE(found);
+
+    /* merge */
+    merge_page_no = page->pageno;
+    merge_page_size = page->alloc_pages;
+    if (prev_size >= 0) {
+        mm->free_tree = avltree_remove(mm->free_tree, &found, MAKE_KEY(prev_size, prev_free_pageno));
+        if (found == NULL) {
+            VMEM_ASSERT(0);
+            return -1;
+        }
+        merge_page_no = found->page->pageno;
+        merge_page_size += found->page->alloc_pages;
+        VMEM_P_FREE(found);
+    }
+    if (next_size >= 0) {
+        mm->free_tree = avltree_remove(mm->free_tree, &found, MAKE_KEY(next_size, next_free_pageno));
+        if (found == NULL) {
+            VMEM_ASSERT(0);
+            return -1;
+        }
+        merge_page_size += found->page->alloc_pages;
+        VMEM_P_FREE(found);
+    }
+
+    page->alloc_pages  = 0;
+    page->first_pageno = -1;
+
+    set_blocks_free(mm, merge_page_no, merge_page_size);
+
+    mm->alloc_page_count -= free_page_size;
+    mm->free_page_count  += free_page_size;
+
+    return 0;
+}
+
+
+
+#endif /* __CNM_JPU_MM_H__ */

+ 301 - 0
soft_3rdpart/codaj12/jdi/linux/driver/jpu-starfive.h

@@ -0,0 +1,301 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 StarFive Technology Co., Ltd.
+ */
+#ifndef __JPU_STARFIVE_H__
+#define __JPU_STARFIVE_H__
+
+#include <linux/io.h>
+#include <linux/clk.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/reset-controller.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/clk-provider.h>
+
+#define JPU_ID_NUM 5
+
+struct starfive_jpu_data {
+	struct device *dev;
+
+	struct clk *clk_jpu_id[JPU_ID_NUM];
+	struct reset_control *rst_jpu_id[JPU_ID_NUM];
+
+};
+
+static struct starfive_jpu_data *sf_jpu = NULL;
+
+const char jpu_data_id[JPU_ID_NUM][15] = {
+	"jpcgc300_main",
+	"vdecbrg_main",
+	"jpeg_axi",
+	"jpeg_cclk",
+	"jpeg_apb",
+};
+
+
+void starfive_jpu_rst_status(void)
+{
+	int i;
+	int rst_state;
+	for (i = 0; i < JPU_ID_NUM; i++) {		
+		rst_state = reset_control_status(sf_jpu->rst_jpu_id[i]);
+		dev_dbg(sf_jpu->dev, "status_rst%d:%d", i, rst_state);
+	}
+	
+	return;
+}
+
+void starfive_jpu_clk_status(void)
+{
+	int i;
+	int clk_state;
+	for (i = 0; i < JPU_ID_NUM; i++) {		
+		clk_state = __clk_is_enabled(sf_jpu->clk_jpu_id[i]);
+		dev_dbg(sf_jpu->dev, "status_clk%d:%d", i, clk_state);
+	}
+
+	return;
+}
+
+/*Do not assert the reset: jpeg_axi, jpcgc300_main, vdecbrg_main. */
+void starfive_jpu_rst_exit(void)
+{
+    int i;
+	int ret;
+	for (i = 3; i < JPU_ID_NUM; i++) {
+		ret = reset_control_assert(sf_jpu->rst_jpu_id[i]);
+		if (ret) {
+			dev_err(sf_jpu->dev, "JPU reset assert failed:\n");
+			dev_err(sf_jpu->dev, jpu_data_id[i]);
+		}
+	}
+	return;
+}
+
+/*Do not disable the clock: jpeg_axi, jpcgc300_main, vdecbrg_main. */
+void starfive_jpu_clk_exit(void)
+{
+	int i;
+	for (i = 2; i < JPU_ID_NUM; i++) {
+		clk_disable_unprepare(sf_jpu->clk_jpu_id[i]);
+	}
+	return;
+}
+
+static int starfive_jpu_clk_init(void)
+{
+	int ret = 0;
+	int i;
+	for (i = 0; i < JPU_ID_NUM; i++) {
+		ret = clk_prepare_enable(sf_jpu->clk_jpu_id[i]);
+		if (ret) {
+			dev_err(sf_jpu->dev, "JPU enable clock failed:\n");
+			dev_err(sf_jpu->dev, jpu_data_id[i]);
+			goto init_clk_failed;
+		}
+	}
+
+	return 0;
+
+init_clk_failed:
+	for(; i > 2 ; i--) {
+		clk_disable_unprepare(sf_jpu->clk_jpu_id[i-1]);
+	}
+
+	return ret;
+}
+
+static int starfive_jpu_get_clk(void)
+{
+	int ret = 0;
+	int i;
+	for ( i = 0; i < JPU_ID_NUM ; i++) {
+		sf_jpu->clk_jpu_id[i] = devm_clk_get(sf_jpu->dev, jpu_data_id[i]);
+		if (IS_ERR(sf_jpu->clk_jpu_id[i])) {
+			dev_err(sf_jpu->dev, "JPU get clock failed: \n");
+			dev_err(sf_jpu->dev,  jpu_data_id[i]);
+			ret = PTR_ERR(sf_jpu->clk_jpu_id[i]);
+			goto get_clk_failed;
+		}
+	}
+
+	return 0;
+
+get_clk_failed:
+	for( ; i > 0 ; i--) {
+		devm_clk_put(sf_jpu->dev, sf_jpu->clk_jpu_id[i-1]);
+	}
+
+	return ret;
+}
+
+static int starfive_jpu_reset_init(void)
+{
+	int ret = 0;
+	int i;
+	for (i = 2; i < JPU_ID_NUM ; i++) {
+		ret = reset_control_deassert(sf_jpu->rst_jpu_id[i]);
+    	if (ret) {
+			dev_err(sf_jpu->dev, "JPU reset deassert failed: \n");
+			dev_err(sf_jpu->dev, jpu_data_id[i]);
+       	 	goto init_reset_failed;
+		}
+	}
+
+	return 0;
+
+init_reset_failed:
+	for (; i > 3 ; i--) {
+		reset_control_assert(sf_jpu->rst_jpu_id[i-1]);
+	}
+
+	return ret;
+}
+
+/*Do not manipulate the reset: jpcgc300_main, vdecbrg_main. */
+static int starfive_jpu_get_resets(void)
+{
+	int ret = 0;
+	int i;
+	for (i = 2; i < JPU_ID_NUM ; i++) {
+		sf_jpu->rst_jpu_id[i] = devm_reset_control_get_exclusive(sf_jpu->dev, jpu_data_id[i]);
+		if (IS_ERR(sf_jpu->rst_jpu_id[i])) {
+			dev_err(sf_jpu->dev, "failed to get JPU reset: \n");
+			dev_err(sf_jpu->dev,  jpu_data_id[i]);
+			ret = PTR_ERR(sf_jpu->rst_jpu_id[i]);
+			goto get_resets_failed;
+		}
+	}
+
+	return 0;
+
+get_resets_failed:
+	for (; i > 0; i--) {
+		reset_control_put(sf_jpu->rst_jpu_id[i-1]);
+	}
+
+	return ret;
+}
+
+int starfive_jpu_data_init(struct device *dev)
+{
+	int ret = 0;
+
+	if (sf_jpu == NULL){
+		sf_jpu = devm_kzalloc(dev, sizeof(*sf_jpu), GFP_KERNEL);
+		if (!sf_jpu)
+			return -ENOMEM;
+		sf_jpu->dev = dev;
+
+		ret = starfive_jpu_get_clk();
+		if (ret) {
+			dev_err(sf_jpu->dev, "failed to get jpu clock\n");
+			return ret;
+		}
+
+		ret = starfive_jpu_get_resets();
+		if (ret) {
+			dev_err(sf_jpu->dev, "failed to get jpu resets\n");
+			return ret;
+		}		
+	}
+
+	return 0;
+}
+
+int starfive_jpu_clk_enable(struct device *dev)
+{
+    int ret = 0;
+
+	ret = starfive_jpu_data_init(dev);
+	if (ret)
+		return ret;
+
+	ret = starfive_jpu_clk_init();
+	if (ret) {
+		dev_err(sf_jpu->dev, "failed to enable jpu clock\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+int starfive_jpu_clk_disable(struct device *dev)
+{
+    int ret = 0;
+
+	ret = starfive_jpu_data_init(dev);
+	if (ret)
+		return ret;
+    
+	starfive_jpu_clk_exit();
+
+	return 0;	
+}
+
+int starfive_jpu_rst_deassert(struct device *dev)
+{
+    int ret = 0;
+
+	ret = starfive_jpu_data_init(dev);
+	if (ret)
+		return ret;
+
+	ret = starfive_jpu_reset_init();
+	if (ret) {
+		dev_err(sf_jpu->dev, "failed to deassert jpu resets\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+int starfive_jpu_rst_assert(struct device *dev)
+{
+    int ret = 0;
+
+	ret = starfive_jpu_data_init(dev);
+	if (ret)
+		return ret;
+    
+	starfive_jpu_rst_exit();
+
+	return 0; 	
+}
+
+
+int starfive_jpu_clk_rst_init(struct platform_device *pdev)
+{
+    int ret = 0;
+
+	ret = starfive_jpu_data_init(&pdev->dev);
+	if (ret)
+		return ret;
+ 
+	ret = starfive_jpu_clk_init();
+	if (ret) {
+		dev_err(sf_jpu->dev, "failed to enable jpu clock\n");
+		return ret;
+	}
+
+	starfive_jpu_rst_exit();
+	mdelay(1);
+	ret = starfive_jpu_reset_init();
+	if (ret) {
+		dev_err(sf_jpu->dev, "failed to set jpu reset\n");
+		goto init_failed;
+	}
+
+	dev_info(sf_jpu->dev,"success to init JPU clock & reset.");
+    return 0;
+
+init_failed:
+    starfive_jpu_clk_exit();
+    return ret;
+
+}
+
+#endif
+

+ 1217 - 0
soft_3rdpart/codaj12/jdi/linux/driver/jpu.c

@@ -0,0 +1,1217 @@
+//--=========================================================================--
+//  This file is linux device driver for JPU.
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2006 - 2016  CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================-
+
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/mm.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/wait.h>
+#include <linux/list.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+#include <linux/cdev.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include <linux/sched/signal.h>
+#include <linux/version.h>
+#include <soc/sifive/sifive_l2_cache.h>
+
+#include "../../../jpuapi/jpuconfig.h"
+#include "jpu.h"
+#include "jpu-starfive.h"
+
+#define starfive_flush_dcache(start, len) \
+	sifive_l2_flush64_range(start, len)
+
+//#define ENABLE_DEBUG_MSG
+#ifdef ENABLE_DEBUG_MSG
+#define DPRINTK(args...)            printk(KERN_INFO args);
+#else
+#define DPRINTK(args...)
+#endif
+
+/* definitions to be changed as customer  configuration */
+/* if you want to have clock gating scheme frame by frame */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0)
+#define JPU_SUPPORT_CLOCK_CONTROL
+#endif
+
+#define JPU_SUPPORT_ISR
+//#define JPU_IRQ_CONTROL
+/* if the platform driver knows the name of this driver */
+/* JPU_PLATFORM_DEVICE_NAME */
+#define JPU_SUPPORT_PLATFORM_DRIVER_REGISTER
+
+/* if this driver knows the dedicated video memory address */
+
+//#define JPU_SUPPORT_RESERVED_VIDEO_MEMORY        //if this driver knows the dedicated video memory address
+
+#define JPU_PLATFORM_DEVICE_NAME    "cnm_jpu"
+#define JPU_DEV_NAME                "jpu"
+
+#define JPU_REG_BASE_ADDR           0x11900000
+#define JPU_REG_SIZE                0x300
+
+#ifdef JPU_SUPPORT_ISR
+#define JPU_IRQ_NUM                 24
+/* if the driver want to disable and enable IRQ whenever interrupt asserted. */
+/*#define JPU_IRQ_CONTROL*/
+#endif
+
+
+#ifndef VM_RESERVED	/*for kernel up to 3.7.0 version*/
+#define VM_RESERVED   (VM_DONTEXPAND | VM_DONTDUMP)
+#endif
+
+struct device *jpu_dev;
+
+typedef struct jpu_drv_context_t {
+    struct fasync_struct *async_queue;
+    u32 open_count;                     /*!<< device reference count. Not instance count */
+    u32 interrupt_reason[MAX_NUM_INSTANCE];
+} jpu_drv_context_t;
+
+
+/* To track the allocated memory buffer */
+typedef struct jpudrv_buffer_pool_t {
+    struct list_head        list;
+    struct jpudrv_buffer_t  jb;
+    struct file*            filp;
+} jpudrv_buffer_pool_t;
+
+/* To track the instance index and buffer in instance pool */
+typedef struct jpudrv_instance_list_t {
+    struct list_head    list;
+    unsigned long       inst_idx;
+    struct file*        filp;
+} jpudrv_instance_list_t;
+
+typedef struct jpudrv_instance_pool_t {
+	unsigned char codecInstPool[MAX_NUM_INSTANCE][MAX_INST_HANDLE_SIZE];
+} jpudrv_instance_pool_t;
+
+#ifdef JPU_SUPPORT_RESERVED_VIDEO_MEMORY
+#include "jmm.h"
+static jpu_mm_t         s_jmem;
+static jpudrv_buffer_t  s_video_memory = {0};
+#endif /* JPU_SUPPORT_RESERVED_VIDEO_MEMORY */
+
+
+static int jpu_hw_reset(void);
+static void jpu_clk_disable(void);
+static int jpu_clk_enable(void);
+// end customer definition
+
+static jpudrv_buffer_t s_instance_pool = {0};
+static jpu_drv_context_t s_jpu_drv_context;
+static int s_jpu_major;
+static struct cdev s_jpu_cdev;
+static int s_jpu_open_ref_count;
+#ifdef JPU_SUPPORT_ISR
+static int s_jpu_irq = JPU_IRQ_NUM;
+#endif
+
+static jpudrv_buffer_t s_jpu_register = {0};
+
+static int s_interrupt_flag[MAX_NUM_INSTANCE];
+static wait_queue_head_t s_interrupt_wait_q[MAX_NUM_INSTANCE];
+
+
+static spinlock_t s_jpu_lock = __SPIN_LOCK_UNLOCKED(s_jpu_lock);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
+static DECLARE_MUTEX(s_jpu_sem);
+#else
+static DEFINE_SEMAPHORE(s_jpu_sem);
+#endif
+static struct list_head s_jbp_head = LIST_HEAD_INIT(s_jbp_head);
+static struct list_head s_inst_list_head = LIST_HEAD_INIT(s_inst_list_head);
+
+#ifdef CONFIG_PM
+/* implement to power management functions */
+#endif
+
+#define NPT_BASE                                0x0000
+#define NPT_REG_SIZE                            0x300
+#define MJPEG_PIC_STATUS_REG(_inst_no)          (NPT_BASE + (_inst_no*NPT_REG_SIZE) + 0x004)
+
+#define ReadJpuRegister(addr)           *(volatile unsigned int *)(s_jpu_register.virt_addr + addr)
+#define WriteJpuRegister(addr, val)     *(volatile unsigned int *)(s_jpu_register.virt_addr + addr) = (unsigned int)val
+#define WriteJpu(addr, val)             *(volatile unsigned int *)(addr) = (unsigned int)val;
+
+#define vic_readl(addr)             readl((void __iomem *)addr)
+#define vic_writel(val,addr)        writel(val,(void __iomem *)addr)
+
+#define rstgen_Software_RESET_BASE_REG_ADDR     0x11840000
+#define rstgen_Software_RESET_assert0_OFFSET    (0x0)
+#define rstgen_Software_RESET_status0_OFFSET    (0x10)
+#define NBIT_RSTN_JPEG_AXI                      18
+#define NBIT_RSTN_JPEG_CCLK                     19
+#define NBIT_RSTN_JPEG_APB                      20
+
+#define clk_BASE_REG_ADDR                       0x11800000
+#define clk_vdecbrg_main_ctrl_REG_OFFSET        (0xb0)
+#define clk_jpeg_axi_ctrl_REG_OFFSET            (0xc0)
+#define clk_jpeg_cclk_ctrl_REG_OFFSET           (0xc4)
+#define clk_jpeg_apb_ctrl_REG_OFFSET            (0xc8)
+#define clk_jpcgc300_main_ctrl_REG_OFFSET       (0xdc)
+
+
+static int jpu_alloc_dma_buffer(jpudrv_buffer_t *jb)
+{
+    if (!jb)
+        return -1;
+#ifdef JPU_SUPPORT_RESERVED_VIDEO_MEMORY
+    jb->phys_addr = (unsigned long long)jmem_alloc(&s_jmem, jb->size, 0);
+    if ((unsigned long)jb->phys_addr  == (unsigned long)-1) {
+        printk(KERN_ERR "[JPUDRV] Physical memory allocation error size=%d\n", jb->size);
+        return -1;
+    }
+
+    jb->base = (unsigned long)(s_video_memory.base + (jb->phys_addr - s_video_memory.phys_addr));
+#else
+    jb->base = (unsigned long)dma_alloc_coherent(jpu_dev, PAGE_ALIGN(jb->size), (dma_addr_t *) (&jb->phys_addr), GFP_DMA | GFP_KERNEL);
+    if ((void *)(jb->base) == NULL) {
+        printk(KERN_ERR "[JPUDRV] Physical memory allocation error size=%d\n", jb->size);
+        return -1;
+    }
+	starfive_flush_dcache(jb->phys_addr,PAGE_ALIGN(jb->size));
+#endif /* JPU_SUPPORT_RESERVED_VIDEO_MEMORY */
+    return 0;
+}
+
+static void jpu_free_dma_buffer(jpudrv_buffer_t *jb)
+{
+    if (!jb) {
+        return;
+    }
+
+    if (jb->base)
+#ifdef JPU_SUPPORT_RESERVED_VIDEO_MEMORY
+        jmem_free(&s_jmem, jb->phys_addr, 0);
+#else
+        dma_free_coherent(jpu_dev, PAGE_ALIGN(jb->size), (void *)jb->base, jb->phys_addr);
+#endif /* JPUR_SUPPORT_RESERVED_VIDEO_MEMORY */
+}
+
+static int jpu_free_instances(struct file *filp)
+{
+    jpudrv_instance_list_t *vil, *n;
+    jpudrv_instance_pool_t *vip;
+    void *vip_base;
+    int instance_pool_size_per_core;
+    void *jdi_mutexes_base;
+    const int PTHREAD_MUTEX_T_DESTROY_VALUE = 0xdead10cc;
+
+    DPRINTK("[JPUDRV] jpu_free_instances\n");
+
+    instance_pool_size_per_core = (s_instance_pool.size/MAX_NUM_JPU_CORE); /* s_instance_pool.size  assigned to the size of all core once call JDI_IOCTL_GET_INSTANCE_POOL by user. */
+
+    list_for_each_entry_safe(vil, n, &s_inst_list_head, list)
+    {
+        if (vil->filp == filp) {
+            vip_base = (void *)(s_instance_pool.base + instance_pool_size_per_core);
+            DPRINTK("[JPUDRV] jpu_free_instances detect instance crash instIdx=%d, vip_base=%p, instance_pool_size_per_core=%d\n", (int)vil->inst_idx, vip_base, (int)instance_pool_size_per_core);
+            vip = (jpudrv_instance_pool_t *)vip_base;
+            if (vip) {
+                memset(&vip->codecInstPool[vil->inst_idx], 0x00, 4);    /* only first 4 byte is key point(inUse of CodecInst in jpuapi) to free the corresponding instance. */
+#define PTHREAD_MUTEX_T_HANDLE_SIZE 4
+                jdi_mutexes_base = (vip_base + (instance_pool_size_per_core - PTHREAD_MUTEX_T_HANDLE_SIZE*4));
+                DPRINTK("[JPUDRV] jpu_free_instances : force to destroy jdi_mutexes_base=%p in userspace \n", jdi_mutexes_base);
+                if (jdi_mutexes_base) {
+                    int i;
+                    for (i = 0; i < 4; i++) {
+                        memcpy(jdi_mutexes_base, &PTHREAD_MUTEX_T_DESTROY_VALUE, PTHREAD_MUTEX_T_HANDLE_SIZE);
+                        jdi_mutexes_base += PTHREAD_MUTEX_T_HANDLE_SIZE;
+                    }
+                }
+            }
+            s_jpu_open_ref_count--;
+            list_del(&vil->list);
+            kfree(vil);
+        }
+    }
+    return 1;
+}
+
+static int jpu_free_buffers(struct file *filp)
+{
+    jpudrv_buffer_pool_t *pool, *n;
+    jpudrv_buffer_t jb;
+
+    DPRINTK("[JPUDRV] jpu_free_buffers\n");
+
+    list_for_each_entry_safe(pool, n, &s_jbp_head, list)
+    {
+        if (pool->filp == filp) {
+            jb = pool->jb;
+            if (jb.base) {
+                jpu_free_dma_buffer(&jb);
+                list_del(&pool->list);
+                kfree(pool);
+            }
+        }
+    }
+
+    return 0;
+}
+
+
+static irqreturn_t jpu_irq_handler(int irq, void *dev_id)
+{
+    jpu_drv_context_t*  dev = (jpu_drv_context_t *)dev_id;
+    int i;
+    u32 flag;
+
+    DPRINTK("[JPUDRV][+]%s\n", __func__);
+
+#ifdef JPU_IRQ_CONTROL
+    disable_irq_nosync(s_jpu_irq);
+#endif
+
+    for (i=0; i<MAX_NUM_INSTANCE; i++) {
+        flag = ReadJpuRegister(MJPEG_PIC_STATUS_REG(i));
+        if (flag != 0) {
+            break;
+        }
+    }
+
+    dev->interrupt_reason[i] = flag;
+    s_interrupt_flag[i] = 1;
+    DPRINTK("[JPUDRV][%d] INTERRUPT FLAG: %08x, %08x\n", i, dev->interrupt_reason[i], MJPEG_PIC_STATUS_REG(i));
+
+    if (dev->async_queue)
+        kill_fasync(&dev->async_queue, SIGIO, POLL_IN);    // notify the interrupt to userspace
+
+#ifndef JPU_IRQ_CONTROL
+    WriteJpuRegister(MJPEG_PIC_STATUS_REG(i),flag);  	//clear interrut
+#endif
+
+    wake_up_interruptible(&s_interrupt_wait_q[i]);
+
+    DPRINTK("[JPUDRV][-]%s\n", __func__);
+
+    return IRQ_HANDLED;
+}
+
+static int jpu_open(struct inode *inode, struct file *filp)
+{
+    DPRINTK("[JPUDRV][+] %s\n", __func__);
+
+    spin_lock(&s_jpu_lock);
+
+    s_jpu_drv_context.open_count++;
+
+    filp->private_data = (void *)(&s_jpu_drv_context);
+    spin_unlock(&s_jpu_lock);
+
+    DPRINTK("[JPUDRV][-] %s\n", __func__);
+
+    return 0;
+}
+
+static long jpu_ioctl(struct file *filp, u_int cmd, u_long arg)
+{
+    int ret = 0;
+
+    switch (cmd)
+    {
+    case JDI_IOCTL_ALLOCATE_PHYSICAL_MEMORY:
+        {
+            jpudrv_buffer_pool_t *jbp;
+
+            DPRINTK("[JPUDRV][+]JDI_IOCTL_ALLOCATE_PHYSICAL_MEMORY\n");
+            if ((ret = down_interruptible(&s_jpu_sem)) == 0) {
+                jbp = kzalloc(sizeof(jpudrv_buffer_pool_t), GFP_KERNEL);
+                if (!jbp) {
+                    up(&s_jpu_sem);
+                    return -ENOMEM;
+                }
+
+                ret = copy_from_user(&(jbp->jb), (jpudrv_buffer_t *)arg, sizeof(jpudrv_buffer_t));
+                if (ret)
+                {
+                    kfree(jbp);
+                    up(&s_jpu_sem);
+                    return -EFAULT;
+                }
+
+                ret = jpu_alloc_dma_buffer(&(jbp->jb));
+                if (ret == -1)
+                {
+                    ret = -ENOMEM;
+                    kfree(jbp);
+                    up(&s_jpu_sem);
+                    break;
+                }
+                ret = copy_to_user((void __user *)arg, &(jbp->jb), sizeof(jpudrv_buffer_t));
+                if (ret)
+                {
+                    kfree(jbp);
+                    ret = -EFAULT;
+                    up(&s_jpu_sem);
+                    break;
+                }
+                
+                jbp->filp = filp;
+                spin_lock(&s_jpu_lock);
+                list_add(&jbp->list, &s_jbp_head);
+                spin_unlock(&s_jpu_lock);
+
+                up(&s_jpu_sem);
+            }
+            DPRINTK("[JPUDRV][-]JDI_IOCTL_ALLOCATE_PHYSICAL_MEMORY\n");
+        }
+        break;
+     case JDI_IOCTL_GET_PHYSICAL_MEMORY:
+        {
+            jpudrv_buffer_pool_t *jbp;
+
+            DPRINTK("[JPUDRV][+]JDI_IOCTL_GET_PHYSICAL_MEMORY\n");
+            if ((ret = down_interruptible(&s_jpu_sem)) == 0) {
+                jbp = kzalloc(sizeof(jpudrv_buffer_pool_t), GFP_KERNEL);
+                if (!jbp) {
+                    up(&s_jpu_sem);
+                    return -ENOMEM;
+                }
+
+                ret = copy_from_user(&(jbp->jb), (jpudrv_buffer_t *)arg, sizeof(jpudrv_buffer_t));
+                if (ret)
+                {
+                    kfree(jbp);
+                    up(&s_jpu_sem);
+                    return -EFAULT;
+                }
+
+                void *user_address = (void *)jbp->jb.virt_addr;
+                struct task_struct *my_struct = get_current();
+                struct mm_struct *mm = my_struct->mm;
+                unsigned long address = (unsigned long)user_address;
+                pgd_t *pgd = pgd_offset(mm, address);
+
+                if (!pgd_none(*pgd) && !pgd_bad(*pgd)) {
+                    p4d_t *p4d = p4d_offset(pgd, address);
+                    pud_t *pud = pud_offset(p4d, address);
+                    if (!pud_none(*pud) && !pud_bad(*pud)) {
+                        pmd_t *pmd = pmd_offset(pud, address);
+                        if (!pmd_none(*pmd) && !pmd_bad(*pmd)) {
+                            pte_t *pte = pte_offset_map(pmd, address);
+                            if (!pte_none(*pte)) {
+                                struct page *pg = pte_page(*pte);
+                                unsigned long phys = page_to_phys(pg);
+                                unsigned long virt = (unsigned long)phys_to_virt(phys);
+                                printk("phy address = %lx, virt = %lx\r\n", phys, virt);
+                                jbp->jb.phys_addr = phys;
+                                jbp->jb.base = virt;
+                            }
+                            pte_unmap(pte);
+                        }
+                    }
+                }
+                ret = copy_to_user((void __user *)arg, &(jbp->jb), sizeof(jpudrv_buffer_t));
+                if (ret)
+                {
+                    kfree(jbp);
+                    ret = -EFAULT;
+                    up(&s_jpu_sem);
+                    break;
+                }
+
+                jbp->filp = filp;
+                spin_lock(&s_jpu_lock);
+                list_add(&jbp->list, &s_jbp_head);
+                spin_unlock(&s_jpu_lock);
+
+                up(&s_jpu_sem);
+            }
+            DPRINTK("[JPUDRV][-]JDI_IOCTL_GET_PHYSICAL_MEMORY\n");
+        }
+        break;
+    case JDI_IOCTL_FREE_PHYSICALMEMORY:
+        {
+            jpudrv_buffer_pool_t *jbp, *n;
+            jpudrv_buffer_t jb;
+
+            DPRINTK("[JPUDRV][+]VDI_IOCTL_FREE_PHYSICALMEMORY\n");
+            if ((ret = down_interruptible(&s_jpu_sem)) == 0) {
+                ret = copy_from_user(&jb, (jpudrv_buffer_t *)arg, sizeof(jpudrv_buffer_t));
+                if (ret) {
+                    up(&s_jpu_sem);
+                    return -EACCES;
+                }
+
+                if (jb.base)
+                    jpu_free_dma_buffer(&jb);
+
+                spin_lock(&s_jpu_lock);
+                list_for_each_entry_safe(jbp, n, &s_jbp_head, list) {
+                    if (jbp->jb.base == jb.base) {
+                        list_del(&jbp->list);
+                        kfree(jbp);
+                        break;
+                    }
+                }
+                spin_unlock(&s_jpu_lock);
+
+                up(&s_jpu_sem);
+            }
+            DPRINTK("[JPUDRV][-]VDI_IOCTL_FREE_PHYSICALMEMORY\n");
+        }
+        break;
+    case JDI_IOCTL_GET_RESERVED_VIDEO_MEMORY_INFO:
+        {
+#ifdef JPU_SUPPORT_RESERVED_VIDEO_MEMORY
+            if (s_video_memory.base != 0) {
+                ret = copy_to_user((void __user *)arg, &s_video_memory, sizeof(jpudrv_buffer_t));
+                if (ret != 0)
+                    ret = -EFAULT;
+            } else {
+                ret = -EFAULT;
+            }
+#endif /* JPU_SUPPORT_RESERVED_VIDEO_MEMORY */
+        }
+        break;
+
+
+    case JDI_IOCTL_WAIT_INTERRUPT:
+        {
+            jpudrv_intr_info_t info;
+            struct jpu_drv_context_t *dev = (struct jpu_drv_context_t *)filp->private_data;
+            u32 instance_no;
+
+            DPRINTK("[JPUDRV][+]JDI_IOCTL_WAIT_INTERRUPT\n");
+            ret = copy_from_user(&info, (jpudrv_intr_info_t *)arg, sizeof(jpudrv_intr_info_t));
+            if (ret != 0)
+                return -EFAULT;
+
+            instance_no = info.inst_idx;
+            DPRINTK("[JPUDRV] INSTANCE NO: %d\n", instance_no);
+            ret = wait_event_interruptible_timeout(s_interrupt_wait_q[instance_no], s_interrupt_flag[instance_no] != 0, msecs_to_jiffies(info.timeout));
+            if (!ret) {
+                DPRINTK("[JPUDRV] INSTANCE NO: %d ETIME\n", instance_no);
+                ret = -ETIME;
+                break;
+            }
+
+            if (signal_pending(current)) {
+                ret = -ERESTARTSYS;
+                DPRINTK("[JPUDRV] INSTANCE NO: %d ERESTARTSYS\n", instance_no);
+                break;
+            }
+
+            DPRINTK("[JPUDRV] INST(%d) s_interrupt_flag(%d), reason(0x%08x)\n", instance_no, s_interrupt_flag[instance_no], dev->interrupt_reason[instance_no]);
+
+            info.intr_reason = dev->interrupt_reason[instance_no];
+            s_interrupt_flag[instance_no] = 0;
+            dev->interrupt_reason[instance_no] = 0;
+            ret = copy_to_user((void __user *)arg, &info, sizeof(jpudrv_intr_info_t));
+#ifdef JPU_IRQ_CONTROL
+            enable_irq(s_jpu_irq);
+#endif
+            DPRINTK("[VPUDRV][-]VDI_IOCTL_WAIT_INTERRUPT\n");
+            if (ret != 0)
+                return -EFAULT;
+        }
+        break;
+    case JDI_IOCTL_SET_CLOCK_GATE:
+        {
+            /*
+            u32 clkgate;
+
+            if (get_user(clkgate, (u32 __user *) arg))
+                return -EFAULT;
+
+//#ifdef JPU_SUPPORT_CLOCK_CONTROL
+            if (clkgate)
+                ret = starfive_jpu_clk_enable(jpu_dev);
+                //jpu_clk_enable();               
+            else
+                ret = starfive_jpu_clk_disable(jpu_dev);
+                //jpu_clk_disable();
+//#endif 
+*/
+        }
+        break;
+    case JDI_IOCTL_GET_INSTANCE_POOL:
+        DPRINTK("[JPUDRV][+]JDI_IOCTL_GET_INSTANCE_POOL\n");
+
+        if ((ret = down_interruptible(&s_jpu_sem)) == 0) {
+            if (s_instance_pool.base != 0) {
+                ret = copy_to_user((void __user *)arg, &s_instance_pool, sizeof(jpudrv_buffer_t));
+            } else {
+                ret = copy_from_user(&s_instance_pool, (jpudrv_buffer_t *)arg, sizeof(jpudrv_buffer_t));
+                if (ret == 0) {
+                    s_instance_pool.size      = PAGE_ALIGN(s_instance_pool.size);
+                    s_instance_pool.base      = (unsigned long)vmalloc(s_instance_pool.size);
+                    s_instance_pool.phys_addr = s_instance_pool.base;
+
+                    if (s_instance_pool.base != 0) {
+                        memset((void *)s_instance_pool.base, 0x0, s_instance_pool.size); /*clearing memory*/
+                        ret = copy_to_user((void __user *)arg, &s_instance_pool, sizeof(jpudrv_buffer_t));
+                        if (ret == 0) {
+                            /* success to get memory for instance pool */
+                            up(&s_jpu_sem);
+                            break;
+                        }
+                    }
+                    ret = -EFAULT;
+                }
+            }
+            up(&s_jpu_sem);
+        }
+
+        DPRINTK("[JPUDRV][-]JDI_IOCTL_GET_INSTANCE_POOL: %s base: %lx, size: %d\n",
+                (ret==0 ? "OK" : "NG"), s_instance_pool.base, s_instance_pool.size);
+        break;
+    case JDI_IOCTL_OPEN_INSTANCE:
+        {
+            jpudrv_inst_info_t inst_info;
+
+            if (copy_from_user(&inst_info, (jpudrv_inst_info_t *)arg, sizeof(jpudrv_inst_info_t)))
+                return -EFAULT;
+
+            spin_lock(&s_jpu_lock);
+            s_jpu_open_ref_count++; /* flag just for that jpu is in opened or closed */
+            inst_info.inst_open_count = s_jpu_open_ref_count;
+            spin_unlock(&s_jpu_lock);
+
+            if (copy_to_user((void __user *)arg, &inst_info, sizeof(jpudrv_inst_info_t))) {
+                return -EFAULT;
+            }
+
+            DPRINTK("[JPUDRV] JDI_IOCTL_OPEN_INSTANCE inst_idx=%d, s_jpu_open_ref_count=%d, inst_open_count=%d\n",
+                    (int)inst_info.inst_idx, s_jpu_open_ref_count, inst_info.inst_open_count);
+        }
+        break;
+    case JDI_IOCTL_CLOSE_INSTANCE:
+        {
+            jpudrv_inst_info_t inst_info;
+
+            DPRINTK("[JPUDRV][+]JDI_IOCTL_CLOSE_INSTANCE\n");
+            if (copy_from_user(&inst_info, (jpudrv_inst_info_t *)arg, sizeof(jpudrv_inst_info_t)))
+                return -EFAULT;
+
+            spin_lock(&s_jpu_lock);
+            s_jpu_open_ref_count--; /* flag just for that jpu is in opened or closed */
+            inst_info.inst_open_count = s_jpu_open_ref_count;
+            spin_unlock(&s_jpu_lock);
+
+            if (copy_to_user((void __user *)arg, &inst_info, sizeof(jpudrv_inst_info_t)))
+                return -EFAULT;
+
+            DPRINTK("[JPUDRV] JDI_IOCTL_CLOSE_INSTANCE inst_idx=%d, s_jpu_open_ref_count=%d, inst_open_count=%d\n",
+                    (int)inst_info.inst_idx, s_jpu_open_ref_count, inst_info.inst_open_count);
+        }
+        break;
+    case JDI_IOCTL_GET_INSTANCE_NUM:
+        {
+            jpudrv_inst_info_t inst_info;
+
+            DPRINTK("[JPUDRV][+]JDI_IOCTL_GET_INSTANCE_NUM\n");
+
+            ret = copy_from_user(&inst_info, (jpudrv_inst_info_t *)arg, sizeof(jpudrv_inst_info_t));
+            if (ret != 0)
+                break;
+
+            spin_lock(&s_jpu_lock);
+            inst_info.inst_open_count = s_jpu_open_ref_count;
+            spin_unlock(&s_jpu_lock);
+
+            ret = copy_to_user((void __user *)arg, &inst_info, sizeof(jpudrv_inst_info_t));
+
+            DPRINTK("[JPUDRV] JDI_IOCTL_GET_INSTANCE_NUM inst_idx=%d, open_count=%d\n", (int)inst_info.inst_idx, inst_info.inst_open_count);
+        }
+        break;
+    case JDI_IOCTL_RESET:
+        //jpu_hw_reset();
+        //starfive_jpu_rst_deassert(jpu_dev);
+        break;
+
+    case JDI_IOCTL_GET_REGISTER_INFO:
+        DPRINTK("[JPUDRV][+]JDI_IOCTL_GET_REGISTER_INFO\n");
+        ret = copy_to_user((void __user *)arg, &s_jpu_register, sizeof(jpudrv_buffer_t));
+        if (ret != 0)
+            ret = -EFAULT;
+        DPRINTK("[JPUDRV][-]JDI_IOCTL_GET_REGISTER_INFO s_jpu_register.phys_addr=0x%lx, s_jpu_register.virt_addr=0x%lx, s_jpu_register.size=%d\n",
+                s_jpu_register.phys_addr , s_jpu_register.virt_addr, s_jpu_register.size);
+        break;
+    case JDI_IOCTL_FLUSH_DCACHE:
+        {
+            jpudrv_flush_cache_t cache_info;
+
+            //DPRINTK("[JPUDRV][+]JDI_IOCTL_FLUSH_DCACHE\n");
+            ret = copy_from_user(&cache_info, (jpudrv_flush_cache_t *)arg, sizeof(jpudrv_flush_cache_t));
+            if (ret != 0)
+                ret = -EFAULT;
+
+            if(cache_info.flag)
+                starfive_flush_dcache(cache_info.start,cache_info.size);
+
+            //DPRINTK("[JPUDRV][-]JDI_IOCTL_FLUSH_DCACHE\n");
+            break;
+        }
+    default:
+        {
+            printk(KERN_ERR "No such IOCTL, cmd is %d\n", cmd);
+        }
+        break;
+    }
+    return ret;
+}
+
+static ssize_t jpu_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
+{
+
+    return -1;
+}
+
+static ssize_t jpu_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
+{
+
+    /* DPRINTK("[JPUDRV] jpu_write len=%d\n", (int)len); */
+    if (!buf) {
+        printk(KERN_ERR "[JPUDRV] jpu_write buf = NULL error \n");
+        return -EFAULT;
+    }
+
+    return -1;
+}
+
+static int jpu_release(struct inode *inode, struct file *filp)
+{
+    int ret = 0;
+    u32 open_count;
+
+    DPRINTK("[JPUDRV][+] jpu_release\n");
+
+    if ((ret = down_interruptible(&s_jpu_sem)) == 0) {
+
+        /* found and free the not handled buffer by user applications */
+        jpu_free_buffers(filp);
+
+        /* found and free the not closed instance by user applications */
+        jpu_free_instances(filp);
+        DPRINTK("[JPUDRV] open_count: %d\n", s_jpu_drv_context.open_count);
+        spin_lock(&s_jpu_lock);
+        s_jpu_drv_context.open_count--;
+        open_count = s_jpu_drv_context.open_count;
+        spin_unlock(&s_jpu_lock);
+        if (open_count == 0) {
+            if (s_instance_pool.base) {
+                DPRINTK("[JPUDRV] free instance pool\n");
+                vfree((const void *)s_instance_pool.base);
+                s_instance_pool.base = 0;
+            }
+
+
+        }
+    }
+    up(&s_jpu_sem);
+
+    DPRINTK("[JPUDRV][-] jpu_release\n");
+
+    return 0;
+}
+
+
+static int jpu_fasync(int fd, struct file *filp, int mode)
+{
+    struct jpu_drv_context_t *dev = (struct jpu_drv_context_t *)filp->private_data;
+    return fasync_helper(fd, filp, mode, &dev->async_queue);
+}
+
+
+
+
+static int jpu_map_to_register(struct file *fp, struct vm_area_struct *vm)
+{
+    unsigned long pfn;
+
+    vm->vm_flags |= VM_IO | VM_RESERVED;
+    vm->vm_page_prot = pgprot_noncached(vm->vm_page_prot);
+    pfn = s_jpu_register.phys_addr >> PAGE_SHIFT;
+
+    return remap_pfn_range(vm, vm->vm_start, pfn, vm->vm_end-vm->vm_start, vm->vm_page_prot) ? -EAGAIN : 0;
+}
+
+static int jpu_map_to_physical_memory(struct file *fp, struct vm_area_struct *vm)
+{
+    vm->vm_flags |= VM_IO | VM_RESERVED;
+    vm->vm_page_prot = pgprot_noncached(vm->vm_page_prot);
+
+    return remap_pfn_range(vm, vm->vm_start, vm->vm_pgoff, vm->vm_end-vm->vm_start, vm->vm_page_prot) ? -EAGAIN : 0;
+}
+
+static int jpu_map_to_instance_pool_memory(struct file *fp, struct vm_area_struct *vm)
+{
+    int ret;
+    long length = vm->vm_end - vm->vm_start;
+    unsigned long start = vm->vm_start;
+    char *vmalloc_area_ptr = (char *)s_instance_pool.base;
+    unsigned long pfn;
+
+    vm->vm_flags |= VM_RESERVED;
+
+    /* loop over all pages, map it page individually */
+    while (length > 0) {
+        pfn = vmalloc_to_pfn(vmalloc_area_ptr);
+        if ((ret = remap_pfn_range(vm, start, pfn, PAGE_SIZE, PAGE_SHARED)) < 0) {
+            return ret;
+        }
+        start += PAGE_SIZE;
+        vmalloc_area_ptr += PAGE_SIZE;
+        length -= PAGE_SIZE;
+    }
+
+
+    return 0;
+}
+
+/*!
+* @brief memory map interface for jpu file operation
+* @return  0 on success or negative error code on error
+*/
+static int jpu_mmap(struct file *fp, struct vm_area_struct *vm)
+{
+    if (vm->vm_pgoff == 0)
+        return jpu_map_to_instance_pool_memory(fp, vm);
+
+    if (vm->vm_pgoff == (s_jpu_register.phys_addr>>PAGE_SHIFT))
+        return jpu_map_to_register(fp, vm);
+
+    return jpu_map_to_physical_memory(fp, vm);
+}
+
+struct file_operations jpu_fops = {
+    .owner = THIS_MODULE,
+    .open = jpu_open,
+    .read = jpu_read,
+    .write = jpu_write,
+    .unlocked_ioctl = jpu_ioctl,
+    .release = jpu_release,
+    .fasync = jpu_fasync,
+    .mmap = jpu_mmap,
+};
+
+
+
+static int jpu_probe(struct platform_device *pdev)
+{
+    int err = 0;
+    struct resource *res = NULL;
+#ifdef JPU_SUPPORT_RESERVED_VIDEO_MEMORY
+	struct resource res_cma;
+	struct device_node *node;
+#endif
+
+    DPRINTK("[JPUDRV] jpu_probe\n");
+    if (pdev) {
+        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+    }
+
+    if (res) {/* if platform driver is implemented */
+        s_jpu_register.phys_addr = res->start;
+        s_jpu_register.virt_addr = (unsigned long)ioremap(res->start, res->end - res->start);
+        s_jpu_register.size      = res->end - res->start;
+        DPRINTK("[JPUDRV] : jpu base address get from platform driver physical base addr==0x%lx, virtual base=0x%lx\n", s_jpu_register.phys_addr , s_jpu_register.virt_addr);
+    } else {
+        s_jpu_register.phys_addr = JPU_REG_BASE_ADDR;
+        s_jpu_register.virt_addr = (unsigned long)ioremap(s_jpu_register.phys_addr, JPU_REG_SIZE);
+        s_jpu_register.size      = JPU_REG_SIZE;
+        DPRINTK("[JPUDRV] : jpu base address get from defined value physical base addr==0x%lx, virtual base=0x%lx\n", s_jpu_register.phys_addr, s_jpu_register.virt_addr);
+    }
+    if (pdev) {
+        jpu_dev = &pdev->dev;
+		//jpu_dev->dma_ops = NULL;
+        dev_info(jpu_dev,"init device.\n");
+    }
+    /* get the major number of the character device */
+    if ((alloc_chrdev_region(&s_jpu_major, 0, 1, JPU_DEV_NAME)) < 0) {
+        err = -EBUSY;
+        printk(KERN_ERR "could not allocate major number\n");
+        goto ERROR_PROVE_DEVICE;
+    }
+
+    /* initialize the device structure and register the device with the kernel */
+    cdev_init(&s_jpu_cdev, &jpu_fops);
+    if ((cdev_add(&s_jpu_cdev, s_jpu_major, 1)) < 0) {
+        err = -EBUSY;
+        printk(KERN_ERR "could not allocate chrdev\n");
+
+        goto ERROR_PROVE_DEVICE;
+    }
+    
+#ifdef JPU_SUPPORT_CLOCK_CONTROL
+    err = starfive_jpu_clk_rst_init(pdev);
+    if (err){
+        goto ERROR_PROVE_DEVICE; 
+    }
+#else
+    jpu_clk_enable();
+    jpu_hw_reset();
+#endif
+
+
+#ifdef JPU_SUPPORT_ISR
+#ifdef JPU_SUPPORT_PLATFORM_DRIVER_REGISTER
+    if(pdev)
+        res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+    if (res) {/* if platform driver is implemented */
+        s_jpu_irq = res->start;
+        DPRINTK("[JPUDRV] : jpu irq number get from platform driver irq=0x%x\n", s_jpu_irq );
+    } else {
+        DPRINTK("[JPUDRV] : jpu irq number get from defined value irq=0x%x\n", s_jpu_irq );
+    }
+#else
+    DPRINTK("[JPUDRV] : jpu irq number get from defined value irq=0x%x\n", s_jpu_irq);
+#endif
+
+
+    err = request_irq(s_jpu_irq, jpu_irq_handler, 0, "JPU_CODEC_IRQ", (void *)(&s_jpu_drv_context));
+    if (err) {
+        printk(KERN_ERR "[JPUDRV] :  fail to register interrupt handler\n");
+        goto ERROR_PROVE_DEVICE;
+    }
+#endif
+
+#ifdef JPU_SUPPORT_RESERVED_VIDEO_MEMORY
+	node = of_parse_phandle(jpu_dev->of_node, "memory-region", 0);
+	if(node){
+		dev_info(jpu_dev, "Get mem form memory-region\n");
+		of_address_to_resource(node, 0, &res_cma);
+		s_video_memory.size = resource_size(&res_cma);
+    	s_video_memory.phys_addr = res_cma.start;
+	}else{
+        dev_info(jpu_dev, "Get mem form reserved memory failed.please check the dts file.\n");
+		return 0;
+    }
+    s_video_memory.base = (unsigned long)ioremap(MEM2SYS(s_video_memory.phys_addr), PAGE_ALIGN(s_video_memory.size));
+	if (!s_video_memory.base) {
+        printk(KERN_ERR "[JPUDRV] :  fail to remap video memory physical phys_addr=0x%lx, base=0x%lx, size=%d\n", MEM2SYS(s_video_memory.phys_addr), s_video_memory.base, s_video_memory.size);
+        goto ERROR_PROVE_DEVICE;
+    }
+
+    if (jmem_init(&s_jmem, s_video_memory.phys_addr, s_video_memory.size) < 0) {
+        printk(KERN_ERR "[JPUDRV] :  fail to init vmem system\n");
+        goto ERROR_PROVE_DEVICE;
+    }
+    DPRINTK("[JPUDRV] success to probe jpu device with reserved video memory phys_addr=0x%lx, base=0x%lx\n", s_video_memory.phys_addr, s_video_memory.base);
+#else
+    DPRINTK("[JPUDRV] success to probe jpu device with non reserved video memory\n");
+#endif
+
+    return 0;
+
+
+ERROR_PROVE_DEVICE:
+
+    if (s_jpu_major)
+        unregister_chrdev_region(s_jpu_major, 1);
+
+    if (s_jpu_register.virt_addr)
+        iounmap((void *)s_jpu_register.virt_addr);
+
+    return err;
+}
+
+static int jpu_remove(struct platform_device *pdev)
+{
+    DPRINTK("[JPUDRV] jpu_remove\n");
+#ifdef JPU_SUPPORT_PLATFORM_DRIVER_REGISTER
+
+    if (s_instance_pool.base) {
+        vfree((const void *)s_instance_pool.base);
+        s_instance_pool.base = 0;
+    }
+#ifdef JPU_SUPPORT_RESERVED_VIDEO_MEMORY
+    if (s_video_memory.base) {
+        iounmap((void *)s_video_memory.base);
+        s_video_memory.base = 0;
+        jmem_exit(&s_jmem);
+    }
+#endif
+
+    if (s_jpu_major > 0) {
+        cdev_del(&s_jpu_cdev);
+        unregister_chrdev_region(s_jpu_major, 1);
+        s_jpu_major = 0;
+    }
+
+#ifdef JPU_SUPPORT_ISR
+    if (s_jpu_irq)
+        free_irq(s_jpu_irq, &s_jpu_drv_context);
+#endif
+
+    if (s_jpu_register.virt_addr)
+        iounmap((void*)s_jpu_register.virt_addr);
+
+#endif /* JPU_SUPPORT_PLATFORM_DRIVER_REGISTER */
+
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int jpu_suspend(struct platform_device *pdev, pm_message_t state)
+{
+#ifdef JPU_SUPPORT_CLOCK_CONTROL
+    starfive_jpu_clk_disable(jpu_dev)
+#else
+    jpu_clk_disable();
+#endif
+    
+    return 0;
+
+}
+static int jpu_resume(struct platform_device *pdev)
+{
+#ifdef JPU_SUPPORT_CLOCK_CONTROL
+    starfive_jpu_clk_enable(jpu_dev)
+#else
+    jpu_clk_enable();
+#endif
+
+    return 0;
+}
+#else
+#define    jpu_suspend    NULL
+#define    jpu_resume    NULL
+#endif /* !CONFIG_PM */
+
+#ifdef JPU_SUPPORT_PLATFORM_DRIVER_REGISTER
+static const struct of_device_id jpu_of_id_table[] = {
+	{ .compatible = "cm,codaj12-jpu-1" },
+	{}
+};
+
+static struct platform_driver jpu_driver = {
+    .driver = {
+        .name = JPU_PLATFORM_DEVICE_NAME,
+        .of_match_table = of_match_ptr(jpu_of_id_table),
+    },
+    .probe      = jpu_probe,
+    .remove     = jpu_remove,
+    .suspend    = jpu_suspend,
+    .resume     = jpu_resume,
+};
+#endif /* JPU_SUPPORT_PLATFORM_DRIVER_REGISTER */
+
+static int __init jpu_init(void)
+{
+    int res = 0;
+    u32 i;
+
+    DPRINTK("[JPUDRV] begin jpu_init\n");
+    for (i=0; i<MAX_NUM_INSTANCE; i++) {
+        init_waitqueue_head(&s_interrupt_wait_q[i]);
+    }
+    s_instance_pool.base = 0;
+#ifdef JPU_SUPPORT_PLATFORM_DRIVER_REGISTER
+    res = platform_driver_register(&jpu_driver);
+#else
+    res = jpu_probe(NULL);
+#endif /* JPU_SUPPORT_PLATFORM_DRIVER_REGISTER */
+
+    DPRINTK("[JPUDRV] end jpu_init result=0x%x\n", res);
+    return res;
+}
+
+static void __exit jpu_exit(void)
+{
+    DPRINTK("[JPUDRV] [+]jpu_exit\n");
+#ifdef JPU_SUPPORT_CLOCK_CONTROL
+    starfive_jpu_clk_disable(jpu_dev);
+    starfive_jpu_rst_assert(jpu_dev);
+#else
+    jpu_clk_disable();
+#endif
+#ifdef JPU_SUPPORT_PLATFORM_DRIVER_REGISTER
+    platform_driver_unregister(&jpu_driver);
+
+#else /* JPU_SUPPORT_PLATFORM_DRIVER_REGISTER */
+    if (s_instance_pool.base) {
+        vfree((const void *)s_instance_pool.base);
+        s_instance_pool.base = 0;
+    }
+#ifdef JPU_SUPPORT_RESERVED_VIDEO_MEMORY
+    if (s_video_memory.base) {
+        iounmap((void *)s_video_memory.base);
+        s_video_memory.base = 0;
+
+        jmem_exit(&s_jmem);
+    }
+#endif /* JPU_SUPPORT_RESERVED_VIDEO_MEMORY */
+
+    if (s_jpu_major > 0) {
+        cdev_del(&s_jpu_cdev);
+        unregister_chrdev_region(s_jpu_major, 1);
+        s_jpu_major = 0;
+    }
+
+#ifdef JPU_SUPPORT_ISR
+    if (s_jpu_irq)
+        free_irq(s_jpu_irq, &s_jpu_drv_context);
+#endif /* JPU_SUPPORT_ISR */
+
+    if (s_jpu_register.virt_addr) {
+        iounmap((void *)s_jpu_register.virt_addr);
+        s_jpu_register.virt_addr = 0x00;
+    }
+
+#endif /* JPU_SUPPORT_PLATFORM_DRIVER_REGISTER */
+    DPRINTK("[JPUDRV] [-]jpu_exit\n");
+
+    return;
+}
+
+MODULE_AUTHOR("A customer using C&M JPU, Inc.");
+MODULE_AUTHOR("Xingyu Wu <xingyu.wu@starfivetech.com>");
+MODULE_DESCRIPTION("JPU linux driver");
+MODULE_LICENSE("GPL");
+
+module_init(jpu_init);
+module_exit(jpu_exit);
+
+
+static void _set_reset(volatile unsigned long p_assert_reg,volatile unsigned long p_status_reg,int ibit)
+{
+    unsigned int read_value;
+	read_value = vic_readl(p_assert_reg);
+    read_value    &= ~(0x1<<ibit);
+    read_value    |= (0x1&0x1)<<ibit;
+	vic_writel(read_value,p_assert_reg);
+
+    do {
+        read_value = (vic_readl(p_status_reg))>>ibit;
+        read_value &= 0x1;
+    } while(read_value!=0x0);
+}
+
+static void _clr_reset(volatile unsigned long p_assert_reg,volatile unsigned long p_status_reg,int ibit)
+{
+    unsigned int read_value;
+	read_value = vic_readl(p_assert_reg);
+    read_value    &= ~(0x1<<ibit);
+	read_value	  |= (0x0&0x1)<<ibit;
+	vic_writel(read_value,p_assert_reg);
+
+    do {
+        read_value = (vic_readl(p_status_reg))>>ibit;
+        read_value &= 0x1;
+    } while(read_value!=0x1);
+}
+
+static void _enable_clk(volatile unsigned long p_reg,int ibit)
+{
+    unsigned int read_value;
+	read_value = vic_readl(p_reg);
+    read_value &= ~(0x1<<ibit);
+    read_value |= (0x1&0x1)<<ibit;
+	vic_writel(read_value,p_reg);
+}
+
+static void _disable_clk(volatile unsigned long p_reg,int ibit)
+{
+    unsigned int read_value;
+	read_value = vic_readl(p_reg);
+    read_value &= ~(0x1<<ibit);
+	read_value |= (0x0&0x1)<<ibit;
+	vic_writel(read_value,p_reg);
+}
+
+static void _reset_assert(volatile unsigned long p_assert_reg,volatile unsigned long p_status_reg)
+{
+    _set_reset(p_assert_reg,p_status_reg,NBIT_RSTN_JPEG_APB);
+    _set_reset(p_assert_reg,p_status_reg,NBIT_RSTN_JPEG_CCLK);
+}
+
+static void _reset_clear(volatile unsigned long p_assert_reg,volatile unsigned long p_status_reg)
+{
+    _clr_reset(p_assert_reg,p_status_reg,NBIT_RSTN_JPEG_AXI);
+    _clr_reset(p_assert_reg,p_status_reg,NBIT_RSTN_JPEG_CCLK);
+    _clr_reset(p_assert_reg,p_status_reg,NBIT_RSTN_JPEG_APB);
+}
+
+static int _reset(void)
+{
+    volatile unsigned long p_breg = (unsigned long)ioremap(rstgen_Software_RESET_BASE_REG_ADDR,0x20);
+
+    if(!p_breg){
+        return -1;
+    }
+
+    _reset_assert(p_breg+rstgen_Software_RESET_assert0_OFFSET,p_breg+rstgen_Software_RESET_status0_OFFSET);
+
+    mdelay(1);
+
+    _reset_clear(p_breg+rstgen_Software_RESET_assert0_OFFSET,p_breg+rstgen_Software_RESET_status0_OFFSET);
+
+    iounmap((void *)p_breg);
+
+    return 0;
+}
+
+static int _clk_control(int enable)
+{
+    volatile unsigned long p_breg = (unsigned long)ioremap(clk_BASE_REG_ADDR,0x100);
+    if(!p_breg){
+        return -1;
+    }
+
+    if(enable){
+        _enable_clk(p_breg+clk_jpeg_axi_ctrl_REG_OFFSET,31);
+        _enable_clk(p_breg+clk_jpcgc300_main_ctrl_REG_OFFSET,31);
+        _enable_clk(p_breg+clk_vdecbrg_main_ctrl_REG_OFFSET,31);
+        _enable_clk(p_breg+clk_jpeg_cclk_ctrl_REG_OFFSET,31);
+        _enable_clk(p_breg+clk_jpeg_apb_ctrl_REG_OFFSET,31);
+    }
+    else
+    {
+        _disable_clk(p_breg+clk_jpeg_axi_ctrl_REG_OFFSET,31);
+        _disable_clk(p_breg+clk_jpeg_cclk_ctrl_REG_OFFSET,31);
+        _disable_clk(p_breg+clk_jpeg_apb_ctrl_REG_OFFSET,31);
+    }
+
+    iounmap((void *)p_breg);
+
+    return 0;
+}
+
+int jpu_hw_reset(void)
+{
+	_reset();
+	DPRINTK("[JPUDRV] request vpu reset from application. \n");
+	return 0;
+}
+
+int jpu_clk_enable(void)
+{
+	_clk_control(1);
+	return 0;
+}
+
+void jpu_clk_disable(void)
+{
+	_clk_control(0);
+}
+
+
+

+ 50 - 0
soft_3rdpart/codaj12/jdi/linux/driver/jpu.h

@@ -0,0 +1,50 @@
+
+
+#ifndef __JPU_DRV_H__
+#define __JPU_DRV_H__
+
+#include <linux/fs.h>
+#include <linux/types.h>
+
+#define JDI_IOCTL_MAGIC  'J'
+
+#define JDI_IOCTL_ALLOCATE_PHYSICAL_MEMORY          _IO(JDI_IOCTL_MAGIC, 0)
+#define JDI_IOCTL_FREE_PHYSICALMEMORY               _IO(JDI_IOCTL_MAGIC, 1)
+#define JDI_IOCTL_WAIT_INTERRUPT                    _IO(JDI_IOCTL_MAGIC, 2)
+#define JDI_IOCTL_SET_CLOCK_GATE                    _IO(JDI_IOCTL_MAGIC, 3)
+#define JDI_IOCTL_RESET                             _IO(JDI_IOCTL_MAGIC, 4)
+#define JDI_IOCTL_GET_INSTANCE_POOL                 _IO(JDI_IOCTL_MAGIC, 5)
+#define JDI_IOCTL_GET_RESERVED_VIDEO_MEMORY_INFO    _IO(JDI_IOCTL_MAGIC, 6)
+#define JDI_IOCTL_GET_REGISTER_INFO                 _IO(JDI_IOCTL_MAGIC, 7)
+#define JDI_IOCTL_OPEN_INSTANCE                     _IO(JDI_IOCTL_MAGIC, 8)
+#define JDI_IOCTL_CLOSE_INSTANCE                    _IO(JDI_IOCTL_MAGIC, 9)
+#define JDI_IOCTL_GET_INSTANCE_NUM                  _IO(JDI_IOCTL_MAGIC, 10)
+#define JDI_IOCTL_FLUSH_DCACHE                 		_IO(JDI_IOCTL_MAGIC, 11)
+#define JDI_IOCTL_GET_PHYSICAL_MEMORY               _IO(JDI_IOCTL_MAGIC, 12)
+
+#define MEM2SYS(addr) ((addr) > 0x80000000 && (addr) < 0x87FFFFFFF ? ((addr)+0xF80000000):(addr))
+
+typedef struct jpudrv_flush_cache_t {
+    unsigned long start;
+    unsigned long size;
+    unsigned char flag;
+} jpudrv_flush_cache_t;
+
+typedef struct jpudrv_buffer_t {
+    unsigned int size;
+    unsigned long phys_addr;
+    unsigned long base;                     /* kernel logical address in use kernel */
+    unsigned long virt_addr;                /* virtual user space address */
+} jpudrv_buffer_t;
+
+typedef struct jpudrv_inst_info_t {
+    unsigned int inst_idx;
+    int inst_open_count;    /* for output only*/
+} jpudrv_inst_info_t;
+
+typedef struct jpudrv_intr_info_t {
+    unsigned int    timeout;
+    int             intr_reason;
+    unsigned int    inst_idx;
+} jpudrv_intr_info_t;
+#endif

+ 2 - 0
soft_3rdpart/codaj12/jdi/linux/driver/jpu.mod

@@ -0,0 +1,2 @@
+/home/samin/data/startlight/freedom-u-sdk/soft_3rdparty/codaj12/jdi/linux/driver/jpu.o
+

+ 26 - 0
soft_3rdpart/codaj12/jdi/linux/driver/load

@@ -0,0 +1,26 @@
+#!/bin/sh
+
+module="jpu"
+device="jpu"
+mode="664"
+
+# Group: since distributions do	it differently,	look for wheel or use staff
+if grep	'^staff:' /etc/group > /dev/null; then
+    group="staff"
+else
+    group="wheel"
+fi
+
+# invoke insmod	with all arguments we got
+# and use a pathname, as newer modutils	don't look in .	by default
+/sbin/insmod -f	./$module.ko $*	|| exit	1
+
+major=`cat /proc/devices | awk "\\$2==\"$module\" {print \\$1}"`
+
+# Remove stale nodes and replace them, then give gid and perms
+# Usually the script is	shorter, it's simple that has several devices in it.
+
+rm -f /dev/${device}
+mknod /dev/${device} c $major 0
+chgrp $group /dev/${device}
+chmod $mode  /dev/${device}

+ 25 - 0
soft_3rdpart/codaj12/jdi/linux/driver/load.sh

@@ -0,0 +1,25 @@
+#!/bin/sh
+
+module="jpu"
+device="jpu"
+mode="664"
+
+# Group: since distributions do	it differently,	look for wheel or use staff
+if grep	'^staff:' /etc/group > /dev/null; then
+    group="staff"
+else
+    group="wheel"
+fi
+
+# invoke insmod	with all arguments we got
+# and use a pathname, as newer modutils	don't look in .	by default
+/sbin/insmod ./$module.ko $*	|| exit	1
+
+major=`cat /proc/devices | grep "$device"|awk {'print $1'}`
+# Remove stale nodes and replace them, then give gid and perms
+# Usually the script is	shorter, it's simple that has several devices in it.
+
+rm -f /dev/${device}
+mknod /dev/${device} c $major 0
+chgrp $group /dev/${device}
+chmod $mode  /dev/${device}

+ 24 - 0
soft_3rdpart/codaj12/jdi/linux/driver/load_android.sh

@@ -0,0 +1,24 @@
+module="jpu"
+device="jpu"
+mode="664"
+
+# invoke insmod	with all arguments we got
+# and use a pathname, as newer modutils	don't look in .	by default
+/system/bin/insmod /system/lib/modules/$module.ko $*	|| exit	1
+echo "module $module inserted"
+
+#remove old nod
+rm -f /dev/${device}
+
+#read the major asigned at loading time
+major=`cat /proc/devices | busybox awk "\\$2==\"$module\" {print \\$1}"`
+echo "$module major = $major"
+
+# Remove stale nodes and replace them, then give gid and perms
+# Usually the script is	shorter, it's simple that has several devices in it.
+
+busybox mknod /dev/${device} c $major 0
+echo "node $device created"
+
+chmod $mode  /dev/${device}
+echo "set node access to $mode"

+ 14 - 0
soft_3rdpart/codaj12/jdi/linux/driver/unload

@@ -0,0 +1,14 @@
+#!/bin/sh
+module="jpu"
+device="jpu"
+
+# invoke rmmod with all	arguments we got
+/sbin/rmmod $module $* || exit 1
+
+# Remove stale nodes
+rm -f /dev/${device} 
+
+
+
+
+ 

+ 14 - 0
soft_3rdpart/codaj12/jdi/linux/driver/unload.sh

@@ -0,0 +1,14 @@
+#!/bin/sh
+module="jpu"
+device="jpu"
+
+# invoke rmmod with all	arguments we got
+/sbin/rmmod $module $* || exit 1
+
+# Remove stale nodes
+rm -f /dev/${device} 
+
+
+
+
+ 

+ 13 - 0
soft_3rdpart/codaj12/jdi/linux/driver/unload_android.sh

@@ -0,0 +1,13 @@
+module="jpu"
+device="jpu"
+
+# invoke rmmod with all	arguments we got
+/system/bin/rmmod $module $* || exit 1
+
+# Remove stale nodes
+rm -f /dev/${device} 
+
+
+
+
+ 

+ 874 - 0
soft_3rdpart/codaj12/jdi/linux/jdi.c

@@ -0,0 +1,874 @@
+/*
+ * Copyright (c) 2018, Chips&Media
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#if defined(linux) || defined(__linux) || defined(ANDROID)
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#ifdef    _KERNEL_
+#include <linux/delay.h>
+#endif
+#include <signal.h>        /* SIGIO */
+#include <fcntl.h>        /* fcntl */
+#include <pthread.h>
+#include <sys/mman.h>        /* mmap */
+#include <sys/ioctl.h>        /* fopen/fread */
+#include <sys/errno.h>        /* fopen/fread */
+#include <sys/types.h>
+#include <sys/time.h>
+#include <termios.h>
+
+#include "driver/jpu.h"
+#include "../jdi.h"
+#include "jpulog.h"
+#include "jputypes.h"
+#include "regdefine.h"
+
+
+#define JPU_DEVICE_NAME "/dev/jpu"
+#define JDI_INSTANCE_POOL_SIZE          sizeof(jpu_instance_pool_t)
+#define JDI_INSTANCE_POOL_TOTAL_SIZE    (JDI_INSTANCE_POOL_SIZE + sizeof(MUTEX_HANDLE)*JDI_NUM_LOCK_HANDLES)
+typedef pthread_mutex_t    MUTEX_HANDLE;
+
+#endif /* CNM_FPGA_PLATFORM */
+
+
+
+/***********************************************************************************
+*
+***********************************************************************************/
+
+#define JDI_DRAM_PHYSICAL_BASE          0x00
+#define JDI_DRAM_PHYSICAL_SIZE          (64*1024*1024)
+#define JDI_SYSTEM_ENDIAN               JDI_LITTLE_ENDIAN
+#define JPU_REG_SIZE                    0x300
+#define JDI_NUM_LOCK_HANDLES            4
+
+typedef struct jpudrv_buffer_pool_t
+{
+    jpudrv_buffer_t jdb;
+    BOOL            inuse;
+} jpudrv_buffer_pool_t;
+
+typedef struct  {
+    Int32                   jpu_fd;
+    jpu_instance_pool_t*    pjip;
+    Int32                   task_num;
+    Int32                   clock_state;
+    jpudrv_buffer_t         jdb_register;
+    jpudrv_buffer_pool_t    jpu_buffer_pool[MAX_JPU_BUFFER_POOL];
+    Int32                   jpu_buffer_pool_count;
+    void*                   jpu_mutex;
+} jdi_info_t;
+
+static jdi_info_t s_jdi_info;
+
+static Int32 swap_endian(BYTE* data, Uint32 len, Uint32 endian);
+
+void jdi_flush_ddr(unsigned long start,unsigned long size,unsigned char flag)
+{
+	jdi_info_t *jdi;
+	jpudrv_flush_cache_t cache_info;
+	
+	jdi = &s_jdi_info;
+	cache_info.start = start;
+	cache_info.size = size;
+	cache_info.flag = flag;
+
+	ioctl(jdi->jpu_fd, JDI_IOCTL_FLUSH_DCACHE, &cache_info);
+}
+
+int jdi_probe()
+{
+    int ret;
+
+    ret = jdi_init();
+    jdi_release();
+
+    return ret;
+}
+
+/* @return number of tasks.
+ */
+int jdi_get_task_num()
+{
+    jdi_info_t *jdi;
+
+    jdi = &s_jdi_info;
+
+    if (jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00) {
+        return 0;
+    }
+
+    return jdi->task_num;
+}
+
+
+int jdi_init()
+{
+    jdi_info_t *jdi;
+    int i;
+
+    jdi = &s_jdi_info;
+
+    if (jdi->jpu_fd != -1 && jdi->jpu_fd != 0x00)
+    {
+        jdi_lock();
+        jdi->task_num++;
+        jdi_unlock();
+        return 0;
+    }
+
+#ifdef ANDROID
+    system("/system/lib/modules/load_android.sh");
+#endif /* ANDROID */
+
+    jdi->jpu_fd = open(JPU_DEVICE_NAME, O_RDWR);
+    if (jdi->jpu_fd < 0) {
+        JLOG(ERR, "[JDI] Can't open jpu driver. [error=%s]. try to run jdi/linux/driver/load.sh script \n", strerror(errno));
+        return -1;
+    }
+
+    memset(jdi->jpu_buffer_pool, 0x00, sizeof(jpudrv_buffer_pool_t)*MAX_JPU_BUFFER_POOL);
+
+    if (!jdi_get_instance_pool()) {
+        JLOG(ERR, "[JDI] fail to create instance pool for saving context \n");
+        goto ERR_JDI_INIT;
+    }
+
+    if (jdi->pjip->instance_pool_inited == FALSE) {
+        Uint32* pCodecInst;
+        pthread_mutexattr_t mutexattr;
+        pthread_mutexattr_init(&mutexattr);
+        pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED);
+#if defined(ANDROID) || !defined(PTHREAD_MUTEX_ROBUST_NP)
+#else
+         /* If a process or a thread is terminated abnormally,
+         * pthread_mutexattr_setrobust_np(attr, PTHREAD_MUTEX_ROBUST_NP) makes
+         * next onwer call pthread_mutex_lock() without deadlock.
+         */
+        pthread_mutexattr_setrobust_np(&mutexattr, PTHREAD_MUTEX_ROBUST_NP);
+#endif
+        pthread_mutex_init((MUTEX_HANDLE *)jdi->jpu_mutex, &mutexattr);
+
+        for( i = 0; i < MAX_NUM_INSTANCE; i++) {
+            pCodecInst    = (Uint32*)jdi->pjip->jpgInstPool[i];
+            pCodecInst[1] = i;    // indicate instIndex of CodecInst
+            pCodecInst[0] = 0;    // indicate inUse of CodecInst
+        }
+        jdi->pjip->instance_pool_inited = TRUE;
+    }
+    if (ioctl(jdi->jpu_fd, JDI_IOCTL_GET_REGISTER_INFO, &jdi->jdb_register) < 0)
+    {
+        JLOG(ERR, "[JDI] fail to get host interface register\n");
+        goto ERR_JDI_INIT;
+    }
+    jdi->jdb_register.virt_addr = (unsigned long)mmap(NULL, jdi->jdb_register.size, PROT_READ | PROT_WRITE, MAP_SHARED, jdi->jpu_fd, jdi->jdb_register.phys_addr);
+    if (jdi->jdb_register.virt_addr == (unsigned long)MAP_FAILED) {
+        JLOG(ERR, "[JDI] fail to map jpu registers \n");
+        goto ERR_JDI_INIT;
+    }
+    JLOG(INFO, "[JDI] map jdb_register virtaddr=0x%lx, size=%d\n", jdi->jdb_register.virt_addr, jdi->jdb_register.size);
+    jdi_set_clock_gate(1);
+
+
+
+    if (jdi_lock() < 0)
+    {
+        JLOG(ERR, "[JDI] fail to handle lock function\n");
+        goto ERR_JDI_INIT;
+    }
+
+    jdi->task_num++;
+    jdi_unlock();
+
+    JLOG(INFO, "[JDI] success to init driver \n");
+    return 0;
+
+ERR_JDI_INIT:
+    jdi_unlock();
+    jdi_release();
+    return -1;
+}
+
+int jdi_release()
+{
+    jdi_info_t *jdi;
+
+    jdi = &s_jdi_info;
+    if (!jdi || jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00) {
+        return 0;
+    }
+
+    if (jdi_lock() < 0) {
+        JLOG(ERR, "[JDI] fail to handle lock function\n");
+        return -1;
+    }
+
+    if (jdi->task_num == 0) {
+        JLOG(ERR, "[JDI] %s:%d task_num is 0\n", __FUNCTION__, __LINE__);
+        jdi_unlock();
+        return 0;
+    }
+
+    jdi->task_num--;
+    if (jdi->task_num > 0) {// means that the opened instance remains
+        jdi_unlock();
+        return 0;
+    }
+    if (jdi->jdb_register.virt_addr) {
+        if (munmap((void *)jdi->jdb_register.virt_addr, jdi->jdb_register.size) < 0) { //lint !e511
+            JLOG(ERR, "%s:%d failed to munmap\n", __FUNCTION__, __LINE__);
+        }
+    }
+
+    memset(&jdi->jdb_register, 0x00, sizeof(jpudrv_buffer_t));
+    jdi_unlock();
+    if (jdi->jpu_fd != -1 && jdi->jpu_fd != 0x00) {
+        if (jdi->pjip != NULL) {
+            if (munmap((void*)jdi->pjip, JDI_INSTANCE_POOL_TOTAL_SIZE) < 0) {
+                JLOG(ERR, "%s:%d failed to munmap\n", __FUNCTION__, __LINE__);
+            }
+        }
+        close(jdi->jpu_fd);
+    }
+
+    memset(jdi, 0x00, sizeof(jdi_info_t));
+
+    return 0;
+}
+
+jpu_instance_pool_t *jdi_get_instance_pool()
+{
+    jdi_info_t *jdi;
+    jpudrv_buffer_t jdb;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00 )
+        return NULL;
+
+    memset(&jdb, 0x00, sizeof(jpudrv_buffer_t));
+    if (!jdi->pjip) {
+        jdb.size = JDI_INSTANCE_POOL_TOTAL_SIZE;
+        if (ioctl(jdi->jpu_fd, JDI_IOCTL_GET_INSTANCE_POOL, &jdb) < 0) {
+            JLOG(ERR, "[JDI] fail to allocate get instance pool physical space=%d\n", (int)jdb.size);
+            return NULL;
+        }
+
+        jdb.virt_addr = (unsigned long)mmap(NULL, jdb.size, PROT_READ | PROT_WRITE, MAP_SHARED, jdi->jpu_fd, 0);
+        if (jdb.virt_addr == (unsigned long)MAP_FAILED) {
+            JLOG(ERR, "[JDI] fail to map instance pool phyaddr=0x%lx, size = %d\n", (int)jdb.phys_addr, (int)jdb.size);
+            return NULL;
+        }
+        jdi->pjip      = (jpu_instance_pool_t *)jdb.virt_addr;//lint !e511
+        //change the pointer of jpu_mutex to at end pointer of jpu_instance_pool_t to assign at allocated position.
+        jdi->jpu_mutex = (void *)((unsigned long)jdi->pjip + JDI_INSTANCE_POOL_SIZE); //lint !e511
+
+        JLOG(INFO, "[JDI] instance pool physaddr=%p, virtaddr=%p, base=%p, size=%d\n", jdb.phys_addr, jdb.virt_addr, jdb.base, jdb.size);
+    }
+
+    return (jpu_instance_pool_t *)jdi->pjip;
+}
+
+int jdi_open_instance(unsigned long inst_idx)
+{
+    jdi_info_t *jdi;
+    jpudrv_inst_info_t inst_info;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    inst_info.inst_idx = inst_idx;
+    if (ioctl(jdi->jpu_fd, JDI_IOCTL_OPEN_INSTANCE, &inst_info) < 0)
+    {
+        JLOG(ERR, "[JDI] fail to deliver open instance num inst_idx=%d\n", (int)inst_idx);
+        return -1;
+    }
+    jdi->pjip->jpu_instance_num = inst_info.inst_open_count;
+
+    return 0;
+}
+
+int jdi_close_instance(unsigned long inst_idx)
+{
+    jdi_info_t *jdi;
+    jpudrv_inst_info_t inst_info;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    inst_info.inst_idx = inst_idx;
+    if (ioctl(jdi->jpu_fd, JDI_IOCTL_CLOSE_INSTANCE, &inst_info) < 0)
+    {
+        JLOG(ERR, "[JDI] fail to deliver open instance num inst_idx=%d\n", (int)inst_idx);
+        return -1;
+    }
+    jdi->pjip->jpu_instance_num = inst_info.inst_open_count;
+
+    return 0;
+}
+int jdi_get_instance_num()
+{
+    jdi_info_t *jdi;
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    return jdi->pjip->jpu_instance_num;
+}
+
+int jdi_hw_reset()
+{
+    jdi_info_t *jdi;
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    return ioctl(jdi->jpu_fd, JDI_IOCTL_RESET, 0);
+
+}
+
+static void restore_mutex_in_dead(MUTEX_HANDLE *mutex)
+{
+    int mutex_value;
+
+    if (!mutex)
+        return;
+#if defined(ANDROID)
+    mutex_value = mutex->value;
+#else
+    memcpy(&mutex_value, mutex, sizeof(mutex_value));
+#endif
+    if (mutex_value == (int)0xdead10cc) // destroy by device driver
+    {
+        pthread_mutexattr_t mutexattr;
+        pthread_mutexattr_init(&mutexattr);
+        pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED);
+        pthread_mutex_init(mutex, &mutexattr);
+    }
+}
+
+int jdi_lock()
+{
+    jdi_info_t *jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00) {
+        JLOG(ERR, "%s:%d JDI handle isn't initialized\n", __FUNCTION__, __LINE__);
+        return -1;
+    }
+
+
+#if defined(ANDROID) || !defined(PTHREAD_MUTEX_ROBUST_NP)
+    restore_mutex_in_dead((MUTEX_HANDLE *)jdi->jpu_mutex);
+    pthread_mutex_lock((MUTEX_HANDLE*)jdi->jpu_mutex);
+#else
+    if (pthread_mutex_lock(&jdi->jpu_mutex) != 0) {
+        JLOG(ERR, "%s:%d failed to pthread_mutex_locK\n", __FUNCTION__, __LINE__);
+        return -1;
+    }
+#endif
+
+    return 0;//lint !e454
+}
+
+void jdi_unlock()
+{
+    jdi_info_t *jdi;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd <= 0)
+        return;
+
+    pthread_mutex_unlock((MUTEX_HANDLE *)jdi->jpu_mutex);//lint !e455
+}
+void jdi_write_register(unsigned long addr, unsigned long data)
+{
+    jdi_info_t *jdi;
+    unsigned long *reg_addr;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00)
+        return;
+
+
+    reg_addr = (unsigned long *)(addr + (unsigned long)jdi->jdb_register.virt_addr);
+    *(volatile unsigned int *)reg_addr = data;
+}
+
+unsigned long jdi_read_register(unsigned long addr)
+{
+    jdi_info_t *jdi;
+    unsigned long *reg_addr;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd == -1 || jdi->jpu_fd == 0x00)
+        return (unsigned int)-1;
+
+
+    reg_addr = (unsigned long *)(addr + (unsigned long)jdi->jdb_register.virt_addr);
+    return *(volatile unsigned int *)reg_addr;
+}
+
+int jdi_write_memory(unsigned long addr, unsigned char *data, int len, int endian)
+{
+    jdi_info_t *jdi;
+    jpudrv_buffer_t jdb;
+    Uint32          offset;
+    Uint32          i;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd==-1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    memset(&jdb, 0x00, sizeof(jpudrv_buffer_t));
+
+    for (i=0; i<MAX_JPU_BUFFER_POOL; i++)
+    {
+        if (jdi->jpu_buffer_pool[i].inuse == 1)
+        {
+            jdb = jdi->jpu_buffer_pool[i].jdb;
+            if (addr >= jdb.phys_addr && addr < (jdb.phys_addr + jdb.size)) {
+                break;
+            }
+        }
+    }
+
+    if (i == MAX_JPU_BUFFER_POOL) {
+        JLOG(ERR, "%s NOT FOUND ADDRESS: %#lx\n", __FUNCTION__, addr);
+        return -1;
+    }
+
+    if (!jdb.size) {
+        JLOG(ERR, "address 0x%08x is not mapped address!!!\n", (int)addr);
+        return -1;
+    }
+
+    offset = addr - (unsigned long)jdb.phys_addr;
+    swap_endian(data, len, endian);
+    memcpy((void *)((unsigned long)jdb.virt_addr+offset), data, len);
+
+   jdi_flush_ddr((unsigned long )(jdb.phys_addr+offset),len,1);
+	
+    return len;
+}
+
+int jdi_read_memory(unsigned long addr, unsigned char *data, int len, int endian)
+{
+    jdi_info_t *jdi;
+    jpudrv_buffer_t jdb;
+    unsigned long offset;
+    int i;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd==-1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    memset(&jdb, 0x00, sizeof(jpudrv_buffer_t));
+
+    for (i=0; i<MAX_JPU_BUFFER_POOL; i++)
+    {
+        if (jdi->jpu_buffer_pool[i].inuse == 1)
+        {
+            jdb = jdi->jpu_buffer_pool[i].jdb;
+            if (addr >= jdb.phys_addr && addr < (jdb.phys_addr + jdb.size))
+                break;
+        }
+    }
+
+    if (len == 0) {
+        return 0;
+    }
+
+    if (!jdb.size)
+        return -1;
+
+
+
+    offset = addr - (unsigned long)jdb.phys_addr;
+
+    jdi_flush_ddr((unsigned long )(jdb.phys_addr+offset),len,1);
+    memcpy(data, (const void *)((unsigned long)jdb.virt_addr+offset), len);
+    swap_endian(data, len,  endian);
+
+    return len;
+}
+
+int jdi_attach_dma_memory(jpu_buffer_t *vb)
+{
+    jdi_info_t *jdi;
+    int i;
+    jpudrv_buffer_t jdb;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd==-1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    memset(&jdb, 0x00, sizeof(jpudrv_buffer_t));
+
+    jdb.virt_addr = vb->virt_addr;
+    if (ioctl(jdi->jpu_fd, JDI_IOCTL_GET_PHYSICAL_MEMORY, &jdb) < 0)
+    {
+        JLOG(ERR, "[JDI] fail to jdi_allocate_dma_memory size=%d\n", vb->size);
+        return -1;
+    }
+
+    vb->phys_addr = (unsigned long)jdb.phys_addr;
+    vb->base = (unsigned long)jdb.base;
+
+    jdi_lock();
+    for (i=0; i<MAX_JPU_BUFFER_POOL; i++)
+    {
+        if (jdi->jpu_buffer_pool[i].inuse == 0)
+        {
+            jdi->jpu_buffer_pool[i].jdb = jdb;
+            jdi->jpu_buffer_pool_count++;
+            jdi->jpu_buffer_pool[i].inuse = 1;
+            break;
+        }
+    }
+    jdi_unlock();
+    JLOG(INFO, "[JDI] jdi_attach_dma_memory, physaddr=%p, virtaddr=%p~%p, size=%d\n",
+         vb->phys_addr, vb->virt_addr, vb->virt_addr + vb->size, vb->size);
+    return 0;
+}
+
+int jdi_allocate_dma_memory(jpu_buffer_t *vb)
+{
+    jdi_info_t *jdi;
+    int i;
+    jpudrv_buffer_t jdb;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd==-1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    memset(&jdb, 0x00, sizeof(jpudrv_buffer_t));
+
+    jdb.size = vb->size;
+    if (ioctl(jdi->jpu_fd, JDI_IOCTL_ALLOCATE_PHYSICAL_MEMORY, &jdb) < 0)
+    {
+        JLOG(ERR, "[JDI] fail to jdi_allocate_dma_memory size=%d\n", vb->size);
+        return -1;
+    }
+
+    vb->phys_addr = (unsigned long)jdb.phys_addr;
+    vb->base = (unsigned long)jdb.base;
+
+    //map to virtual address
+    jdb.virt_addr = (unsigned long)mmap(NULL, jdb.size, PROT_READ | PROT_WRITE, MAP_SHARED, jdi->jpu_fd, MEM2SYS(jdb.phys_addr));
+    if (jdb.virt_addr == (unsigned long)MAP_FAILED) {
+        memset(vb, 0x00, sizeof(jpu_buffer_t));
+        return -1;
+    }
+    vb->virt_addr = jdb.virt_addr;
+
+    jdi_lock();
+    for (i=0; i<MAX_JPU_BUFFER_POOL; i++)
+    {
+        if (jdi->jpu_buffer_pool[i].inuse == 0)
+        {
+            jdi->jpu_buffer_pool[i].jdb = jdb;
+            jdi->jpu_buffer_pool_count++;
+            jdi->jpu_buffer_pool[i].inuse = 1;
+            break;
+        }
+    }
+    jdi_unlock();
+    JLOG(INFO, "[JDI] jdi_allocate_dma_memory, physaddr=%p, virtaddr=%p~%p, size=%d\n",
+         vb->phys_addr, vb->virt_addr, vb->virt_addr + vb->size, vb->size);
+    return 0;
+}
+
+void jdi_free_dma_memory(jpu_buffer_t *vb)
+{
+    jdi_info_t *jdi;
+    int i;
+    jpudrv_buffer_t jdb;
+
+
+    jdi = &s_jdi_info;
+
+    if(!vb || !jdi || jdi->jpu_fd==-1 || jdi->jpu_fd == 0x00)
+        return;
+
+    if (vb->size == 0)
+        return ;
+
+    memset(&jdb, 0x00, sizeof(jpudrv_buffer_t));
+
+    jdi_lock();
+    for (i=0; i<MAX_JPU_BUFFER_POOL; i++) {
+        if (jdi->jpu_buffer_pool[i].jdb.phys_addr == vb->phys_addr) {
+            jdi->jpu_buffer_pool[i].inuse = 0;
+            jdi->jpu_buffer_pool_count--;
+            jdb = jdi->jpu_buffer_pool[i].jdb;
+            break;
+        }
+    }
+	jdi_unlock();
+
+    if (!jdb.size)
+    {
+        JLOG(ERR, "[JDI] invalid buffer to free address = 0x%lx\n", (int)jdb.virt_addr);
+        return ;
+    }
+    ioctl(jdi->jpu_fd, JDI_IOCTL_FREE_PHYSICALMEMORY, &jdb);
+
+    if (munmap((void *)jdb.virt_addr, jdb.size) != 0) {
+        JLOG(ERR, "[JDI] fail to jdi_free_dma_memory virtial address = 0x%lx\n", (int)jdb.virt_addr);
+    }
+    memset(vb, 0, sizeof(jpu_buffer_t));
+}
+
+
+
+int jdi_set_clock_gate(int enable)
+{
+    jdi_info_t *jdi = NULL;
+    int ret;
+
+    jdi = &s_jdi_info;
+    if(!jdi || jdi->jpu_fd==-1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    jdi->clock_state = enable;
+    ret = ioctl(jdi->jpu_fd, JDI_IOCTL_SET_CLOCK_GATE, &enable);
+
+    return ret;
+}
+
+int jdi_get_clock_gate()
+{
+    jdi_info_t *jdi;
+    int ret;
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd==-1 || jdi->jpu_fd == 0x00)
+        return -1;
+
+    ret = jdi->clock_state;
+
+    return ret;
+}
+
+
+
+
+int jdi_wait_inst_ctrl_busy(int timeout, unsigned int addr_flag_reg, unsigned int flag)
+{
+	Int64 elapse, cur;
+	unsigned int data_flag_reg;
+	struct timeval tv;
+	int retry_count;
+	tv.tv_sec = 0;
+	tv.tv_usec = 0;
+	gettimeofday(&tv, NULL);
+	elapse = tv.tv_sec*1000 + tv.tv_usec/1000;
+
+
+	while(1)
+	{
+		data_flag_reg = jdi_read_register(addr_flag_reg);
+
+		if (((data_flag_reg >> 4)&0xf) == flag)
+			break;
+
+		gettimeofday(&tv, NULL);
+		cur = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+
+		if (timeout > 0 && (cur - elapse) > timeout)
+		{
+
+			for (retry_count=0; retry_count<10; retry_count++) {
+				JLOG(ERR, "[VDI] jdi_wait_inst_ctrl_busy timeout, 0x%x=0x%lx\n", addr_flag_reg, jdi_read_register(addr_flag_reg));
+			}
+			return -1;
+		}
+	}
+	return 0;
+
+}
+
+
+int jdi_wait_interrupt(int timeout, unsigned int addr_int_reason, unsigned long instIdx)
+{
+    int intr_reason = 0;
+    jdi_info_t *jdi;
+    int ret;
+    jpudrv_intr_info_t intr_info;
+
+
+    jdi = &s_jdi_info;
+
+    if(!jdi || jdi->jpu_fd <= 0)
+        return -1;
+
+
+    intr_info.timeout     = timeout;
+    intr_info.intr_reason = 0;
+    intr_info.inst_idx    = instIdx;
+    ret = ioctl(jdi->jpu_fd, JDI_IOCTL_WAIT_INTERRUPT, (void*)&intr_info);
+    if (ret != 0)
+        return -1;
+    intr_reason = intr_info.intr_reason;
+
+    return intr_reason;
+}
+
+void jdi_log(int cmd, int step, int inst)
+{
+    Int32   i;
+
+    switch(cmd)
+    {
+    case JDI_LOG_CMD_PICRUN:
+        if (step == 1)    //
+            JLOG(INFO, "\n**PIC_RUN INST=%d start\n", inst);
+        else
+            JLOG(INFO, "\n**PIC_RUN INST=%d  end \n", inst);
+        break;
+    case JDI_LOG_CMD_INIT:
+        if (step == 1)    //
+            JLOG(INFO, "\n**INIT INST=%d  start\n", inst);
+        else
+            JLOG(INFO, "\n**INIT INST=%d  end \n", inst);
+        break;
+    case JDI_LOG_CMD_RESET:
+        if (step == 1)    //
+            JLOG(INFO, "\n**RESET INST=%d  start\n", inst);
+        else
+            JLOG(INFO, "\n**RESET INST=%d  end \n", inst);
+        break;
+    case JDI_LOG_CMD_PAUSE_INST_CTRL:
+        if (step == 1)    //
+            JLOG(INFO, "\n**PAUSE INST_CTRL  INST=%d start\n", inst);
+        else
+            JLOG(INFO, "\n**PAUSE INST_CTRL  INST=%d end\n", inst);
+        break;
+    }
+
+    for (i=(inst*NPT_REG_SIZE); i<=((inst*NPT_REG_SIZE)+0x250); i=i+16)
+    {
+        JLOG(INFO, "0x%04xh: 0x%08x 0x%08x 0x%08x 0x%08x\n", i,
+            jdi_read_register(i), jdi_read_register(i+4),
+            jdi_read_register(i+8), jdi_read_register(i+0xc));
+    }
+
+    JLOG(INFO, "0x%04xh: 0x%08x 0x%08x 0x%08x 0x%08x\n", NPT_PROC_BASE,
+        jdi_read_register(NPT_PROC_BASE+0x00), jdi_read_register(NPT_PROC_BASE+4),
+        jdi_read_register(NPT_PROC_BASE+8), jdi_read_register(NPT_PROC_BASE+0xc));
+}
+
+
+static void SwapByte(Uint8* data, Uint32 len)
+{
+    Uint8   temp;
+    Uint32  i;
+
+    for (i=0; i<len; i+=2) {
+        temp      = data[i];
+        data[i]   = data[i+1];
+        data[i+1] = temp;
+    }
+}
+
+static void SwapWord(Uint8* data, Uint32 len)
+{
+    Uint16  temp;
+    Uint16* ptr = (Uint16*)data;
+    Int32   i, size = len/sizeof(Uint16);
+
+    for (i=0; i<size; i+=2) {
+        temp      = ptr[i];
+        ptr[i]   = ptr[i+1];
+        ptr[i+1] = temp;
+    }
+}
+
+static void SwapDword(Uint8* data, Uint32 len)
+{
+    Uint32  temp;
+    Uint32* ptr = (Uint32*)data;
+    Int32   i, size = len/sizeof(Uint32);
+
+    for (i=0; i<size; i+=2) {
+        temp      = ptr[i];
+        ptr[i]   = ptr[i+1];
+        ptr[i+1] = temp;
+    }
+}
+
+
+Int32 swap_endian(BYTE* data, Uint32 len, Uint32 endian)
+{
+    Uint8   endianMask[8] = {   // endianMask : [2] - 4byte unit swap
+        0x00, 0x07, 0x04, 0x03, //              [1] - 2byte unit swap
+        0x06, 0x05, 0x02, 0x01  //              [0] - 1byte unit swap
+    };
+    Uint8   targetEndian;
+    Uint8   systemEndian;
+    Uint8   changes;
+    BOOL    byteSwap=FALSE, wordSwap=FALSE, dwordSwap=FALSE;
+
+    if (endian > 7) {
+        JLOG(ERR, "Invalid endian mode: %d, expected value: 0~7\n", endian);
+        return -1;
+    }
+
+    targetEndian = endianMask[endian];
+    systemEndian = endianMask[JDI_SYSTEM_ENDIAN];
+    changes      = targetEndian ^ systemEndian;
+    byteSwap     = changes & 0x01 ? TRUE : FALSE;
+    wordSwap     = changes & 0x02 ? TRUE : FALSE;
+    dwordSwap    = changes & 0x04 ? TRUE : FALSE;
+
+    if (byteSwap == TRUE)  SwapByte(data, len);
+    if (wordSwap == TRUE)  SwapWord(data, len);
+    if (dwordSwap == TRUE) SwapDword(data, len);
+
+    return changes == 0 ? 0 : 1;
+}
+
+
+
+

+ 660 - 0
soft_3rdpart/codaj12/jdi/mm.c

@@ -0,0 +1,660 @@
+/*
+ * Copyright (c) 2018, Chips&Media
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "mm.h"
+
+#ifdef MM_DEBUG
+#ifdef _MSC_VER
+#define DPRINT(_fmt, ...)       printf(_fmt, __VA_ARGS__)
+#else
+#define DPRINT(_fmt, ...)       printf(_fmt, args...)
+#endif
+#else
+#define DPRINT(_fmt, ...)
+#endif
+
+
+
+#define P_ALLOC(_x)         malloc(_x)
+#define P_FREE(_x)          free(_x)
+#define ASSERT(_exp)        if (!(_exp)) { printf("ASSERT at %s:%d\n", __FILE__, __LINE__); while(1); }
+#define HEIGHT(_tree)       (_tree==NULL ? -1 : _tree->height)
+#define MAX(_a, _b)         (_a >= _b ? _a : _b)
+
+typedef enum {
+    LEFT,
+    RIGHT
+} rotation_dir_t;
+
+
+
+typedef struct avl_node_data_struct {
+    int     key;
+    page_t* page;
+} avl_node_data_t;
+
+static avl_node_t*
+make_avl_node(
+    vmem_key_t key,
+    page_t* page
+    )
+{
+    avl_node_t* node = (avl_node_t*)P_ALLOC(sizeof(avl_node_t));
+    if (node != NULL)
+    {
+        node->key     = key;
+        node->page    = page;
+        node->height  = 0;
+        node->left    = NULL;
+        node->right   = NULL;
+    }
+
+    return node;
+}
+
+
+static int
+get_balance_factor(
+    avl_node_t* tree
+    )
+{
+    int factor = 0;
+    if (tree) {
+        factor = HEIGHT(tree->right) - HEIGHT(tree->left);
+    }
+
+    return factor;
+}
+
+/*
+ * Left Rotation
+ *
+ *      A                      B
+ *       \                    / \
+ *        B         =>       A   C
+ *       /  \                 \
+ *      D    C                 D
+ *
+ */
+static avl_node_t*
+rotation_left(
+    avl_node_t* tree
+    )
+{
+    avl_node_t* rchild;
+    avl_node_t* lchild;
+
+    if (tree == NULL) return NULL;
+
+    rchild = tree->right;
+    if (rchild == NULL) {
+        return tree;
+    }
+
+    lchild = rchild->left;
+    rchild->left = tree;
+    tree->right = lchild;
+
+    tree->height   = MAX(HEIGHT(tree->left), HEIGHT(tree->right)) + 1;
+    rchild->height = MAX(HEIGHT(rchild->left), HEIGHT(rchild->right)) + 1;
+
+    return rchild;
+}
+
+
+/*
+ * Reft Rotation
+ *
+ *         A                  B
+ *       \                  /  \
+ *      B         =>       D    A
+ *    /  \                     /
+ *   D    C                   C
+ *
+ */
+static avl_node_t*
+rotation_right(
+    avl_node_t* tree
+    )
+{
+    avl_node_t* rchild;
+    avl_node_t* lchild;
+
+    if (tree == NULL) return NULL;
+
+    lchild = tree->left;
+    if (lchild == NULL) return NULL;
+
+    rchild = lchild->right;
+    lchild->right = tree;
+    tree->left = rchild;
+
+    tree->height   = MAX(HEIGHT(tree->left), HEIGHT(tree->right)) + 1;
+    lchild->height = MAX(HEIGHT(lchild->left), HEIGHT(lchild->right)) + 1;
+
+    return lchild;
+}
+
+static avl_node_t*
+do_balance(
+    avl_node_t* tree
+    )
+{
+    int bfactor = 0, child_bfactor;       /* balancing factor */
+
+    bfactor = get_balance_factor(tree);
+
+    if (bfactor >= 2) {
+        child_bfactor = get_balance_factor(tree->right);
+        if (child_bfactor == 1 || child_bfactor == 0) {
+            tree = rotation_left(tree);
+        } else if (child_bfactor == -1) {
+            tree->right = rotation_right(tree->right);
+            tree        = rotation_left(tree);
+        } else {
+            fprintf(stderr, "invalid balancing factor: %d\n", child_bfactor);
+            ASSERT(0);
+            return NULL;
+        }
+    } else if (bfactor <= -2) {
+        child_bfactor = get_balance_factor(tree->left);
+        if (child_bfactor == -1 || child_bfactor == 0) {
+            tree = rotation_right(tree);
+        } else if (child_bfactor == 1) {
+            tree->left = rotation_left(tree->left);
+            tree       = rotation_right(tree);
+        } else {
+            fprintf(stderr, "invalid balancing factor: %d\n", child_bfactor);
+            ASSERT(0);
+            return NULL;
+        }
+    }
+
+    return tree;
+}
+static avl_node_t*
+unlink_end_node(
+    avl_node_t* tree,
+    int dir,
+    avl_node_t** found_node
+    )
+{
+    *found_node = NULL;
+    if (tree == NULL) return NULL;
+
+    if (dir == LEFT) {
+        if (tree->left == NULL) {
+            *found_node = tree;
+            return NULL;
+        }
+    } else {
+        if (tree->right == NULL) {
+            *found_node = tree;
+            return NULL;
+        }
+    }
+
+    if (dir == LEFT) {
+        tree->left = unlink_end_node(tree->left, LEFT, found_node);
+        if (tree->left == NULL) {
+            tree->left = (*found_node)->right;
+            (*found_node)->left  = NULL;
+            (*found_node)->right = NULL;
+        }
+    } else {
+        tree->right = unlink_end_node(tree->right, RIGHT, found_node);
+        if (tree->right == NULL) {
+            tree->right = (*found_node)->left;
+            (*found_node)->left  = NULL;
+            (*found_node)->right = NULL;
+        }
+    }
+
+    tree->height = MAX(HEIGHT(tree->left), HEIGHT(tree->right)) + 1;
+
+    return do_balance(tree);
+}
+
+static avl_node_t*
+avltree_insert(
+    avl_node_t* tree,
+    vmem_key_t key,
+    page_t* page
+    )
+{
+    if (tree == NULL) {
+        tree = make_avl_node(key, page);
+    } else {
+        if (key >= tree->key) {
+            tree->right = avltree_insert(tree->right, key, page);
+        } else {
+            tree->left  = avltree_insert(tree->left, key, page);
+        }
+    }
+
+    tree = do_balance(tree);
+
+    tree->height = MAX(HEIGHT(tree->left), HEIGHT(tree->right)) + 1;
+
+    return tree;
+}
+
+static avl_node_t*
+do_unlink(
+    avl_node_t* tree
+    )
+{
+    avl_node_t* node;
+    avl_node_t* end_node;
+    node = unlink_end_node(tree->right, LEFT, &end_node);
+    if (node) {
+        tree->right = node;
+    } else {
+        node = unlink_end_node(tree->left, RIGHT, &end_node);
+        if (node) tree->left = node;
+    }
+
+    if (node == NULL) {
+        node = tree->right ? tree->right : tree->left;
+        end_node = node;
+    }
+
+    if (end_node) {
+        end_node->left  = (tree->left != end_node) ? tree->left : end_node->left;
+        end_node->right = (tree->right != end_node) ? tree->right : end_node->right;
+        end_node->height = MAX(HEIGHT(end_node->left), HEIGHT(end_node->right)) + 1;
+    }
+
+    tree = end_node;
+
+    return tree;
+}
+
+static avl_node_t*
+avltree_remove(
+    avl_node_t* tree,
+    avl_node_t** found_node,
+    vmem_key_t key
+    )
+{
+    *found_node = NULL;
+    if (tree == NULL) {
+        DPRINT("failed to find key %d\n", (int)key);
+        return NULL;
+    }
+
+    if (key == tree->key) {
+        *found_node = tree;
+        tree = do_unlink(tree);
+    } else if (key > tree->key) {
+        tree->right = avltree_remove(tree->right, found_node, key);
+    } else {
+        tree->left  = avltree_remove(tree->left, found_node, key);
+    }
+
+    if (tree) tree->height = MAX(HEIGHT(tree->left), HEIGHT(tree->right)) + 1;
+
+    tree = do_balance(tree);
+
+    return tree;
+}
+
+void
+avltree_free(
+    avl_node_t* tree
+    )
+{
+    if (tree == NULL) return;
+    if (tree->left == NULL && tree->right == NULL) {
+        P_FREE(tree);
+        return;
+    }
+
+    avltree_free(tree->left);
+    tree->left = NULL;
+    avltree_free(tree->right);
+    tree->right = NULL;
+    P_FREE(tree);
+}
+
+static avl_node_t*
+remove_approx_value(
+    avl_node_t* tree,
+    avl_node_t** found,
+    vmem_key_t key
+    )
+{
+    *found = NULL;
+    if (tree == NULL) {
+        return NULL;
+    }
+
+    if (key == tree->key) {
+        *found = tree;
+        tree = do_unlink(tree);
+    } else if (key > tree->key) {
+        tree->right = remove_approx_value(tree->right, found, key);
+    } else {
+        tree->left  = remove_approx_value(tree->left, found, key);
+        if (*found == NULL) {
+            *found = tree;
+            tree = do_unlink(tree);
+        }
+    }
+    if (tree) tree->height = MAX(HEIGHT(tree->left), HEIGHT(tree->right)) + 1;
+    tree = do_balance(tree);
+
+    return tree;
+}
+
+static void
+set_blocks_free(
+	jpeg_mm_t *mm,
+    int pageno,
+    int npages
+    )
+{
+    int last_pageno     = pageno + npages - 1;
+    int i;
+    page_t* page;
+    page_t* last_page;
+
+    ASSERT(npages);
+
+    if (last_pageno >= mm->num_pages) {
+        DPRINT("set_blocks_free: invalid last page number: %d\n", last_pageno);
+        ASSERT(0);
+        return;
+    }
+
+    for (i=pageno; i<=last_pageno; i++) {
+        mm->page_list[i].used         = 0;
+        mm->page_list[i].alloc_pages  = 0;
+        mm->page_list[i].first_pageno = -1;
+    }
+
+    page        = &mm->page_list[pageno];
+    page->alloc_pages = npages;
+    last_page   = &mm->page_list[last_pageno];
+    last_page->first_pageno = pageno;
+
+    mm->free_tree = avltree_insert(mm->free_tree, MAKE_KEY(npages, pageno), page);
+}
+
+static void
+set_blocks_alloc(
+	jpeg_mm_t *mm,
+    int pageno,
+    int npages
+    )
+{
+    int last_pageno     = pageno + npages - 1;
+    int i;
+    page_t* page;
+    page_t* last_page;
+
+    if (last_pageno >= mm->num_pages) {
+        DPRINT("set_blocks_free: invalid last page number: %d\n", last_pageno);
+        ASSERT(0);
+        return;
+    }
+
+    for (i=pageno; i<=last_pageno; i++) {
+        mm->page_list[i].used         = 1;
+        mm->page_list[i].alloc_pages  = 0;
+        mm->page_list[i].first_pageno = -1;
+    }
+
+    page        = &mm->page_list[pageno];
+    page->alloc_pages = npages;
+
+    last_page   = &mm->page_list[last_pageno];
+    last_page->first_pageno = pageno;
+
+    mm->alloc_tree = avltree_insert(mm->alloc_tree, MAKE_KEY(page->addr, 0), page);
+}
+
+
+int
+jmem_init(
+	jpeg_mm_t* mm,
+	unsigned long addr,
+    unsigned long size
+    )
+{
+    int i;
+
+
+    mm->base_addr  = (addr+(VMEM_PAGE_SIZE-1))&~(VMEM_PAGE_SIZE-1);
+    mm->mem_size   = size&~VMEM_PAGE_SIZE;
+    mm->num_pages  = mm->mem_size/VMEM_PAGE_SIZE;
+    mm->page_list  = (page_t*)P_ALLOC(mm->num_pages*sizeof(page_t));
+    mm->free_tree  = NULL;
+    mm->alloc_tree = NULL;
+    mm->free_page_count = mm->num_pages;
+    mm->alloc_page_count = 0;
+
+    for (i=0; i<mm->num_pages; i++) {
+        mm->page_list[i].pageno       = i;
+        mm->page_list[i].addr         = mm->base_addr + i*VMEM_PAGE_SIZE;
+        mm->page_list[i].alloc_pages  = 0;
+        mm->page_list[i].used         = 0;
+        mm->page_list[i].first_pageno = -1;
+    }
+
+    set_blocks_free(mm, 0, mm->num_pages);
+
+    return 0;
+}
+
+int
+jmem_exit(
+	jpeg_mm_t* mm
+    )
+{
+	if (mm == NULL) {
+        DPRINT("vmem_exit: invalid handle\n");
+        return -1;
+    }
+
+    if (mm->free_tree) {
+        avltree_free(mm->free_tree);
+        mm->free_tree = NULL;
+    }
+    if (mm->alloc_tree) {
+        avltree_free(mm->alloc_tree);
+        mm->alloc_tree = NULL;
+    }
+
+    if (mm->page_list) {
+        P_FREE(mm->page_list);
+        mm->page_list = NULL;
+    }
+
+    return 0;
+}
+
+unsigned long
+jmem_alloc(
+	jpeg_mm_t* mm,
+    int size,
+	unsigned long pid
+    )
+{
+    avl_node_t* node;
+    page_t*     free_page;
+    int         npages, free_size;
+    int         alloc_pageno;
+    unsigned long  ptr;
+
+	if (mm == NULL) {
+		printf("%s:%d: invalid handle\n", __FUNCTION__, __LINE__);
+        return (unsigned long)-1;
+    }
+
+    if (size <= 0) return (unsigned long)-1;
+
+	npages = (size + VMEM_PAGE_SIZE -1)/VMEM_PAGE_SIZE;
+
+    mm->free_tree = remove_approx_value(mm->free_tree, &node, MAKE_KEY(npages, 0));
+    if (node == NULL) {
+        printf("%s:%d: Not found node?\n", __FUNCTION__, __LINE__);
+        return (unsigned long)-1;
+    }
+    free_page = node->page;
+    free_size = KEY_TO_VALUE(node->key);
+
+    alloc_pageno = free_page->pageno;
+    set_blocks_alloc(mm, alloc_pageno, npages);
+    if (npages != free_size) {
+        int free_pageno = alloc_pageno + npages;
+        set_blocks_free(mm, free_pageno, (free_size-npages));
+    }
+
+    P_FREE(node);
+
+    ptr = mm->page_list[alloc_pageno].addr;
+    mm->alloc_page_count += npages;
+    mm->free_page_count  -= npages;
+
+
+    return ptr;
+}
+
+int
+jmem_free(
+	jpeg_mm_t* mm,
+    unsigned long ptr,
+	unsigned long pid
+    )
+{
+    unsigned long addr;
+    avl_node_t* found;
+    page_t* page;
+    int pageno, prev_free_pageno, next_free_pageno;
+    int prev_size, next_size;
+    int merge_page_no, merge_page_size, free_page_size;
+
+
+	if (mm == NULL) {
+		DPRINT("vmem_free: invalid handle\n");
+		return -1;
+	}
+
+    addr = ptr;
+
+    mm->alloc_tree = avltree_remove(mm->alloc_tree, &found, MAKE_KEY(addr, 0));
+    if (found == NULL) {
+        DPRINT("vmem_free: 0x%08x not found\n", addr);
+        return -1;
+    }
+
+    /* find previous free block */
+    page = found->page;
+    pageno = page->pageno;
+    free_page_size = page->alloc_pages;
+    prev_free_pageno = pageno-1;
+    prev_size = -1;
+    if (prev_free_pageno >= 0) {
+        if (mm->page_list[prev_free_pageno].used == 0) {
+            prev_free_pageno = mm->page_list[prev_free_pageno].first_pageno;
+            prev_size = mm->page_list[prev_free_pageno].alloc_pages;
+        }
+    }
+
+    /* find next free block */
+    next_free_pageno = pageno + page->alloc_pages;
+    next_free_pageno = (next_free_pageno == mm->num_pages) ? -1 : next_free_pageno;
+    next_size = -1;
+    if (next_free_pageno >= 0) {
+        if (mm->page_list[next_free_pageno].used == 0) {
+            next_size = mm->page_list[next_free_pageno].alloc_pages;
+        }
+    }
+    P_FREE(found);
+
+    /* merge */
+    merge_page_no = page->pageno;
+    merge_page_size = page->alloc_pages;
+    if (prev_size >= 0) {
+        mm->free_tree = avltree_remove(mm->free_tree, &found, MAKE_KEY(prev_size, prev_free_pageno));
+        if (found == NULL) {
+            ASSERT(0);
+            return -1;
+        }
+        merge_page_no = found->page->pageno;
+        merge_page_size += found->page->alloc_pages;
+        P_FREE(found);
+    }
+    if (next_size >= 0) {
+        mm->free_tree = avltree_remove(mm->free_tree, &found, MAKE_KEY(next_size, next_free_pageno));
+        if (found == NULL) {
+            ASSERT(0);
+            return -1;
+        }
+        merge_page_size += found->page->alloc_pages;
+        P_FREE(found);
+    }
+
+    page->alloc_pages  = 0;
+    page->first_pageno = -1;
+
+    set_blocks_free(mm, merge_page_no, merge_page_size);
+
+    mm->alloc_page_count -= free_page_size;
+    mm->free_page_count  += free_page_size;
+
+    DPRINT("FREE: total(%d) alloc(%d) free(%d)\n", mm->num_pages, mm->alloc_page_count, mm->free_page_count);
+
+    return 0;
+}
+
+int
+jmem_get_info(
+	jpeg_mm_t* mm,
+    jmem_info_t* info
+    )
+{
+	if (mm == NULL) {
+		DPRINT("vmem_get_info: invalid handle\n");
+		return -1;
+	}
+
+    if (info == NULL) {
+        return -1;
+    }
+
+    info->total_pages = mm->num_pages;
+    info->alloc_pages = mm->alloc_page_count;
+    info->free_pages  = mm->free_page_count;
+    info->page_size   = VMEM_PAGE_SIZE;
+
+    return 0;
+}
+
+
+

+ 123 - 0
soft_3rdpart/codaj12/jdi/mm.h

@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2018, Chips&Media
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __CNM_VIDEO_MEMORY_MANAGEMENT_H__
+#define __CNM_VIDEO_MEMORY_MANAGEMENT_H__
+
+
+typedef struct _jmem_info_struct {
+	unsigned long   total_pages;
+	unsigned long   alloc_pages;
+	unsigned long   free_pages;
+    unsigned long   page_size;
+} jmem_info_t;
+
+#if defined(WIN32) || defined(WIN64)
+#if (_MSC_VER == 1200)
+typedef _int64              vmem_key_t;
+#else
+typedef unsigned long long  vmem_key_t;
+#endif
+#else
+typedef unsigned long long  vmem_key_t;
+#endif
+
+#define VMEM_PAGE_SIZE           (16*1024UL)
+
+#define MAKE_KEY(_a, _b)        (((vmem_key_t)_a)<<32 | _b)
+#define KEY_TO_VALUE(_key)      (_key>>32)
+
+typedef struct page_struct {
+	int             pageno;
+	unsigned long   addr;
+	int             used;
+	int             alloc_pages;
+	int             first_pageno;
+} page_t;
+
+
+typedef struct avl_node_struct {
+	vmem_key_t   key;
+	int     height;
+	page_t* page;
+	struct avl_node_struct* left;
+	struct avl_node_struct* right;
+} avl_node_t;
+
+
+typedef struct _jpeg_mm_struct {
+	avl_node_t*     free_tree;
+	avl_node_t*     alloc_tree;
+	page_t*         page_list;
+	int             num_pages;
+	unsigned long   base_addr;
+	unsigned long   mem_size;
+	void*           mutex;
+	int             free_page_count;
+	int             alloc_page_count;
+} jpeg_mm_t;
+
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
+extern int
+jmem_init(
+	jpeg_mm_t* mm,
+	unsigned long addr,
+	unsigned long size
+	);
+
+extern int
+jmem_exit(
+	jpeg_mm_t* mm
+	);
+
+extern unsigned long
+jmem_alloc(
+	jpeg_mm_t* mm,
+	int size,
+	unsigned long pid
+	);
+
+extern int
+jmem_free(
+	jpeg_mm_t* mm,
+	unsigned long ptr,
+	unsigned long pid
+	);
+
+
+extern int
+jmem_get_info(
+	jpeg_mm_t* mm,
+	jmem_info_t* info
+	);
+
+#if defined (__cplusplus)
+}
+#endif
+#endif /* __CNM_VIDEO_MEMORY_MANAGEMENT_H__ */
+

+ 853 - 0
soft_3rdpart/codaj12/jdi/nonos/jdi.c

@@ -0,0 +1,853 @@
+/*
+ * Copyright (c) 2018, Chips&Media
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#if defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WIN32) || defined(__MINGW32__)
+#elif defined(linux) || defined(__linux) || defined(ANDROID)
+#else
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../jdi.h"
+#include "jpulog.h"
+
+
+#define JPU_BIT_REG_SIZE		0x300
+#define JPU_BIT_REG_BASE		(0x10000000 + 0x3000)
+
+#define JDI_DRAM_PHYSICAL_BASE	0x00
+#define JDI_DRAM_PHYSICAL_SIZE	(128*1024*1024)
+#define JDI_SYSTEM_ENDIAN	JDI_LITTLE_ENDIAN
+
+typedef struct jpu_buffer_t jpudrv_buffer_t;
+
+typedef struct jpu_buffer_pool_t
+{
+	jpudrv_buffer_t jdb;
+	int inuse;
+} jpu_buffer_pool_t;
+
+static int s_jpu_fd;
+static jpu_instance_pool_t *s_pjip;
+static jpu_instance_pool_t s_jip;
+static int s_task_num;
+static int s_clock_state;
+static jpudrv_buffer_t s_jdb_video_memory;
+static jpudrv_buffer_t s_jdb_register;
+static jpu_buffer_pool_t s_jpu_buffer_pool[MAX_JPU_BUFFER_POOL];
+static int s_jpu_buffer_pool_count;
+
+static Int32 swap_endian(BYTE* data, Uint32 len, Uint32 endian);
+
+int jdi_probe()
+{
+	int ret;
+
+	ret = jdi_init();
+	jdi_release();
+
+	return ret;
+}
+
+/* @return number of task
+ */
+int jdi_get_task_num()
+{
+    if (s_jpu_fd == -1 || s_jpu_fd == 0x00) {
+        return 0;
+    }
+
+    return s_task_num;
+}
+
+
+int jdi_init()
+{
+	int ret;
+
+	if (s_jpu_fd != -1 && s_jpu_fd != 0x00)
+	{
+		s_task_num++;
+		return 0;
+	}
+
+    s_jpu_fd = 1;
+
+	memset((void *)&s_jpu_buffer_pool, 0x00, sizeof(jpu_buffer_pool_t)*MAX_JPU_BUFFER_POOL);
+	s_jpu_buffer_pool_count = 0;
+
+	if (!(s_pjip = jdi_get_instance_pool()))
+	{
+		JLOG(ERR, "[jdi] fail to create instance pool for saving context \n");
+		goto ERR_JDI_INIT;
+	}
+
+
+	s_jdb_video_memory.phys_addr = JDI_DRAM_PHYSICAL_BASE;
+	s_jdb_video_memory.size = JDI_DRAM_PHYSICAL_SIZE;
+
+	if (!s_pjip->instance_pool_inited)
+	{
+		memset(&s_pjip->vmem, 0x00, sizeof(jpeg_mm_t));
+		ret = jmem_init(&s_pjip->vmem, (unsigned long)s_jdb_video_memory.phys_addr, s_jdb_video_memory.size);
+		if (ret < 0)
+		{
+			JLOG(ERR, "[JDI] fail to init jpu memory management logic\n");
+			goto ERR_JDI_INIT;
+		}
+	}
+
+	s_jdb_register.phys_addr = JPU_BIT_REG_BASE;
+	s_jdb_register.virt_addr = JPU_BIT_REG_BASE;
+	s_jdb_register.size = JPU_BIT_REG_SIZE;
+
+
+	jdi_set_clock_gate(1);
+
+	s_task_num++;
+
+	JLOG(INFO, "[jdi] success to init driver \n");
+	return s_jpu_fd;
+
+ERR_JDI_INIT:
+
+	jdi_release();
+	return -1;
+}
+
+int jdi_release()
+{
+
+	if (s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return 0;
+
+	if (jdi_lock() < 0)
+	{
+		JLOG(ERR, "[jdi] fail to handle lock function\n");
+		return -1;
+	}
+
+	if (s_task_num > 1) // means that the opened instance remains
+	{
+		s_task_num--;
+		jdi_unlock();
+		return 0;
+	}
+
+	s_task_num--;
+
+	memset(&s_jdb_register, 0x00, sizeof(jpudrv_buffer_t));
+
+	if (s_jpu_fd != -1 && s_jpu_fd != 0x00)
+		s_jpu_fd = -1;
+
+	s_pjip = NULL;
+
+	jdi_unlock();
+
+
+	return 0;
+}
+
+
+jpu_instance_pool_t *jdi_get_instance_pool()
+{
+	if (!s_pjip)
+	{
+		s_pjip = &s_jip;
+
+		memset(s_pjip, 0x00, sizeof(jpu_instance_pool_t));
+	}
+
+	return (jpu_instance_pool_t *)s_pjip;
+}
+
+int jdi_open_instance(unsigned long instIdx)
+{
+	if(!s_pjip || s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return -1;
+
+	s_pjip->jpu_instance_num++;
+
+	return 0;
+}
+
+int jdi_close_instance(unsigned long instIdx)
+{
+	if(!s_pjip || s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return -1;
+
+	s_pjip->jpu_instance_num--;
+
+	return 0;
+}
+
+
+int jdi_get_instance_num()
+{
+	if(!s_pjip || s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return -1;
+
+	return s_pjip->jpu_instance_num;
+}
+
+int jdi_hw_reset()
+{
+	if(!s_pjip || s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return -1;
+
+	// to do any action for hw reset
+
+	return 0;
+}
+
+
+
+int jdi_lock()
+{
+
+	return 0;
+}
+void jdi_unlock()
+{
+
+}
+
+void jdi_write_register(unsigned long addr, unsigned int data)
+{
+	unsigned long *reg_addr;
+
+	if(!s_pjip || s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return;
+
+	reg_addr = (unsigned long *)(addr + (unsigned long)s_jdb_register.virt_addr);
+	//*(volatile unsigned long *)reg_addr = data;
+	*(volatile unsigned int *)reg_addr = data;
+
+}
+
+unsigned long jdi_read_register(unsigned long addr)
+{
+	unsigned long *reg_addr;
+
+	reg_addr = (unsigned long *)(addr + (unsigned long)s_jdb_register.virt_addr);
+	//return *(volatile unsigned long *)reg_addr;
+	return *(volatile unsigned int *)reg_addr;
+}
+
+int jdi_write_memory(unsigned long addr, unsigned char *data, int len, int endian)
+{
+	jpudrv_buffer_t jdb = {0, };
+	unsigned long offset;
+	int i;
+
+
+	if(!s_pjip || s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return -1;
+
+	for (i=0; i<MAX_JPU_BUFFER_POOL; i++)
+	{
+		if (s_jpu_buffer_pool[i].inuse == 1)
+		{
+			jdb = s_jpu_buffer_pool[i].jdb;
+			if (addr >= jdb.phys_addr && addr < (jdb.phys_addr + jdb.size))
+				break;
+		}
+	}
+
+	if (!jdb.size) {
+		JLOG(ERR, "address 0x%08x is not mapped address!!!\n", addr);
+		return -1;
+	}
+
+	offset = addr - (unsigned long)jdb.phys_addr;
+
+
+	swap_endian(data, len, endian);
+
+	memcpy((void *)((unsigned long)jdb.virt_addr+offset), data, len);
+
+	return len;
+}
+
+int jdi_read_memory(unsigned long addr, unsigned char *data, int len, int endian)
+{
+	jpudrv_buffer_t jdb = {0};
+	unsigned long offset;
+	int i;
+
+	if(!s_pjip || s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return -1;
+
+	for (i=0; i<MAX_JPU_BUFFER_POOL; i++)
+	{
+		if (s_jpu_buffer_pool[i].inuse == 1)
+		{
+			jdb = s_jpu_buffer_pool[i].jdb;
+			if (addr >= jdb.phys_addr && addr < (jdb.phys_addr + jdb.size))
+				break;
+		}
+	}
+
+	if (!jdb.size)
+		return -1;
+
+
+	offset = addr - (unsigned long)jdb.phys_addr;
+
+
+
+	memcpy(data, (const void *)((unsigned long)jdb.virt_addr+offset), len);
+	swap_endian(data, (Uint32)len,  (Uint32)endian);
+
+	return len;
+}
+
+int jdi_allocate_dma_memory(jpu_buffer_t *vb)
+{
+	int i;
+	unsigned long offset;
+	jpudrv_buffer_t jdb = {0, };
+
+	if(!s_pjip || s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return -1;
+
+	jdb.size = vb->size;
+	jdb.phys_addr = (unsigned long)jmem_alloc(&s_pjip->vmem, jdb.size, 0);
+
+	if (jdb.phys_addr == (unsigned long)-1)
+		return -1; // not enough memory
+
+
+	offset = (unsigned long)(jdb.phys_addr - s_jdb_video_memory.phys_addr);
+	jdb.base = (unsigned long )s_jdb_video_memory.base + offset;
+	jdb.virt_addr = jdb.phys_addr;
+
+	vb->phys_addr = (unsigned long)jdb.phys_addr;
+	vb->base = (unsigned long)jdb.base;
+	vb->virt_addr = (unsigned long)vb->phys_addr;
+
+
+	for (i=0; i<MAX_JPU_BUFFER_POOL; i++)
+	{
+		if (s_jpu_buffer_pool[i].inuse == 0)
+		{
+			s_jpu_buffer_pool[i].jdb = jdb;
+			s_jpu_buffer_pool_count++;
+			s_jpu_buffer_pool[i].inuse = 1;
+			break;
+		}
+	}
+
+	return 0;
+}
+
+void jdi_free_dma_memory(jpu_buffer_t *vb)
+{
+	int i;
+	jpudrv_buffer_t jdb = {0, };
+
+
+	if(!s_pjip || s_jpu_fd == -1 || s_jpu_fd == 0x00)
+		return ;
+
+	if (vb->size == 0)
+		return ;
+
+
+
+	for (i=0; i<MAX_JPU_BUFFER_POOL; i++)
+	{
+		if (s_jpu_buffer_pool[i].jdb.phys_addr == vb->phys_addr)
+		{
+			s_jpu_buffer_pool[i].inuse = 0;
+			s_jpu_buffer_pool_count--;
+			jdb = s_jpu_buffer_pool[i].jdb;
+			break;
+		}
+	}
+
+	if (!jdb.size)
+	{
+		JLOG(ERR, "[JDI] invalid buffer to free address = 0x%x\n", (int)jdb.virt_addr);
+		return ;
+	}
+
+	jmem_free(&s_pjip->vmem, (unsigned long)jdb.phys_addr, 0);
+	memset(vb, 0, sizeof(jpu_buffer_t));
+}
+
+
+int jdi_set_clock_gate(int enable)
+{
+	s_clock_state = enable;
+    return 0;
+}
+
+
+int jdi_get_clock_gate()
+{
+
+	return s_clock_state;
+}
+
+int jdi_wait_inst_ctrl_busy(int timeout, unsigned int addr_flag_reg, unsigned int flag)
+{
+	unsigned int data_flag_reg;
+
+	JLOG(ERR, "<%s:%d> Need to implement counter\n", __FUNCTION__, __LINE__);
+
+	while(1)
+	{
+		data_flag_reg = jdi_read_register(addr_flag_reg);
+
+		if (((data_flag_reg >> 4)&0xf) == flag) {
+			break;
+		}
+
+		//if (timeout > 0 && (cur - elapse) > timeout) {
+		//	JLOG(ERR, "[jDI] jdi_wait_inst_ctrl_busy timeout, 0x%x=0x%lx\n", addr_flag_reg, jdi_read_register(addr_flag_reg));
+		//	return -1;
+		//}
+	}
+	return 0;
+}
+
+int jdi_wait_interrupt(int timeout, unsigned int addr_int_reason, unsigned long instIdx)
+{
+	//int count = 0;
+
+	while(1)
+	{
+		if (jdi_read_register(addr_int_reason))
+			break;
+
+		//Sleep(1);	// 1ms sec
+		//if (count++ > timeout)
+		//	return -1;
+	}
+
+	return 0;
+}
+
+void jdi_log(int cmd, int step, int inst)
+{
+	int i;
+
+	switch(cmd)
+	{
+	case JDI_LOG_CMD_PICRUN:
+		if (step == 1)	//
+			JLOG(INFO, "\n**PIC_RUN start\n");
+		else
+			JLOG(INFO, "\n**PIC_RUN end \n");
+		break;
+	}
+
+	for (i=0; i<=0x238; i=i+16)
+	{
+		JLOG(INFO, "0x%04xh: 0x%08x 0x%08x 0x%08x 0x%08x\n", i,
+			jdi_read_register(i), jdi_read_register(i+4),
+			jdi_read_register(i+8), jdi_read_register(i+0xc));
+	}
+}
+
+static void SwapByte(Uint8* data, Uint32 len)
+{
+    Uint8   temp;
+    Uint32  i;
+
+    for (i=0; i<len; i+=2) {
+        temp      = data[i];
+        data[i]   = data[i+1];
+        data[i+1] = temp;
+    }
+}
+
+static void SwapWord(Uint8* data, Uint32 len)
+{
+    Uint16  temp;
+    Uint16* ptr = (Uint16*)data;
+    Int32   i, size = len/sizeof(Uint16);
+
+    for (i=0; i<size; i+=2) {
+        temp      = ptr[i];
+        ptr[i]   = ptr[i+1];
+        ptr[i+1] = temp;
+    }
+}
+
+static void SwapDword(Uint8* data, Uint32 len)
+{
+    Uint32  temp;
+    Uint32* ptr = (Uint32*)data;
+    Int32   i, size = len/sizeof(Uint32);
+
+    for (i=0; i<size; i+=2) {
+        temp      = ptr[i];
+        ptr[i]   = ptr[i+1];
+        ptr[i+1] = temp;
+    }
+}
+
+
+static Int32 swap_endian(BYTE* data, Uint32 len, Uint32 endian)
+{
+    Uint8   endianMask[8] = {   // endianMask : [2] - 4byte unit swap
+        0x00, 0x07, 0x04, 0x03, //              [1] - 2byte unit swap
+        0x06, 0x05, 0x02, 0x01  //              [0] - 1byte unit swap
+    };
+    Uint8   targetEndian;
+    Uint8   systemEndian;
+    Uint8   changes;
+    BOOL    byteSwap=FALSE, wordSwap=FALSE, dwordSwap=FALSE;
+
+    if (endian > 7) {
+        JLOG(ERR, "Invalid endian mode: %d, expected value: 0~7\n", endian);
+        return -1;
+    }
+
+    targetEndian = endianMask[endian];
+    systemEndian = endianMask[JDI_SYSTEM_ENDIAN];
+    changes      = targetEndian ^ systemEndian;
+    byteSwap     = changes & 0x01 ? TRUE : FALSE;
+    wordSwap     = changes & 0x02 ? TRUE : FALSE;
+    dwordSwap    = changes & 0x04 ? TRUE : FALSE;
+
+    if (byteSwap == TRUE)  SwapByte(data, len);
+    if (wordSwap == TRUE)  SwapWord(data, len);
+    if (dwordSwap == TRUE) SwapDword(data, len);
+
+    return changes == 0 ? 0 : 1;
+}
+
+
+
+int kbhit(void)
+{
+	return 0;
+}
+int  getch(void)
+{
+	return -1;
+}
+
+
+/*
+* newlib_stubs.c
+* the bellow code is just to build ref-code. customers will removed the bellow code because they need a library which is related to the system library such as newlibc
+*/
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/times.h>
+#include <sys/unistd.h>
+
+
+#ifndef STDOUT_USART
+#define STDOUT_USART 0
+#endif
+
+#ifndef STDERR_USART
+#define STDERR_USART 0
+#endif
+
+#ifndef STDIN_USART
+#define STDIN_USART 0
+#endif
+
+#undef errno
+extern int errno;
+
+/*
+environ
+A pointer to a list of environment variables and their values.
+For a minimal environment, this empty list is adequate:
+*/
+char *__env[1] = { 0 };
+char **environ = __env;
+
+int _write(int file, char *ptr, int len);
+
+void _exit(int status) {
+	_write(1, "exit", 4);
+	while (1) {
+		;
+	}
+}
+
+int _open(int file) {
+		return -1;
+}
+int _close(int file) {
+	return -1;
+}
+/*
+execve
+Transfer control to a new process. Minimal implementation (for a system without processes):
+*/
+int _execve(char *name, char **argv, char **env) {
+	errno = ENOMEM;
+	return -1;
+}
+/*
+fork
+Create a new process. Minimal implementation (for a system without processes):
+*/
+
+int _fork() {
+	errno = EAGAIN;
+	return -1;
+}
+/*
+fstat
+Status of an open file. For consistency with other minimal implementations in these examples,
+all files are regarded as character special devices.
+The `sys/stat.h' header file required is distributed in the `include' subdirectory for this C library.
+*/
+int _fstat(int file, struct stat *st) {
+	st->st_mode = S_IFCHR;
+	return 0;
+}
+
+/*
+getpid
+Process-ID; this is sometimes used to generate strings unlikely to conflict with other processes. Minimal implementation, for a system without processes:
+*/
+
+int _getpid() {
+	return 1;
+}
+
+/*
+isatty
+Query whether output stream is a terminal. For consistency with the other minimal implementations,
+*/
+int _isatty(int file) {
+	switch (file){
+	case STDOUT_FILENO:
+	case STDERR_FILENO:
+	case STDIN_FILENO:
+		return 1;
+	default:
+		//errno = ENOTTY;
+		errno = EBADF;
+		return 0;
+	}
+}
+
+
+/*
+kill
+Send a signal. Minimal implementation:
+*/
+int _kill(int pid, int sig) {
+	errno = EINVAL;
+	return (-1);
+}
+
+/*
+link
+Establish a new name for an existing file. Minimal implementation:
+*/
+
+int _link(char *old, char *new) {
+	errno = EMLINK;
+	return -1;
+}
+
+/*
+lseek
+Set position in a file. Minimal implementation:
+*/
+int _lseek(int file, int ptr, int dir) {
+	return 0;
+}
+
+static char* __get_MSP(void)
+{
+	JLOG(ERR, "<%s:%d> Need to implement it\n", __FUNCTION__, __LINE__);
+	return NULL;
+}
+
+/*
+sbrk
+Increase program data space.
+Malloc and related functions depend on this
+*/
+caddr_t _sbrk(int incr) {
+
+	// extern char _ebss; // Defined by the linker
+	char _ebss;
+	static char *heap_end;
+	char *prev_heap_end;
+
+	JLOG(ERR, "<%s:%d> check _ebss to implement it\n", __FUNCTION__, __LINE__);
+	if (heap_end == 0) {
+		heap_end = &_ebss;
+	}
+	prev_heap_end = heap_end;
+
+	char * stack = (char*) __get_MSP();
+	if (heap_end + incr >  stack)
+	{
+		_write (STDERR_FILENO, "Heap and stack collision\n", 25);
+		errno = ENOMEM;
+		return  (caddr_t) -1;
+		//abort ();
+	}
+
+	heap_end += incr;
+	return (caddr_t) prev_heap_end;
+
+}
+
+/*
+read
+Read a character to a file. `libc' subroutines will use this system routine for input from all files, including stdin
+Returns -1 on error or blocks until the number of characters have been read.
+*/
+
+
+int _read(int file, char *ptr, int len) {
+	int n;
+	int num = 0;
+	switch (file) {
+	case STDIN_FILENO:
+		for (n = 0; n < len; n++) {
+			char c=0;
+#if   STDIN_USART == 1
+			while ((USART1->SR & USART_FLAG_RXNE) == (uint16_t)RESET) {}
+			c = (char)(USART1->DR & (uint16_t)0x01FF);
+#elif STDIN_USART == 2
+			while ((USART2->SR & USART_FLAG_RXNE) == (uint16_t) RESET) {}
+			c = (char) (USART2->DR & (uint16_t) 0x01FF);
+#elif STDIN_USART == 3
+			while ((USART3->SR & USART_FLAG_RXNE) == (uint16_t)RESET) {}
+			c = (char)(USART3->DR & (uint16_t)0x01FF);
+#endif
+			*ptr++ = c;
+			num++;
+		}
+		break;
+	default:
+		errno = EBADF;
+		return -1;
+	}
+	return num;
+}
+
+/*
+stat
+Status of a file (by name). Minimal implementation:
+int    _EXFUN(stat,( const char *__path, struct stat *__sbuf ));
+*/
+
+int _stat(const char *filepath, struct stat *st) {
+	st->st_mode = S_IFCHR;
+	return 0;
+}
+
+/*
+times
+Timing information for current process. Minimal implementation:
+*/
+
+clock_t _times(struct tms *buf) {
+	return -1;
+}
+
+/*
+unlink
+Remove a file's directory entry. Minimal implementation:
+*/
+int _unlink(char *name) {
+	errno = ENOENT;
+	return -1;
+}
+
+/*
+wait
+Wait for a child process. Minimal implementation:
+*/
+int _wait(int *status) {
+	errno = ECHILD;
+	return -1;
+}
+
+/*
+write
+Write a character to a file. `libc' subroutines will use this system routine for output to all files, including stdout
+Returns -1 on error or number of bytes sent
+*/
+int _write(int file, char *ptr, int len) {
+	int n;
+	switch (file) {
+	case STDOUT_FILENO: /*stdout*/
+		for (n = 0; n < len; n++) {
+#if STDOUT_USART == 1
+			while ((USART1->SR & USART_FLAG_TC) == (uint16_t)RESET) {}
+			USART1->DR = (*ptr++ & (uint16_t)0x01FF);
+#elif  STDOUT_USART == 2
+			while ((USART2->SR & USART_FLAG_TC) == (uint16_t) RESET) {
+			}
+			USART2->DR = (*ptr++ & (uint16_t) 0x01FF);
+#elif  STDOUT_USART == 3
+			while ((USART3->SR & USART_FLAG_TC) == (uint16_t)RESET) {}
+			USART3->DR = (*ptr++ & (uint16_t)0x01FF);
+#endif
+		}
+		break;
+	case STDERR_FILENO: /* stderr */
+		for (n = 0; n < len; n++) {
+#if STDERR_USART == 1
+			while ((USART1->SR & USART_FLAG_TC) == (uint16_t)RESET) {}
+			USART1->DR = (*ptr++ & (uint16_t)0x01FF);
+#elif  STDERR_USART == 2
+			while ((USART2->SR & USART_FLAG_TC) == (uint16_t) RESET) {
+			}
+			USART2->DR = (*ptr++ & (uint16_t) 0x01FF);
+#elif  STDERR_USART == 3
+			while ((USART3->SR & USART_FLAG_TC) == (uint16_t)RESET) {}
+			USART3->DR = (*ptr++ & (uint16_t)0x01FF);
+#endif
+		}
+		break;
+	default:
+		errno = EBADF;
+		return -1;
+	}
+	return len;
+}
+
+int _gettimeofday( struct timeval *tv, void *tzvp )
+{
+    Uint64 t = 0;//__your_system_time_function_here__();  // get uptime in nanoseconds
+    tv->tv_sec = t / 1000000000;  // convert to seconds
+    tv->tv_usec = ( t % 1000000000 ) / 1000;  // get remaining microseconds
+
+    JLOG(WARN, "<%s:%d> NEED TO IMPLEMENT %s\n", __FUNCTION__, __LINE__, __FUNCTION__);
+    return 0;
+}
+
+
+#endif

+ 39 - 0
soft_3rdpart/codaj12/jpuapi/Android.mk

@@ -0,0 +1,39 @@
+LOCAL_PATH := $(call my-dir)
+
+# Building the vpuapi
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ 	jpuapi.c \
+	jpuapifunc.c \
+	../src/jpuhelper.c \
+	../src/jpulog.c
+
+ LOCAL_SRC_FILES += \
+	../jdi/linux/jdi.c \
+
+
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE := libjpu
+
+# LOCAL_CFLAGS +=  -DCNM_FPGA_PLATFORM
+
+
+LOCAL_SHARED_LIBRARIES :=       \
+		libutils		\
+		libcutils		\
+		libdl  			\
+		libdvm			\
+		liblog
+
+							
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src		\
+					$(TOP)/hardware/jpu	\
+					$(TOP)/hardware/jpu/include		\
+							
+
+					
+
+include $(BUILD_SHARED_LIBRARY)
+

+ 1804 - 0
soft_3rdpart/codaj12/jpuapi/jpuapi.c

@@ -0,0 +1,1804 @@
+/*
+ * Copyright (c) 2018, Chips&Media
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "jpuapifunc.h"
+#include "jpuapi.h"
+#include "regdefine.h"
+#include "jpulog.h"
+
+static JPUCap   g_JpuAttributes;
+
+int JPU_IsBusy(JpgHandle handle)
+{
+    Uint32 val;
+    JpgInst *pJpgInst = (JpgInst *)handle;
+    Int32 instRegIndex;
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+    val = JpuReadInstReg(instRegIndex, MJPEG_PIC_STATUS_REG);
+
+    if ((val & (1<<INT_JPU_DONE)) ||
+        (val & (1<<INT_JPU_ERROR)))
+        return 0;
+
+    return 1;
+}
+
+void JPU_ClrStatus(JpgHandle handle, Uint32 val)
+{
+    JpgInst *pJpgInst = (JpgInst *)handle;
+    Int32 instRegIndex;
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+    if (val != 0)
+        JpuWriteInstReg(instRegIndex, MJPEG_PIC_STATUS_REG, val);
+}
+Uint32 JPU_GetStatus(JpgHandle handle)
+{
+    JpgInst *pJpgInst = (JpgInst *)handle;
+    Int32 instRegIndex;
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+
+    return JpuReadInstReg(instRegIndex, MJPEG_PIC_STATUS_REG);
+}
+
+
+Uint32 JPU_IsInit()
+{
+    jpu_instance_pool_t *pjip;
+
+    pjip = (jpu_instance_pool_t *)jdi_get_instance_pool();
+
+    if (!pjip)
+        return 0;
+
+    return 1;
+}
+
+
+Int32	JPU_WaitInterrupt(JpgHandle handle, int timeout)
+{
+    Uint32 val;
+    Uint32 instPicStatusRegAddr;
+    Int32 instRegIndex;
+
+    Int32 reason = 0;
+
+    JpgInst *pJpgInst = (JpgInst *)handle;
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+
+    instPicStatusRegAddr = ((instRegIndex*NPT_REG_SIZE) + MJPEG_PIC_STATUS_REG);
+
+    reason = jdi_wait_interrupt(timeout, instPicStatusRegAddr, instRegIndex);
+    if (reason == -1)
+        return -1;
+
+    if (reason & (1<<INT_JPU_DONE) || reason & (1<<INT_JPU_SLICE_DONE)) {
+        val = JpuReadReg(MJPEG_INST_CTRL_STATUS_REG);
+        if ((((val & 0xf) >> instRegIndex) & 0x01) == 0) {
+            return -2;
+        }
+    }
+
+    return reason;
+}
+
+
+
+int JPU_GetOpenInstanceNum()
+{
+    jpu_instance_pool_t *pjip;
+
+    pjip = (jpu_instance_pool_t *)jdi_get_instance_pool();
+    if (!pjip)
+        return -1;
+
+    return pjip->jpu_instance_num;
+}
+
+JpgRet JPU_Init()
+{
+    jpu_instance_pool_t *pjip;
+    Uint32              val;
+
+    if (jdi_init() < 0) {
+        return JPG_RET_FAILURE;
+    }
+
+    if (jdi_get_task_num() > 1) {
+        return JPG_RET_CALLED_BEFORE;
+    }
+
+    JpgEnterLock();
+    pjip = (jpu_instance_pool_t *)jdi_get_instance_pool();
+    if (!pjip) {
+        JpgLeaveLock();
+        return JPG_RET_FAILURE;
+    }
+
+    //jdi_log(JDI_LOG_CMD_INIT, 1, 0);
+    JPU_SWReset(NULL);
+    JpuWriteReg(MJPEG_INST_CTRL_START_REG, (1<<0));
+
+    val = JpuReadInstReg(0, MJPEG_VERSION_INFO_REG);
+    // JPU Capabilities
+    g_JpuAttributes.productId    = (val>>24) & 0xf;
+    g_JpuAttributes.revisoin     = (val & 0xffffff);
+    g_JpuAttributes.support12bit = (val>>28) & 0x01;
+
+    //jdi_log(JDI_LOG_CMD_INIT, 0, 0);
+    JpgLeaveLock();
+    return JPG_RET_SUCCESS;
+}
+
+void JPU_DeInit()
+{
+    JpgEnterLock();
+    if (jdi_get_task_num() == 1) {
+        JpuWriteReg(MJPEG_INST_CTRL_START_REG, 0);
+    }
+    JpgLeaveLock();
+    jdi_release();
+}
+
+JpgRet JPU_GetVersionInfo(Uint32 *apiVersion, Uint32 *hwRevision, Uint32 *hwProductId)
+{
+    if (JPU_IsInit() == 0) {
+        return JPG_RET_NOT_INITIALIZED;
+    }
+
+    JpgEnterLock();
+    if (apiVersion) {
+        *apiVersion = API_VERSION;
+    }
+    if (hwRevision) {
+        *hwRevision = g_JpuAttributes.revisoin;
+    }
+    if (hwProductId) {
+        *hwProductId = g_JpuAttributes.productId;
+    }
+    JpgLeaveLock();
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_DecOpen(JpgDecHandle * pHandle, JpgDecOpenParam * pop)
+{
+    JpgInst*    pJpgInst;
+    JpgDecInfo* pDecInfo;
+    JpgRet      ret;
+    ret = CheckJpgDecOpenParam(pop);
+    if (ret != JPG_RET_SUCCESS) {
+        return ret;
+    }
+
+    JpgEnterLock();
+    ret = GetJpgInstance(&pJpgInst);
+    if (ret == JPG_RET_FAILURE) {
+        *pHandle = 0;
+        JpgLeaveLock();
+        return JPG_RET_FAILURE;
+    }
+
+    *pHandle = pJpgInst;
+
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+    memset(pDecInfo, 0x00, sizeof(JpgDecInfo));
+
+    pDecInfo->streamWrPtr = pop->bitstreamBuffer;
+    pDecInfo->streamRdPtr = pop->bitstreamBuffer;
+    JLOG(INFO, "streamWrPtr = %x\r\n", pop->bitstreamBuffer);
+    pDecInfo->streamBufStartAddr = pop->bitstreamBuffer;
+    pDecInfo->streamBufSize     = pop->bitstreamBufferSize;
+    pDecInfo->streamBufEndAddr  = pop->bitstreamBuffer + pop->bitstreamBufferSize;
+    pDecInfo->pBitStream        = pop->pBitStream;
+    pDecInfo->streamEndian      = pop->streamEndian;
+    pDecInfo->frameEndian       = pop->frameEndian;
+    pDecInfo->chromaInterleave  = pop->chromaInterleave;
+    pDecInfo->packedFormat      = pop->packedFormat;
+    pDecInfo->roiEnable         = pop->roiEnable;
+    pDecInfo->roiWidth          = pop->roiWidth;
+    pDecInfo->roiHeight         = pop->roiHeight;
+    pDecInfo->roiOffsetX        = pop->roiOffsetX;
+    pDecInfo->roiOffsetY        = pop->roiOffsetY;
+    pDecInfo->pixelJustification = pop->pixelJustification;
+    pDecInfo->intrEnableBit     = pop->intrEnableBit;
+    pJpgInst->sliceInstMode     = 0;    /* The decoder does not support the slice-decoding */
+    pDecInfo->rotationIndex     = pop->rotation / 90;
+    pDecInfo->mirrorIndex       = pop->mirror;
+    /* convert output format */
+    switch (pop->outputFormat) {
+    case FORMAT_400: ret = JPG_RET_INVALID_PARAM; break;
+    case FORMAT_420: pDecInfo->ofmt = O_FMT_420;  break;
+    case FORMAT_422: pDecInfo->ofmt = O_FMT_422;  break;
+    case FORMAT_440: ret = JPG_RET_INVALID_PARAM; break;
+    case FORMAT_444: pDecInfo->ofmt = O_FMT_444;  break;
+    case FORMAT_MAX: pDecInfo->ofmt = O_FMT_NONE; break;
+    default:         ret = JPG_RET_INVALID_PARAM; break;
+    }
+
+    pDecInfo->userqMatTab = 0;
+    pDecInfo->decIdx = 0;
+
+    JpgLeaveLock();
+
+    return ret;
+}
+
+JpgRet JPU_DecClose(JpgDecHandle handle)
+{
+    JpgInst * pJpgInst;
+    JpgRet ret;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    pJpgInst = handle;
+
+    JpgEnterLock();
+
+    if (GetJpgPendingInstEx(pJpgInst->instIndex)) {
+        JpgLeaveLock();
+        return JPG_RET_FRAME_NOT_COMPLETE;
+    }
+
+    FreeJpgInstance(pJpgInst);
+    JpgLeaveLock();
+
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_DecGetInitialInfo(JpgDecHandle handle, JpgDecInitialInfo * info)
+{
+    JpgInst*    pJpgInst;
+    JpgDecInfo* pDecInfo;
+    JpgRet      ret;
+    int         err;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    if (info == 0) {
+        return JPG_RET_INVALID_PARAM;
+    }
+    pJpgInst = handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+
+    if (0 >= (err=JpegDecodeHeader(pDecInfo))) {
+        /* The value of -2 indicates that the bitstream in the buffer is not enough to decode a header. */
+        return (-2 == err) ? JPG_RET_BIT_EMPTY : JPG_RET_FAILURE;
+    }
+
+    if (pDecInfo->jpg12bit == TRUE && g_JpuAttributes.support12bit == FALSE) {
+        return JPG_RET_NOT_SUPPORT;
+    }
+
+    info->picWidth = pDecInfo->picWidth;
+    info->picHeight = pDecInfo->picHeight;
+    info->minFrameBufferCount = 1;
+    info->sourceFormat = (FrameFormat)pDecInfo->format;
+    info->ecsPtr = pDecInfo->ecsPtr;
+
+    pDecInfo->initialInfoObtained = 1;
+    pDecInfo->minFrameBufferNum = 1;
+
+
+    if ((pDecInfo->packedFormat == PACKED_FORMAT_444) && (pDecInfo->format != FORMAT_444)) {
+        return JPG_RET_INVALID_PARAM;
+    }
+
+    if (pDecInfo->roiEnable) {
+        if (pDecInfo->format == FORMAT_400) {
+            pDecInfo->roiMcuWidth = pDecInfo->roiWidth/8;
+        }
+        else  {
+            pDecInfo->roiMcuWidth = pDecInfo->roiWidth/pDecInfo->mcuWidth;
+        }
+        pDecInfo->roiMcuHeight = pDecInfo->roiHeight/pDecInfo->mcuHeight;
+        pDecInfo->roiMcuOffsetX = pDecInfo->roiOffsetX/pDecInfo->mcuWidth;
+        pDecInfo->roiMcuOffsetY = pDecInfo->roiOffsetY/pDecInfo->mcuHeight;
+
+        if ((pDecInfo->roiOffsetX > pDecInfo->alignedWidth)
+            || (pDecInfo->roiOffsetY > pDecInfo->alignedHeight)
+            || (pDecInfo->roiOffsetX + pDecInfo->roiWidth > pDecInfo->alignedWidth)
+            || (pDecInfo->roiOffsetY + pDecInfo->roiHeight > pDecInfo->alignedHeight))
+            return JPG_RET_INVALID_PARAM;
+
+        if (pDecInfo->format == FORMAT_400) {
+            if (((pDecInfo->roiOffsetX + pDecInfo->roiWidth) < 8) || ((pDecInfo->roiOffsetY + pDecInfo->roiHeight) < pDecInfo->mcuHeight))
+                return JPG_RET_INVALID_PARAM;
+        }
+        else {
+            if (((pDecInfo->roiOffsetX + pDecInfo->roiWidth) < pDecInfo->mcuWidth) || ((pDecInfo->roiOffsetY + pDecInfo->roiHeight) < pDecInfo->mcuHeight))
+                return JPG_RET_INVALID_PARAM;
+        }
+
+        if (pDecInfo->format == FORMAT_400)
+            pDecInfo->roiFrameWidth = pDecInfo->roiMcuWidth * 8;
+        else
+            pDecInfo->roiFrameWidth = pDecInfo->roiMcuWidth * pDecInfo->mcuWidth;
+        pDecInfo->roiFrameHeight = pDecInfo->roiMcuHeight*pDecInfo->mcuHeight;
+        info->roiFrameWidth   = pDecInfo->roiFrameWidth;
+        info->roiFrameHeight  = pDecInfo->roiFrameHeight;
+        info->roiFrameOffsetX = pDecInfo->roiMcuOffsetX*pDecInfo->mcuWidth;
+        info->roiFrameOffsetY = pDecInfo->roiMcuOffsetY*pDecInfo->mcuHeight;
+    }
+    info->bitDepth        = pDecInfo->bitDepth;
+
+
+    return JPG_RET_SUCCESS;
+}
+
+FrameBuffer *JPU_GetFrameBufPool(JpgDecHandle handle)
+{
+    JpgInst * pJpgInst;
+    JpgDecInfo * pDecInfo;
+    JpgRet ret;
+
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return NULL;
+
+    pJpgInst = handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+    return pDecInfo->frameBufPool;
+}
+
+JpgRet JPU_DecRegisterFrameBuffer(JpgDecHandle handle, FrameBuffer * bufArray, int num, int stride)
+{
+    JpgInst * pJpgInst;
+    JpgDecInfo * pDecInfo;
+    JpgRet ret;
+
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    pJpgInst = handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+
+
+    if (!pDecInfo->initialInfoObtained) {
+        return JPG_RET_WRONG_CALL_SEQUENCE;
+    }
+
+    if (bufArray == 0) {
+        return JPG_RET_INVALID_FRAME_BUFFER;
+    }
+
+    if (num < pDecInfo->minFrameBufferNum) {
+        return JPG_RET_INSUFFICIENT_FRAME_BUFFERS;
+    }
+
+    if ((stride % 8) != 0) {
+        return JPG_RET_INVALID_STRIDE;
+    }
+
+    pDecInfo->frameBufPool    = bufArray;
+    pDecInfo->numFrameBuffers = num;
+    pDecInfo->stride          = stride;
+    pDecInfo->stride_c        = bufArray[0].strideC;
+
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_DecRegisterFrameBuffer2(JpgDecHandle handle, FrameBuffer * bufArray, int stride)
+{
+    JpgInst * pJpgInst;
+    JpgDecInfo * pDecInfo;
+    JpgRet ret;
+    int number;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    pJpgInst = handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+    number = pDecInfo->numFrameBuffers;
+
+    if (!pDecInfo->initialInfoObtained) {
+        return JPG_RET_WRONG_CALL_SEQUENCE;
+    }
+
+    if (bufArray == 0) {
+        return JPG_RET_INVALID_FRAME_BUFFER;
+    }
+
+    if ((stride % 8) != 0) {
+        return JPG_RET_INVALID_STRIDE;
+    }
+
+    
+    if (pDecInfo->frameBufPool == NULL)
+    {
+        //First register
+        JLOG(INFO, "%s First register frame buffer\r\n", __FUNCTION__);
+        pDecInfo->frameBufPool = bufArray;
+        pDecInfo->stride          = stride;
+        pDecInfo->stride_c        = bufArray->strideC;
+    }
+    
+    //check wether frameBufPool and bufArray match
+    if (pDecInfo->frameBufPool[number].bufY != bufArray->bufY)
+    {
+        JLOG(ERR, "Does not support discontinuous array!\n");
+        return JPG_RET_FAILURE;
+    }
+    number ++;
+
+    if (number >= MAX_FRAME)
+    {
+        JLOG(ERR, "Too lot of frame buffer! %d/%d\n", number, MAX_FRAME);
+        return JPG_RET_FAILURE;
+    }
+    pDecInfo->numFrameBuffers = number;
+    JLOG(INFO, "%s numFrameBuffers = %d\r\n", __FUNCTION__, pDecInfo->numFrameBuffers);
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_DecGetBitstreamBuffer(JpgDecHandle handle,
+    PhysicalAddress * prdPtr,
+    PhysicalAddress * pwrPtr,
+    int * size)
+{
+    JpgInst * pJpgInst;
+    JpgDecInfo * pDecInfo;
+    JpgRet ret;
+    PhysicalAddress rdPtr;
+    PhysicalAddress wrPtr;
+    int room;
+    Int32 instRegIndex;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    pJpgInst = handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+
+    if (GetJpgPendingInstEx(pJpgInst->instIndex) == pJpgInst) {
+        rdPtr = JpuReadInstReg(instRegIndex, MJPEG_BBC_RD_PTR_REG);
+    }
+    else {
+        rdPtr = pDecInfo->streamRdPtr;
+    }
+
+    wrPtr = pDecInfo->streamWrPtr;
+
+    if (wrPtr == pDecInfo->streamBufStartAddr) {
+        if (pDecInfo->frameOffset == 0) {
+            room = (pDecInfo->streamBufEndAddr-pDecInfo->streamBufStartAddr);
+        }
+        else {
+            room = (pDecInfo->frameOffset);
+        }
+    }
+    else {
+        room = (pDecInfo->streamBufEndAddr - wrPtr);
+    }
+
+    room = ((room>>9)<<9); // multiple of 512
+
+    if (prdPtr) *prdPtr = rdPtr;
+    if (pwrPtr) *pwrPtr = wrPtr;
+    if (size)   *size = room;
+
+    return JPG_RET_SUCCESS;
+}
+
+
+JpgRet JPU_DecUpdateBitstreamBuffer(JpgDecHandle handle, int size)
+{
+    JpgInst * pJpgInst;
+    JpgDecInfo * pDecInfo;
+    PhysicalAddress wrPtr;
+    PhysicalAddress rdPtr;
+    JpgRet ret;
+    int		val = 0;
+    Int32 instRegIndex;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    pJpgInst = handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+    wrPtr = pDecInfo->streamWrPtr;
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+
+    if (size == 0)
+    {
+        val = (wrPtr-pDecInfo->streamBufStartAddr) / 256;
+        if ((wrPtr-pDecInfo->streamBufStartAddr) % 256)
+            val = val + 1;
+
+        if (GetJpgPendingInstEx(pJpgInst->instIndex) == pJpgInst) {
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_STRM_CTRL_REG, (1UL << 31 | val));
+        }
+        pDecInfo->streamEndflag = 1;
+        return JPG_RET_SUCCESS;
+    }
+
+    wrPtr = pDecInfo->streamWrPtr;
+    wrPtr += size;
+
+    if (wrPtr == pDecInfo->streamBufEndAddr) {
+        wrPtr = pDecInfo->streamBufStartAddr;
+    }
+
+    pDecInfo->streamWrPtr = wrPtr;
+
+    if (GetJpgPendingInstEx(pJpgInst->instIndex) == pJpgInst) {
+        rdPtr = JpuReadInstReg(instRegIndex, MJPEG_BBC_RD_PTR_REG);
+
+        if (rdPtr >= pDecInfo->streamBufEndAddr) {
+            JLOG(INFO, "!!!!! WRAP-AROUND !!!!!\n");
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_CUR_POS_REG, 0);
+            JpuWriteInstReg(instRegIndex, MJPEG_GBU_TCNT_REG, 0);
+            JpuWriteInstReg(instRegIndex, (MJPEG_GBU_TCNT_REG+4), 0);
+        }
+
+        JpuWriteInstReg(instRegIndex, MJPEG_BBC_WR_PTR_REG, wrPtr);
+        if (wrPtr == pDecInfo->streamBufStartAddr) {
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_END_ADDR_REG, pDecInfo->streamBufEndAddr);
+        }
+        else {
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_END_ADDR_REG, wrPtr);
+        }
+    }
+    else {
+        rdPtr = pDecInfo->streamRdPtr;
+    }
+
+    pDecInfo->streamRdPtr = rdPtr;
+
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_SWReset(JpgHandle handle)
+{
+    Uint32 val;
+
+    int clock_state;
+    JpgInst *pJpgInst;
+
+    pJpgInst = ((JpgInst *)handle);
+    clock_state = jdi_get_clock_gate();
+
+    if (clock_state == 0)
+        jdi_set_clock_gate(1);
+
+    if (handle)
+        jdi_log(JDI_LOG_CMD_RESET, 1, pJpgInst->instIndex);
+
+    val = JpuReadReg(MJPEG_INST_CTRL_START_REG);
+    val |= (1<<2);
+    JpuWriteReg(MJPEG_INST_CTRL_START_REG, val);
+    if (jdi_wait_inst_ctrl_busy(JPU_INST_CTRL_TIMEOUT_MS, MJPEG_INST_CTRL_STATUS_REG, INST_CTRL_IDLE) == -1) {// wait for INST_CTRL become IDLE
+        if (handle)
+            jdi_log(JDI_LOG_CMD_RESET, 0, pJpgInst->instIndex);
+        val &= ~(1<<2);
+        JpuWriteReg(MJPEG_INST_CTRL_START_REG, val);
+        if (clock_state == 0)
+            jdi_set_clock_gate(0);
+        return JPG_RET_INST_CTRL_ERROR;
+    }
+    val &= ~(1<<2);
+    JpuWriteReg(MJPEG_INST_CTRL_START_REG, val);
+
+    if (handle)
+        jdi_log(JDI_LOG_CMD_RESET, 0, pJpgInst->instIndex);
+
+    if (clock_state == 0)
+        jdi_set_clock_gate(0);
+
+    return JPG_RET_SUCCESS;
+}
+JpgRet JPU_HWReset()
+{
+    if (jdi_hw_reset() < 0 )
+        return JPG_RET_FAILURE;
+
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_DecSetRdPtr(JpgDecHandle handle, PhysicalAddress addr, BOOL updateWrPtr)
+{
+    JpgInst*    pJpgInst;
+    JpgDecInfo* pDecInfo;
+    JpgRet      ret;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    pJpgInst = (JpgInst*)handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+
+    JpgEnterLock();
+
+    if (GetJpgPendingInstEx(pJpgInst->instIndex)) {
+        JpgLeaveLock();
+        return JPG_RET_FRAME_NOT_COMPLETE;
+    }
+    pDecInfo->streamRdPtr = addr;
+    if (updateWrPtr)
+        pDecInfo->streamWrPtr = addr;
+
+    pDecInfo->frameOffset = addr - pDecInfo->streamBufStartAddr;
+    pDecInfo->consumeByte = 0;
+
+    JpuWriteReg(MJPEG_BBC_RD_PTR_REG, pDecInfo->streamRdPtr);
+
+    JpgLeaveLock();
+
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_DecSetRdPtrEx(JpgDecHandle handle, PhysicalAddress addr, BOOL updateWrPtr)
+{
+    JpgInst*    pJpgInst;
+    JpgDecInfo* pDecInfo;
+    JpgRet      ret;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    pJpgInst = (JpgInst*)handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+
+    JpgEnterLock();
+
+    if (GetJpgPendingInstEx(pJpgInst->instIndex)) {
+        JpgLeaveLock();
+        return JPG_RET_FRAME_NOT_COMPLETE;
+    }
+    pDecInfo->streamRdPtr = addr;
+    pDecInfo->streamBufStartAddr = addr;
+    if (updateWrPtr)
+        pDecInfo->streamWrPtr = addr;
+
+    pDecInfo->frameOffset = 0;
+    pDecInfo->consumeByte = 0;
+
+    JpuWriteReg(MJPEG_BBC_RD_PTR_REG, pDecInfo->streamRdPtr);
+
+    JpgLeaveLock();
+
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_DecStartOneFrame(JpgDecHandle handle, JpgDecParam *param)
+{
+    JpgInst * pJpgInst;
+    JpgDecInfo * pDecInfo;
+    JpgRet ret;
+    Uint32 val;
+    PhysicalAddress rdPtr, wrPtr;
+    BOOL    is12Bit     = FALSE;
+    BOOL    ppuEnable   = FALSE;
+    Int32 instRegIndex;
+    BOOL bTableInfoUpdate;
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+
+    pJpgInst = handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+    is12Bit  = (pDecInfo->bitDepth == 8) ? FALSE : TRUE;
+
+    if (pDecInfo->frameBufPool == 0) { // This means frame buffers have not been registered.
+        return JPG_RET_WRONG_CALL_SEQUENCE;
+    }
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+
+    JpgEnterLock();
+    if (GetJpgPendingInstEx(pJpgInst->instIndex) == pJpgInst) {
+        JpgLeaveLock();
+        return JPG_RET_FRAME_NOT_COMPLETE;
+    }
+
+
+    if (pDecInfo->frameOffset < 0) {
+        SetJpgPendingInstEx(0, pJpgInst->instIndex);
+        return JPG_RET_EOS;
+    }
+
+    pDecInfo->q_prec0 = 0;
+    pDecInfo->q_prec1 = 0;
+    pDecInfo->q_prec2 = 0;
+    pDecInfo->q_prec3 = 0;
+
+    //check for stream empty case
+    if (pDecInfo->streamEndflag == 0) {
+        rdPtr = pDecInfo->streamRdPtr;
+        wrPtr = pDecInfo->streamWrPtr;
+        if (wrPtr == pDecInfo->streamBufStartAddr)
+            wrPtr = pDecInfo->streamBufEndAddr;
+        if (rdPtr > wrPtr) { // wrap-around case
+            if ( ((pDecInfo->streamBufEndAddr-rdPtr) + (wrPtr-pDecInfo->streamBufStartAddr)) <1024 ) {
+                JpgLeaveLock();
+                return JPG_RET_BIT_EMPTY;
+            }
+        }
+        else {
+            if (wrPtr - rdPtr < 1024) {
+                JpgLeaveLock();
+                return JPG_RET_BIT_EMPTY;
+            }
+        }
+    }
+
+    {
+        val = JpegDecodeHeader(pDecInfo);
+        if (val == 0) {
+            JpgLeaveLock();
+            return JPG_RET_FAILURE;
+        }
+
+        if (val == (Uint32)-2) {	// wrap around case
+            pDecInfo->frameOffset = 0;
+            pDecInfo->ecsPtr = 0;
+            val = JpegDecodeHeader(pDecInfo);
+            if (val == 0) {
+                JpgLeaveLock();
+                return JPG_RET_FAILURE;
+            }
+        }
+
+        if (val == (Uint32)-1) {	//stream empty case
+            if (pDecInfo->streamEndflag == 1) {
+                SetJpgPendingInstEx(0, pJpgInst->instIndex);
+                pDecInfo->frameOffset = -1;
+                if (pJpgInst->sliceInstMode == TRUE) {
+                    JpgLeaveLock();
+                }
+                return JPG_RET_EOS;
+            }
+            JpgLeaveLock();
+            return JPG_RET_BIT_EMPTY;
+        }
+    }
+
+    JpuWriteInstReg(instRegIndex, MJPEG_INTR_MASK_REG, ((~pDecInfo->intrEnableBit) & 0x3ff));
+    /* The registers related to the slice encoding should be clear */
+    JpuWriteInstReg(instRegIndex, MJPEG_SLICE_INFO_REG,    pDecInfo->alignedHeight);
+    JpuWriteInstReg(instRegIndex, MJPEG_SLICE_DPB_POS_REG, pDecInfo->alignedHeight);
+    JpuWriteInstReg(instRegIndex, MJPEG_SLICE_POS_REG,     0);
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_SETMB_REG,     0);
+
+    if (pDecInfo->streamRdPtr == pDecInfo->streamBufEndAddr) {
+        JpuWriteInstReg(instRegIndex, MJPEG_BBC_CUR_POS_REG, 0);
+        JpuWriteInstReg(instRegIndex, MJPEG_GBU_TCNT_REG, 0);
+        JpuWriteInstReg(instRegIndex, (MJPEG_GBU_TCNT_REG+4), 0);
+    }
+
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_WR_PTR_REG, pDecInfo->streamWrPtr);
+    if (pDecInfo->streamWrPtr == pDecInfo->streamBufStartAddr) {
+        JpuWriteInstReg(instRegIndex, MJPEG_BBC_END_ADDR_REG, pDecInfo->streamBufEndAddr);
+    }
+    else {
+        JpuWriteInstReg(instRegIndex, MJPEG_BBC_END_ADDR_REG, JPU_CEIL(256, pDecInfo->streamWrPtr));
+    }
+
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_BAS_ADDR_REG, pDecInfo->streamBufStartAddr);
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_TCNT_REG, 0);
+    JpuWriteInstReg(instRegIndex, (MJPEG_GBU_TCNT_REG+4), 0);
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_ERRMB_REG, 0);
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_CTRL_REG, is12Bit << 31 | pDecInfo->q_prec0 << 30 | pDecInfo->q_prec1 << 29 | pDecInfo->q_prec2 << 28 | pDecInfo->q_prec3 << 27 |
+                                                       pDecInfo->huffAcIdx << 13 | pDecInfo->huffDcIdx << 7 | pDecInfo->userHuffTab << 6 |
+                                                       (JPU_CHECK_WRITE_RESPONSE_BVALID_SIGNAL << 2) | 0);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_SIZE_REG, (pDecInfo->alignedWidth << 16) | pDecInfo->alignedHeight);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_OP_INFO_REG,  pDecInfo->busReqNum);
+    JpuWriteInstReg(instRegIndex, MJPEG_MCU_INFO_REG, (pDecInfo->mcuBlockNum&0x0f) << 17 | (pDecInfo->compNum&0x07) << 14    |
+                                                      (pDecInfo->compInfo[0]&0x3f) << 8  | (pDecInfo->compInfo[1]&0x0f) << 4 |
+                                                      (pDecInfo->compInfo[2]&0x0f));
+
+    //enable intlv NV12: 10, NV21: 11
+    //packedFormat:0 => 4'd0
+    //packedFormat:1,2,3,4 => 4, 5, 6, 7,
+    //packedFormat:5 => 8
+    //packedFormat:6 => 9
+    val = (pDecInfo->ofmt << 9) | (pDecInfo->frameEndian << 6) | ((pDecInfo->chromaInterleave==0)?0:(pDecInfo->chromaInterleave==1)?2:3);
+    if (pDecInfo->packedFormat == PACKED_FORMAT_NONE) {
+        val |= (0<<5) | (0<<4);
+    }
+    else if (pDecInfo->packedFormat == PACKED_FORMAT_444) {
+        val |= (1<<5) | (0<<4) | (0<<2);
+    }
+    else {
+        val |= (0<<5) | (1<<4) | ((pDecInfo->packedFormat-1)<<2);
+    }
+    val |= (pDecInfo->pixelJustification << 11);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_CONFIG_REG, val);
+    JpuWriteInstReg(instRegIndex, MJPEG_RST_INTVAL_REG, pDecInfo->rstIntval);
+
+    if (param) {
+        if (param->scaleDownRatioWidth > 0 )
+            pDecInfo->iHorScaleMode = param->scaleDownRatioWidth;
+        if (param->scaleDownRatioHeight > 0 )
+            pDecInfo->iVerScaleMode = param->scaleDownRatioHeight;
+    }
+    if (pDecInfo->iHorScaleMode | pDecInfo->iVerScaleMode)
+        val = ((pDecInfo->iHorScaleMode&0x3)<<2) | ((pDecInfo->iVerScaleMode&0x3)) | 0x10 ;
+    else {
+        val = 0;
+    }
+    JpuWriteInstReg(instRegIndex, MJPEG_SCL_INFO_REG, val);
+
+    bTableInfoUpdate = FALSE;
+    if (pDecInfo->userHuffTab) {
+        bTableInfoUpdate = TRUE;
+    }
+
+    if (bTableInfoUpdate == TRUE) {
+        if (is12Bit == TRUE){
+            if (!JpgDecHuffTabSetUp_12b(pDecInfo, instRegIndex)) {
+                JpgLeaveLock();
+                return JPG_RET_INVALID_PARAM;
+            }
+        }else{
+            if (!JpgDecHuffTabSetUp(pDecInfo, instRegIndex)) {
+                JpgLeaveLock();
+                return JPG_RET_INVALID_PARAM;
+            }
+        }
+    }
+
+    bTableInfoUpdate = TRUE; // it always should be TRUE for multi-instance
+    if (bTableInfoUpdate == TRUE) {
+        if (!JpgDecQMatTabSetUp(pDecInfo, instRegIndex)) {
+            JpgLeaveLock();
+            return JPG_RET_INVALID_PARAM;
+        }
+    }
+
+    JpgDecGramSetup(pDecInfo, instRegIndex);
+
+    if (pDecInfo->streamEndflag == 1) {
+        val = JpuReadInstReg(instRegIndex, MJPEG_BBC_STRM_CTRL_REG);
+        if ((val & (1UL << 31)) == 0 ) {
+            val = (pDecInfo->streamWrPtr-pDecInfo->streamBufStartAddr) / 256;
+            if ((pDecInfo->streamWrPtr-pDecInfo->streamBufStartAddr) % 256)
+                val = val + 1;
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_STRM_CTRL_REG, (1UL << 31 | val));
+        }
+    }
+    else {
+        JpuWriteInstReg(instRegIndex, MJPEG_BBC_STRM_CTRL_REG, 0);
+    }
+
+    JpuWriteInstReg(instRegIndex, MJPEG_RST_INDEX_REG, 0);	// RST index at the beginning.
+    JpuWriteInstReg(instRegIndex, MJPEG_RST_COUNT_REG, 0);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_DPCM_DIFF_Y_REG, 0);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPCM_DIFF_CB_REG, 0);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPCM_DIFF_CR_REG, 0);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_FF_RPTR_REG, pDecInfo->bitPtr);
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_CTRL_REG, 3);
+
+    ppuEnable = (pDecInfo->rotationIndex > 0) || (pDecInfo->mirrorIndex > 0);
+    JpuWriteInstReg(instRegIndex, MJPEG_ROT_INFO_REG, (ppuEnable<<4) | (pDecInfo->mirrorIndex<<2) | pDecInfo->rotationIndex);
+
+    val = (pDecInfo->frameIdx % pDecInfo->numFrameBuffers);
+    // JLOG(INFO, "%s: bufY = %lx bufCb = %lx bufCr = %lx stride = %d stride_c = %d\r\n", __FUNCTION__,
+    //     pDecInfo->frameBufPool[val].bufY, pDecInfo->frameBufPool[val].bufCb, pDecInfo->frameBufPool[val].bufCr, 
+    //     pDecInfo->stride, pDecInfo->stride_c);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_BASE00_REG, pDecInfo->frameBufPool[val].bufY);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_BASE01_REG, pDecInfo->frameBufPool[val].bufCb);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_BASE02_REG, pDecInfo->frameBufPool[val].bufCr);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_YSTRIDE_REG, pDecInfo->stride);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_CSTRIDE_REG, pDecInfo->stride_c);
+
+    if (pDecInfo->roiEnable) {
+        JpuWriteInstReg(instRegIndex, MJPEG_CLP_INFO_REG, 1);
+        JpuWriteInstReg(instRegIndex, MJPEG_CLP_BASE_REG, pDecInfo->roiOffsetX << 16 | pDecInfo->roiOffsetY);	// pixel unit
+        JpuWriteInstReg(instRegIndex, MJPEG_CLP_SIZE_REG, (pDecInfo->roiFrameWidth << 16) | pDecInfo->roiFrameHeight); // pixel Unit
+    }
+    else {
+        JpuWriteInstReg(instRegIndex, MJPEG_CLP_INFO_REG, 0);
+    }
+
+    if (pJpgInst->loggingEnable)
+        jdi_log(JDI_LOG_CMD_PICRUN, 1, instRegIndex);
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        JpuWriteInstReg(instRegIndex, MJPEG_PIC_START_REG, (1<<JPG_DEC_SLICE_ENABLE_START_PIC));
+    }
+    else {
+        JpuWriteInstReg(instRegIndex, MJPEG_PIC_START_REG, (1<<JPG_ENABLE_START_PIC));
+    }
+
+    pDecInfo->decIdx++;
+
+    SetJpgPendingInstEx(pJpgInst, pJpgInst->instIndex);
+    if (pJpgInst->sliceInstMode == TRUE) {
+        JpgLeaveLock();
+    }
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_DecGetOutputInfo(JpgDecHandle handle, JpgDecOutputInfo * info)
+{
+    JpgInst*    pJpgInst;
+    JpgDecInfo* pDecInfo;
+    JpgRet      ret;
+    Uint32      val = 0;
+    Int32       instRegIndex;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS) {
+        return ret;
+    }
+
+    if (info == 0) {
+        return JPG_RET_INVALID_PARAM;
+    }
+
+    pJpgInst = handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        JpgEnterLock();
+    }
+
+    if (pJpgInst != GetJpgPendingInstEx(pJpgInst->instIndex)) {
+        JpgLeaveLock();
+        return JPG_RET_WRONG_CALL_SEQUENCE;
+    }
+
+
+    if (pDecInfo->frameOffset < 0)
+    {
+        info->numOfErrMBs = 0;
+        info->decodingSuccess = 1;
+        info->indexFrameDisplay = -1;
+        SetJpgPendingInstEx(0, pJpgInst->instIndex);
+
+        JpgLeaveLock();
+        return JPG_RET_SUCCESS;
+    }
+
+    if (pDecInfo->roiEnable) {
+        info->decPicWidth = pDecInfo->roiMcuWidth*pDecInfo->mcuWidth;
+        info->decPicHeight = pDecInfo->roiMcuHeight*pDecInfo->mcuHeight;
+    }
+    else {
+        info->decPicWidth = pDecInfo->alignedWidth;
+        info->decPicHeight = pDecInfo->alignedHeight;
+    }
+
+    info->decPicWidth  >>= pDecInfo->iHorScaleMode;
+    info->decPicHeight >>= pDecInfo->iVerScaleMode;
+
+    info->indexFrameDisplay = (pDecInfo->frameIdx%pDecInfo->numFrameBuffers);
+    info->consumedByte = (JpuReadInstReg(instRegIndex, MJPEG_GBU_TCNT_REG))/8;
+    pDecInfo->streamRdPtr = JpuReadInstReg(instRegIndex, MJPEG_BBC_RD_PTR_REG);
+    pDecInfo->consumeByte = info->consumedByte - 16 - pDecInfo->ecsPtr;
+	
+	/*
+ 		fix up the program may not be able to exit normally when decoder some pictures.
+		due to  pDecInfo->consumeByte==0 when not first enter.
+	*/
+	if(pDecInfo->consumeByte == 0) 
+		pDecInfo->consumeByte += 2;
+
+    info->bytePosFrameStart = pDecInfo->frameOffset;
+    info->ecsPtr = pDecInfo->ecsPtr;
+    info->rdPtr  = pDecInfo->streamRdPtr;
+    info->wrPtr  = JpuReadInstReg(instRegIndex, MJPEG_BBC_WR_PTR_REG);
+
+    pDecInfo->ecsPtr = 0;
+    pDecInfo->frameIdx++;
+
+    val = JpuReadInstReg(instRegIndex, MJPEG_PIC_STATUS_REG);
+    if (val & (1<<INT_JPU_DONE)) {
+        info->decodingSuccess  = 1;
+        info->numOfErrMBs      = 0;
+    }
+    else if (val & (1<<INT_JPU_ERROR)){
+        info->numOfErrMBs = JpuReadInstReg(instRegIndex, MJPEG_PIC_ERRMB_REG);
+        info->decodingSuccess = 0;
+
+    }
+
+#ifndef JPU_IRQ_CONTROL
+	info->decodingSuccess  = 1;
+	info->numOfErrMBs      = 0;
+#endif
+
+    info->frameCycle = JpuReadInstReg(instRegIndex, MJPEG_CYCLE_INFO_REG);
+
+    if (val != 0)
+        JpuWriteInstReg(instRegIndex, MJPEG_PIC_STATUS_REG, val);
+
+    if (pJpgInst->loggingEnable)
+        jdi_log(JDI_LOG_CMD_PICRUN, 0, instRegIndex);
+
+
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_START_REG, 0);
+
+    val = JpuReadReg(MJPEG_INST_CTRL_STATUS_REG);
+    val &= ~(1UL<<instRegIndex);
+    JpuWriteReg(MJPEG_INST_CTRL_STATUS_REG, val);
+
+    SetJpgPendingInstEx(0, pJpgInst->instIndex);
+    JpgLeaveLock();
+
+    return JPG_RET_SUCCESS;
+}
+
+
+JpgRet JPU_DecGiveCommand(
+    JpgDecHandle handle,
+    JpgCommand cmd,
+    void * param)
+{
+    JpgInst * pJpgInst;
+    JpgDecInfo * pDecInfo;
+    JpgRet ret;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+
+    pJpgInst = handle;
+    pDecInfo = &pJpgInst->JpgInfo->decInfo;
+    switch (cmd)
+    {
+    case SET_JPG_SCALE_HOR:
+        {
+            int scale;
+            scale = *(int *)param;
+            if (pDecInfo->alignedWidth < 128 || pDecInfo->alignedHeight < 128) {
+                if (scale) {
+                    return JPG_RET_INVALID_PARAM;
+                }
+            }
+
+            pDecInfo->iHorScaleMode = scale;
+            break;
+        }
+    case SET_JPG_SCALE_VER:
+        {
+            int scale;
+            scale = *(int *)param;
+            if (pDecInfo->alignedWidth < 128 || pDecInfo->alignedHeight < 128) {
+                if (scale) {
+                    return JPG_RET_INVALID_PARAM;
+                }
+            }
+            pDecInfo->iVerScaleMode = scale;
+            break;
+        }
+    case ENABLE_LOGGING:
+        {
+            pJpgInst->loggingEnable = 1;
+        }
+        break;
+    case DISABLE_LOGGING:
+        {
+            pJpgInst->loggingEnable = 0;
+        }
+        break;
+    default:
+        return JPG_RET_INVALID_COMMAND;
+    }
+    return JPG_RET_SUCCESS;
+}
+
+JpgRet JPU_EncOpen(JpgEncHandle * pHandle, JpgEncOpenParam * pop)
+{
+    JpgInst*    pJpgInst;
+    JpgEncInfo* pEncInfo;
+    JpgRet      ret;
+    Uint32      i;
+    Uint32      mcuWidth, mcuHeight;
+    Uint32      comp0McuWidth, comp0McuHeight;
+    BOOL        rotation_90_270 = FALSE;
+    FrameFormat format;
+
+    ret = CheckJpgEncOpenParam(pop, &g_JpuAttributes);
+    if (ret != JPG_RET_SUCCESS) {
+        return ret;
+    }
+
+    JpgEnterLock();
+    ret = GetJpgInstance(&pJpgInst);
+    if (ret == JPG_RET_FAILURE) {
+        JpgLeaveLock();
+        return JPG_RET_FAILURE;
+    }
+
+    *pHandle = pJpgInst;
+    pEncInfo = &pJpgInst->JpgInfo->encInfo;
+    memset(pEncInfo, 0x00, sizeof(JpgEncInfo));
+    pEncInfo->streamRdPtr        = pop->bitstreamBuffer;
+    pEncInfo->streamWrPtr        = pop->bitstreamBuffer;
+    pEncInfo->sliceHeight        = pop->sliceHeight;
+    pEncInfo->intrEnableBit      = pop->intrEnableBit;
+
+    pEncInfo->streamBufStartAddr = pop->bitstreamBuffer;
+    pEncInfo->streamBufEndAddr   = pop->bitstreamBuffer + pop->bitstreamBufferSize - (4096);
+    pEncInfo->streamEndian       = pop->streamEndian;
+    pEncInfo->frameEndian        = pop->frameEndian;
+    pEncInfo->chromaInterleave   = pop->chromaInterleave;
+    pEncInfo->format             = pop->sourceFormat;
+    pEncInfo->picWidth           = pop->picWidth;
+    pEncInfo->picHeight          = pop->picHeight;
+
+    if (pop->rotation == 90 || pop->rotation == 270) {
+        if (pEncInfo->format == FORMAT_422)      format = FORMAT_440;
+        else if (pEncInfo->format == FORMAT_440) format = FORMAT_422;
+        else                                     format = pEncInfo->format;
+        rotation_90_270 = TRUE;
+    }
+    else {
+        format = pEncInfo->format;
+    }
+
+    // Picture size alignment
+    if (format == FORMAT_420 || format == FORMAT_422) {
+        pEncInfo->alignedWidth = JPU_CEIL(16, pEncInfo->picWidth);
+        mcuWidth = 16;
+    }
+    else {
+        pEncInfo->alignedWidth = JPU_CEIL(8, pEncInfo->picWidth);
+        mcuWidth = (format == FORMAT_400) ? 32 : 8;
+    }
+
+    if (format == FORMAT_420 || format == FORMAT_440) {
+        pEncInfo->alignedHeight = JPU_CEIL(16, pEncInfo->picHeight);
+        mcuHeight = 16;
+    }
+    else {
+        pEncInfo->alignedHeight = JPU_CEIL(8, pEncInfo->picHeight);
+        mcuHeight = 8;
+    }
+
+    pEncInfo->mcuWidth  = mcuWidth;
+    pEncInfo->mcuHeight = mcuHeight;
+    if (format == FORMAT_400) {
+        if (pop->rotation == 90 || pop->rotation == 270) {
+            pEncInfo->mcuWidth  = mcuHeight;
+            pEncInfo->mcuHeight = mcuWidth;
+        }
+    }
+
+    comp0McuWidth  = pEncInfo->mcuWidth;
+    comp0McuHeight = pEncInfo->mcuHeight;
+    if (rotation_90_270 == TRUE) {
+        if (pEncInfo->format == FORMAT_420 || pEncInfo->format == FORMAT_422) {
+            comp0McuWidth = 16;
+        }
+        else  {
+            comp0McuWidth = 8;
+        }
+
+        if (pEncInfo->format == FORMAT_420 || pEncInfo->format == FORMAT_440) {
+            comp0McuHeight = 16;
+        }
+        else if (pEncInfo->format == FORMAT_400) {
+            comp0McuHeight = 32;
+        }
+        else {
+            comp0McuHeight = 8;
+        }
+    }
+
+    if (pop->sliceInstMode == TRUE) {
+        Uint32 ppuHeight = (rotation_90_270 == TRUE) ? pEncInfo->alignedWidth : pEncInfo->alignedHeight;
+        if (pop->sliceHeight % pEncInfo->mcuHeight) {
+            JpgLeaveLock();
+            return JPG_RET_INVALID_PARAM;
+        }
+
+        if (pop->sliceHeight > ppuHeight) {
+            JpgLeaveLock();
+            return JPG_RET_INVALID_PARAM;
+        }
+
+        if (pop->sliceHeight < pEncInfo->mcuHeight) {
+            JpgLeaveLock();
+            return JPG_RET_INVALID_PARAM;
+        }
+    }
+
+    pJpgInst->sliceInstMode = pop->sliceInstMode;
+    pEncInfo->rstIntval     = pop->restartInterval;
+    pEncInfo->jpg12bit      = pop->jpg12bit;
+    pEncInfo->q_prec0       = pop->q_prec0;
+    pEncInfo->q_prec1       = pop->q_prec1;
+    pEncInfo->pixelJustification = pop->pixelJustification;
+    if (pop->jpg12bit){
+        for (i=0; i<8; i++)
+            pEncInfo->pHuffVal[i] = pop->huffVal[i];
+        for (i=0; i<8; i++)
+            pEncInfo->pHuffBits[i] = pop->huffBits[i];
+    }else{
+        for (i=0; i<4; i++)
+            pEncInfo->pHuffVal[i] = pop->huffVal[i];
+        for (i=0; i<4; i++)
+            pEncInfo->pHuffBits[i] = pop->huffBits[i];
+    }
+
+    for (i=0; i<4; i++)
+        pEncInfo->pQMatTab[i] = pop->qMatTab[i];
+
+    pEncInfo->pCInfoTab[0] = sJpuCompInfoTable[2/*pEncInfo->format*/];
+    pEncInfo->pCInfoTab[1] = pEncInfo->pCInfoTab[0] + 6;
+    pEncInfo->pCInfoTab[2] = pEncInfo->pCInfoTab[1] + 6;
+    pEncInfo->pCInfoTab[3] = pEncInfo->pCInfoTab[2] + 6;
+
+    if (pop->packedFormat == PACKED_FORMAT_444 && pEncInfo->format != FORMAT_444) {
+        return JPG_RET_INVALID_PARAM;
+    }
+
+    pEncInfo->packedFormat = pop->packedFormat;
+    if (pEncInfo->format == FORMAT_400) {
+        pEncInfo->compInfo[1] = 0;
+        pEncInfo->compInfo[2] = 0;
+    }
+    else {
+        pEncInfo->compInfo[1] = 5;
+        pEncInfo->compInfo[2] = 5;
+    }
+
+    if (pEncInfo->format == FORMAT_400) {
+        pEncInfo->compNum = 1;
+    }
+    else
+        pEncInfo->compNum = 3;
+
+    if (pEncInfo->format == FORMAT_420) {
+        pEncInfo->mcuBlockNum = 6;
+    }
+    else if (pEncInfo->format == FORMAT_422) {
+        pEncInfo->mcuBlockNum = 4;
+    } else if (pEncInfo->format == FORMAT_440) { /* aka YUV440 */
+        pEncInfo->mcuBlockNum = 4;
+    } else if (pEncInfo->format == FORMAT_444) {
+        pEncInfo->mcuBlockNum = 3;
+    } else if (pEncInfo->format == FORMAT_400) {
+        Uint32 picHeight = (90 == pop->rotation || 270 == pop->rotation) ? pEncInfo->picWidth : pEncInfo->picHeight;
+        if (0 < pEncInfo->rstIntval && picHeight == pEncInfo->sliceHeight) {
+            pEncInfo->mcuBlockNum = 1;
+            comp0McuWidth         = 8;
+            comp0McuHeight        = 8;
+        }
+        else {
+            pEncInfo->mcuBlockNum = 4;
+        }
+    }
+    pEncInfo->compInfo[0] = (comp0McuWidth >> 3) << 3 | (comp0McuHeight >> 3);
+
+    pEncInfo->busReqNum = (pop->jpg12bit == FALSE) ? GetEnc8bitBusReqNum(pEncInfo->packedFormat, pEncInfo->format) :
+                                                     GetEnc12bitBusReqNum(pEncInfo->packedFormat, pEncInfo->format);
+
+
+    pEncInfo->tiledModeEnable = pop->tiledModeEnable;
+
+    pEncInfo->encIdx = 0;
+    pEncInfo->encSlicePosY = 0;
+    pEncInfo->rotationIndex = pop->rotation/90;
+    pEncInfo->mirrorIndex   = pop->mirror;
+    JpgLeaveLock();
+
+    return JPG_RET_SUCCESS;
+
+}
+
+JpgRet JPU_EncClose(JpgEncHandle handle)
+{
+    JpgInst * pJpgInst;
+    JpgRet ret;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    JpgEnterLock();
+
+    pJpgInst = handle;
+    if (GetJpgPendingInstEx(pJpgInst->instIndex)) {
+        JpgLeaveLock();
+        return JPG_RET_FRAME_NOT_COMPLETE;
+    }
+
+    FreeJpgInstance(pJpgInst);
+
+    JpgLeaveLock();
+
+    return JPG_RET_SUCCESS;
+}
+
+
+
+JpgRet JPU_EncGetBitstreamBuffer( JpgEncHandle handle,
+    PhysicalAddress * prdPtr,
+    PhysicalAddress * pwrPtr,
+    int * size)
+{
+    JpgInst * pJpgInst;
+    JpgRet ret;
+    Int32 instRegIndex;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    if ( prdPtr == 0 || pwrPtr == 0 || size == 0) {
+        return JPG_RET_INVALID_PARAM;
+    }
+
+    pJpgInst = handle;
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+
+
+    *pwrPtr = JpuReadInstReg(instRegIndex, MJPEG_BBC_WR_PTR_REG);
+    *prdPtr = JpuReadInstReg(instRegIndex, MJPEG_BBC_RD_PTR_REG);
+
+    *size = *pwrPtr - *prdPtr;
+
+    return JPG_RET_SUCCESS;
+
+}
+
+JpgRet JPU_EncUpdateBitstreamBuffer(
+    JpgEncHandle handle,
+    int size)
+{
+    JpgInst * pJpgInst;
+    JpgEncInfo * pEncInfo;
+    JpgRet ret;
+    Int32 instRegIndex;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+    pJpgInst = handle;
+
+    pEncInfo = &pJpgInst->JpgInfo->encInfo;
+    if (GetJpgPendingInstEx(pJpgInst->instIndex) == pJpgInst) {
+        if (pJpgInst->sliceInstMode == TRUE) {
+            instRegIndex = pJpgInst->instIndex;
+        }
+        else {
+            instRegIndex = 0;
+        }
+
+        pEncInfo->streamWrPtr = JpuReadInstReg(instRegIndex, MJPEG_BBC_WR_PTR_REG);
+        pEncInfo->streamRdPtr += size;
+        if ((pEncInfo->streamWrPtr >= pEncInfo->streamBufEndAddr) || (size == 0)) {	//Full Interrupt case. wrap to the start address
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_CUR_POS_REG, 0);
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_BAS_ADDR_REG, pEncInfo->streamBufStartAddr);
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_EXT_ADDR_REG, pEncInfo->streamBufStartAddr);
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_END_ADDR_REG, pEncInfo->streamBufEndAddr);
+            pEncInfo->streamRdPtr = pEncInfo->streamBufStartAddr;
+            pEncInfo->streamWrPtr = pEncInfo->streamBufStartAddr;
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_RD_PTR_REG, pEncInfo->streamRdPtr);
+            JpuWriteInstReg(instRegIndex, MJPEG_BBC_WR_PTR_REG, pEncInfo->streamWrPtr);
+        }
+    }
+    else {
+        pEncInfo->streamRdPtr = pEncInfo->streamBufStartAddr;
+        pEncInfo->streamWrPtr = pEncInfo->streamBufStartAddr;
+    }
+
+    return JPG_RET_SUCCESS;
+}
+
+
+JpgRet JPU_EncStartOneFrame(JpgEncHandle handle, JpgEncParam * param)
+{
+    JpgInst * pJpgInst;
+    JpgEncInfo * pEncInfo;
+    FrameBuffer * pBasFrame;
+    JpgRet ret;
+    Uint32 val;
+    Int32 instRegIndex;
+    BOOL bTableInfoUpdate;
+    Uint32  rotMirEnable = 0;
+    Uint32  rotMirMode   = 0;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+
+    pJpgInst = handle;
+    pEncInfo = &pJpgInst->JpgInfo->encInfo;
+
+
+    ret = CheckJpgEncParam(handle, param);
+    if (ret != JPG_RET_SUCCESS) {
+        return ret;
+    }
+
+    pBasFrame = param->sourceFrame;
+
+    JpgEnterLock();
+
+    if (GetJpgPendingInstEx(pJpgInst->instIndex) == pJpgInst) {
+        JpgLeaveLock();
+        return JPG_RET_FRAME_NOT_COMPLETE;
+    }
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+
+    JpuWriteInstReg(instRegIndex, MJPEG_INTR_MASK_REG, ((~pEncInfo->intrEnableBit) & 0x3ff));
+    JpuWriteInstReg(instRegIndex, MJPEG_SLICE_INFO_REG, pEncInfo->sliceHeight);
+    JpuWriteInstReg(instRegIndex, MJPEG_SLICE_DPB_POS_REG, pEncInfo->picHeight); // assume that the all of source buffer is available
+    JpuWriteInstReg(instRegIndex, MJPEG_SLICE_POS_REG, pEncInfo->encSlicePosY);
+    val = (0 << 16) | (pEncInfo->encSlicePosY / pEncInfo->mcuHeight);
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_SETMB_REG,val);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_CLP_INFO_REG, 0);	//off ROI enable due to not supported feature for encoder.
+
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_BAS_ADDR_REG, pEncInfo->streamBufStartAddr);
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_END_ADDR_REG, pEncInfo->streamBufEndAddr);
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_WR_PTR_REG, pEncInfo->streamWrPtr);
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_RD_PTR_REG, pEncInfo->streamRdPtr);
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_CUR_POS_REG, 0);
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_DATA_CNT_REG, JPU_GBU_SIZE / 4);	// 64 * 4 byte == 32 * 8 byte
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_EXT_ADDR_REG, pEncInfo->streamBufStartAddr);
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_INT_ADDR_REG, 0);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_BAS_ADDR_REG, pEncInfo->streamWrPtr);
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_EXT_ADDR_REG, pEncInfo->streamWrPtr);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_BPTR_REG, 0);
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_WPTR_REG, 0);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_BBSR_REG, 0);
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_CTRL_REG, 0);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_BBER_REG, ((JPU_GBU_SIZE / 4) * 2) - 1);
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_BBIR_REG, JPU_GBU_SIZE / 4);	// 64 * 4 byte == 32 * 8 byte
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_BBHR_REG, JPU_GBU_SIZE / 4);	// 64 * 4 byte == 32 * 8 byte
+
+#define DEFAULT_TDI_TAI_DATA 0x055
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_CTRL_REG, (pEncInfo->jpg12bit<<31) | (pEncInfo->q_prec0<<30) | (pEncInfo->q_prec1<<29) | (pEncInfo->tiledModeEnable<<19) |
+                                                      (DEFAULT_TDI_TAI_DATA<<7) | 0x18 | (1<<6) | (JPU_CHECK_WRITE_RESPONSE_BVALID_SIGNAL<<2));
+    JpuWriteInstReg(instRegIndex, MJPEG_SCL_INFO_REG, 0);
+
+    val = 0;
+    //PackMode[3:0]: 0(NONE), 8(PACK444), 4,5,6,7(YUYV => VYUY)
+    val = (pEncInfo->frameEndian << 6) | ((pEncInfo->chromaInterleave==0)?0:(pEncInfo->chromaInterleave==1)?2:3);
+    if (pEncInfo->packedFormat == PACKED_FORMAT_NONE) {
+        val |= (0<<5) | (0<<4) | (0<<2);
+    }
+    else if (pEncInfo->packedFormat == PACKED_FORMAT_444) {
+        val |= (1<<5) | (0<<4) | (0<<2);
+    }
+    else {
+        val |= (0<<5) | (1<<4) | ((pEncInfo->packedFormat-1)<<2);
+    }
+    val |= (pEncInfo->pixelJustification << 11);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_CONFIG_REG, val);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_RST_INTVAL_REG, pEncInfo->rstIntval);
+    if (pEncInfo->encSlicePosY == 0) {
+        JpuWriteInstReg(instRegIndex, MJPEG_RST_INDEX_REG, 0);// RST index from 0.
+        JpuWriteInstReg(instRegIndex, MJPEG_BBC_STRM_CTRL_REG, 0);// clear BBC ctrl status.
+    }
+
+    JpuWriteInstReg(instRegIndex, MJPEG_BBC_CTRL_REG, (pEncInfo->streamEndian << 1) | 1);
+    JpuWriteInstReg(instRegIndex, MJPEG_OP_INFO_REG, pEncInfo->busReqNum);
+
+
+    bTableInfoUpdate = FALSE;
+    if (pEncInfo->encSlicePosY == 0) {
+        bTableInfoUpdate = TRUE; // if sliceMode is disabled. HW process frame by frame between instances. so Huff table can be updated between instances. instances can have the different HuffTable.
+    }
+
+    if (bTableInfoUpdate == TRUE) {
+        // Load HUFFTab
+        if (pEncInfo->jpg12bit){
+            if (!JpgEncLoadHuffTab_12b(pJpgInst, instRegIndex)) {
+                JpgLeaveLock();
+                return JPG_RET_INVALID_PARAM;
+            }
+        }else{
+            if (!JpgEncLoadHuffTab(pJpgInst, instRegIndex)) {
+                JpgLeaveLock();
+                return JPG_RET_INVALID_PARAM;
+            }
+        }
+    }
+
+    bTableInfoUpdate = FALSE;
+    if (pEncInfo->encSlicePosY == 0) {
+        bTableInfoUpdate = TRUE;
+    }
+
+    if (bTableInfoUpdate == TRUE) {
+        // Load QMATTab
+        if (!JpgEncLoadQMatTab(pJpgInst, instRegIndex)) {
+            JpgLeaveLock();
+            return JPG_RET_INVALID_PARAM;
+        }
+    }
+
+
+
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_SIZE_REG, pEncInfo->alignedWidth<<16 | pEncInfo->alignedHeight);
+
+    if (pEncInfo->rotationIndex || pEncInfo->mirrorIndex) {
+        rotMirEnable = 0x10;
+        rotMirMode   = (pEncInfo->mirrorIndex << 2) | pEncInfo->rotationIndex;
+    }
+    JpuWriteInstReg(instRegIndex, MJPEG_ROT_INFO_REG, rotMirEnable | rotMirMode);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_MCU_INFO_REG, (pEncInfo->mcuBlockNum&0x0f) << 17 | (pEncInfo->compNum&0x07) << 14    |
+                                                      (pEncInfo->compInfo[0]&0x3f) << 8  | (pEncInfo->compInfo[1]&0x0f) << 4 |
+                                                      (pEncInfo->compInfo[2]&0x0f));
+
+    //JpgEncGbuResetReg
+    JpuWriteInstReg(instRegIndex, MJPEG_GBU_CTRL_REG, pEncInfo->stuffByteEnable<<3);     // stuffing "FF" data where frame end
+
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_BASE00_REG,  pBasFrame->bufY);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_BASE01_REG,  pBasFrame->bufCb);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_BASE02_REG,  pBasFrame->bufCr);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_YSTRIDE_REG, pBasFrame->stride);
+    JpuWriteInstReg(instRegIndex, MJPEG_DPB_CSTRIDE_REG, pBasFrame->strideC);
+
+
+    if (pJpgInst->loggingEnable)
+        jdi_log(JDI_LOG_CMD_PICRUN, 1, instRegIndex);
+
+
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_START_REG, (1<<JPG_ENABLE_START_PIC));
+
+    pEncInfo->encIdx++;
+
+
+    SetJpgPendingInstEx(pJpgInst, pJpgInst->instIndex);
+    if (pJpgInst->sliceInstMode == TRUE) {
+        JpgLeaveLock();
+    }
+    return JPG_RET_SUCCESS;
+}
+
+
+JpgRet JPU_EncGetOutputInfo(
+    JpgEncHandle handle,
+    JpgEncOutputInfo * info
+    )
+{
+    JpgInst * pJpgInst;
+    JpgEncInfo * pEncInfo;
+    Uint32 val;
+    Uint32 intReason;
+    JpgRet ret;
+    Int32 instRegIndex;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS) {
+        return ret;
+    }
+
+    if (info == 0) {
+        return JPG_RET_INVALID_PARAM;
+    }
+
+    pJpgInst = handle;
+    pEncInfo = &pJpgInst->JpgInfo->encInfo;
+
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        JpgEnterLock();
+    }
+    if (pJpgInst != GetJpgPendingInstEx(pJpgInst->instIndex)) {
+        JpgLeaveLock();
+        return JPG_RET_WRONG_CALL_SEQUENCE;
+    }
+
+    if (pJpgInst->sliceInstMode == TRUE) {
+        instRegIndex = pJpgInst->instIndex;
+    }
+    else {
+        instRegIndex = 0;
+    }
+
+    info->frameCycle = JpuReadInstReg(instRegIndex, MJPEG_CYCLE_INFO_REG);
+    intReason = JpuReadInstReg(instRegIndex, MJPEG_PIC_STATUS_REG);
+
+    if ((intReason & 0x4) >> 2) {
+        JpgLeaveLock();
+        return JPG_RET_WRONG_CALL_SEQUENCE;
+    }
+
+    info->encodedSliceYPos = JpuReadInstReg(instRegIndex, MJPEG_SLICE_POS_REG);
+    pEncInfo->encSlicePosY = info->encodedSliceYPos;
+    if (intReason & (1<<INT_JPU_DONE))
+        pEncInfo->encSlicePosY = 0;
+
+    pEncInfo->streamWrPtr = JpuReadInstReg(instRegIndex, MJPEG_BBC_WR_PTR_REG);
+    pEncInfo->streamRdPtr = JpuReadInstReg(instRegIndex, MJPEG_BBC_RD_PTR_REG);
+    info->bitstreamBuffer = pEncInfo->streamRdPtr;
+    info->bitstreamSize = pEncInfo->streamWrPtr - pEncInfo->streamRdPtr;
+    info->streamWrPtr = pEncInfo->streamWrPtr;
+    info->streamRdPtr = pEncInfo->streamRdPtr;
+
+    if (intReason != 0) {
+        JpuWriteInstReg(instRegIndex, MJPEG_PIC_STATUS_REG, intReason);
+
+        if (intReason & (1<<INT_JPU_SLICE_DONE))
+            info->encodeState = ENCODE_STATE_SLICE_DONE;
+        if (intReason & (1<<INT_JPU_DONE))
+            info->encodeState = ENCODE_STATE_FRAME_DONE;
+    }
+	
+#ifndef JPU_IRQ_CONTROL
+    info->encodeState = ENCODE_STATE_FRAME_DONE;
+#endif
+
+    if (pJpgInst->loggingEnable)
+        jdi_log(JDI_LOG_CMD_PICRUN, 0, instRegIndex);
+
+    JpuWriteInstReg(instRegIndex, MJPEG_PIC_START_REG, 0);
+
+    val = JpuReadReg(MJPEG_INST_CTRL_STATUS_REG);
+    val &= ~(1UL<<instRegIndex);
+    JpuWriteReg(MJPEG_INST_CTRL_STATUS_REG, val);
+
+    SetJpgPendingInstEx(0, pJpgInst->instIndex);
+
+    JpgLeaveLock();
+    return JPG_RET_SUCCESS;
+}
+
+
+JpgRet JPU_EncGiveCommand(
+    JpgEncHandle handle,
+    JpgCommand cmd,
+    void * param)
+{
+    JpgInst * pJpgInst;
+    JpgEncInfo * pEncInfo;
+    JpgRet ret;
+
+    ret = CheckJpgInstValidity(handle);
+    if (ret != JPG_RET_SUCCESS)
+        return ret;
+
+
+    pJpgInst = handle;
+    pEncInfo = &pJpgInst->JpgInfo->encInfo;
+    switch (cmd)
+    {
+    case ENC_JPG_GET_HEADER:
+        {
+            if (param == 0) {
+                return JPG_RET_INVALID_PARAM;
+            }
+
+            if (!JpgEncEncodeHeader(handle, param)) {
+                return JPG_RET_INVALID_PARAM;
+            }
+            break;
+        }
+    case SET_JPG_USE_STUFFING_BYTE_FF:
+        {
+            int enable;
+            enable = *(int *)param;
+            pEncInfo->stuffByteEnable = enable;
+            break;
+        }
+    case SET_JPG_QUALITY_FACTOR:
+        {
+            Uint32 encQualityPercentage;
+            encQualityPercentage = *(Uint32*)param;
+            JpgEncSetQualityFactor(handle, encQualityPercentage, TRUE);
+            break;
+        }
+    case ENABLE_LOGGING:
+        {
+            pJpgInst->loggingEnable = 1;
+        }
+        break;
+    case DISABLE_LOGGING:
+        {
+            pJpgInst->loggingEnable = 0;
+        }
+        break;
+
+    default:
+        return JPG_RET_INVALID_COMMAND;
+    }
+    return JPG_RET_SUCCESS;
+}

Some files were not shown because too many files changed in this diff