[PORT FROM R2] Revert "atomisp: add CSS support for atomic ISP restart"
authorTao Jing <jing.tao@intel.com>
Fri, 11 Nov 2011 08:35:06 +0000 (16:35 +0800)
committerbuildbot <buildbot@intel.com>
Mon, 19 Dec 2011 13:29:01 +0000 (05:29 -0800)
BZ: 17272

This reverts commit 5b8f28334198de27e20e0001e927dffd8fcf57bb.

Change-Id: Ie10d52ee66a88957ea870a0f75edff11d554481e
Orig-Change-Id: I68fdd2a80b0cf7f58e6abd5f254d609ad7cd32e3
Signed-off-by: Tao Jing <jing.tao@intel.com>
Reviewed-on: http://android.intel.com:8080/23893
Reviewed-by: Cohen, David A <david.a.cohen@intel.com>
Reviewed-by: Wang, Wen W <wen.w.wang@intel.com>
Reviewed-by: Zhang, Xiaolin <xiaolin.zhang@intel.com>
Tested-by: Koski, Anttu <anttu.koski@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
Reviewed-on: http://android.intel.com:8080/27998
Reviewed-by: Tuominen, TeemuX <teemux.tuominen@intel.com>
Reviewed-by: Koski, Anttu <anttu.koski@intel.com>
drivers/media/video/atomisp/atomisp_cmd.c
drivers/media/video/atomisp/atomisp_v4l2.c
drivers/media/video/atomisp/css/sh_css.c
drivers/media/video/atomisp/css/sh_css.h
drivers/media/video/atomisp/css/sh_css_internal.h
drivers/media/video/atomisp/css/sh_css_params.c
drivers/media/video/atomisp/include/atomisp/atomisp_internal.h

index 957bf64..2230f1a 100644 (file)
@@ -226,10 +226,13 @@ irqreturn_t atomisp_isr(int irq, void *dev)
            irq_infos & SH_CSS_IRQ_INFO_START_NEXT_STAGE) {
                /* Wake up sleep thread for next binary */
                signal_worker = true;
-               if (irq_infos & SH_CSS_IRQ_INFO_STATISTICS_READY)
+               if (irq_infos & SH_CSS_IRQ_INFO_STATISTICS_READY) {
                        signal_statistics = true;
-               if (irq_infos & SH_CSS_IRQ_INFO_FW_ACC_DONE)
+                       isp->isp3a_stat_ready = true;
+               }
+               if (irq_infos & SH_CSS_IRQ_INFO_FW_ACC_DONE) {
                        signal_acceleration = true;
+               }
        } else if (irq_infos & SH_CSS_IRQ_INFO_CSS_RECEIVER_ERROR) {
                /* handle mipi receiver error*/
                u32 rx_infos;
@@ -809,8 +812,24 @@ timeout_handle:
 
                        /* proc interrupt */
                        INIT_COMPLETION(isp->wq_frame_complete);
-                       if (irq_infos & SH_CSS_IRQ_INFO_START_NEXT_STAGE)
+                       if (irq_infos & SH_CSS_IRQ_INFO_START_NEXT_STAGE) {
                                sh_css_start_next_stage();
+
+                               /* Getting 3A statistics if ready */
+                               if (isp->isp3a_stat_ready) {
+                                       mutex_lock(&isp->isp3a_lock);
+                                       ret = sh_css_get_3a_statistics
+                                               (isp->params.s3a_output_buf);
+                                       mutex_unlock(&isp->isp3a_lock);
+
+                                       isp->isp3a_stat_ready = false;
+                                       if (ret != sh_css_success)
+                                               v4l2_err(&atomisp_dev,
+                                                       "get 3a statistics"
+                                                       " failed, not "
+                                                       "enough memory.\n");
+                               }
+                       }
                } while (!(irq_infos & SH_CSS_IRQ_INFO_FRAME_DONE));
 
                mutex_unlock(&isp->isp_lock);
@@ -1939,13 +1958,10 @@ int atomisp_3a_stat(struct atomisp_device *isp, int flag,
                   sizeof(isp->params.curr_grid_info)) != 0)
                return -EAGAIN;
 
-       ret = sh_css_get_3a_statistics(isp->params.s3a_output_buf);
-       if (ret) {
-               v4l2_err(&atomisp_dev, "failed to get 3A statistics\n");
-               return -EFAULT;
-       }
+       mutex_lock(&isp->isp3a_lock);
        ret = copy_to_user(arg->data, isp->params.s3a_output_buf,
                           isp->params.s3a_output_bytes);
+       mutex_unlock(&isp->isp3a_lock);
        if (ret) {
                v4l2_err(&atomisp_dev,
                            "copy to user failed: copied %lu bytes\n", ret);
index 47a8567..a51efba 100644 (file)
@@ -828,7 +828,9 @@ static int __devinit atomisp_pci_probe(struct pci_dev *dev,
        mutex_init(&isp->input_lock);
        /* isp_lock is to protect race access of css functions */
        mutex_init(&isp->isp_lock);
+       mutex_init(&isp->isp3a_lock);
        isp->sw_contex.updating_uptr = false;
+       isp->isp3a_stat_ready = false;
 
        pci_set_drvdata(dev, isp);
 
index f999679..18e2b9e 100644 (file)
@@ -1897,10 +1897,8 @@ sh_css_translate_interrupt(unsigned int *irq_infos)
                                infos |= SH_CSS_IRQ_INFO_FRAME_DONE;
                        else
                                infos |= SH_CSS_IRQ_INFO_START_NEXT_STAGE;
-                       if (sh_css_statistics_ready()) {
+                       if (sh_css_statistics_ready())
                                infos |= SH_CSS_IRQ_INFO_STATISTICS_READY;
-                               sh_css_params_swap_3a_buffers();
-                       }
                        if (acceleration_done())
                                infos |= SH_CSS_IRQ_INFO_FW_ACC_DONE;
                        my_css.state = sh_css_state_idle;
@@ -3011,16 +3009,6 @@ sh_css_preview_get_grid_info(struct sh_css_grid_info *info)
        return err;
 }
 
-bool
-sh_css_preview_next_stage_needs_alloc(void)
-{
-       return my_css.invalidate ||
-              my_css.preview_settings.pipeline.reload ||
-              my_css.preview_settings.zoom_changed ||
-              my_css.preview_settings.preview_binary.info == NULL ||
-              my_css.preview_settings.shading_table == NULL;
-}
-
 static void
 init_video_descr(struct sh_css_frame_info *in_info,
                 struct sh_css_frame_info *vf_info)
@@ -3371,16 +3359,6 @@ sh_css_video_get_dis_envelope(unsigned int *width, unsigned int *height)
        *height = my_css.video_settings.dvs_envelope_height;
 }
 
-bool
-sh_css_video_next_stage_needs_alloc(void)
-{
-       return my_css.invalidate ||
-              my_css.video_settings.pipeline.reload ||
-              my_css.video_settings.zoom_changed ||
-              my_css.video_settings.video_binary.info == NULL ||
-              my_css.video_settings.shading_table == NULL;
-}
-
 void
 sh_css_set_zoom_factor(unsigned int dx, unsigned int dy)
 {
@@ -4277,24 +4255,6 @@ sh_css_capture_enable_online(bool enable)
        my_css.capture_settings.online = enable;
 }
 
-bool
-sh_css_capture_next_stage_needs_alloc(void)
-{
-       struct sh_css_binary *main_binary;
-
-       main_binary = &my_css.capture_settings.primary_binary;
-       if (my_css.capture_settings.mode == SH_CSS_CAPTURE_MODE_RAW)
-               main_binary = &my_css.capture_settings.copy_binary;
-       else if (my_css.capture_settings.mode == SH_CSS_CAPTURE_MODE_ADVANCED)
-               main_binary = &my_css.capture_settings.pre_isp_binary;
-
-       return my_css.invalidate ||
-              my_css.capture_settings.pipeline.reload ||
-              my_css.capture_settings.zoom_changed ||
-              main_binary->info == NULL ||
-              my_css.capture_settings.shading_table == NULL;
-}
-
 enum sh_css_err
 sh_css_histogram_allocate(unsigned int num_elements,
                          struct sh_css_histogram **histogram)
index c6155d3..0d04a4b 100644 (file)
@@ -356,16 +356,6 @@ sh_css_preview_get_input_resolution(unsigned int *width,
 enum sh_css_err
 sh_css_preview_configure_pp_input(unsigned int width, unsigned int height);
 
-/* Return whether the next preview stage (or first stage of next
-   frame) needs to perform memory allocation or not.
-   This can be used to determine whether the next stage can be
-   started from an atomic context.
-   Since no CSS functionality can ever perform blocking operations,
-   memory allocation is the only thing that would not allow us to
-   start the next stage from an atomic context. */
-bool
-sh_css_preview_next_stage_needs_alloc(void);
-
 /* ===== CAPTURE ===== */
 
 /* Start the ISP in capture mode:
@@ -443,11 +433,6 @@ sh_css_capture_get_grid_info(struct sh_css_grid_info *info);
 enum sh_css_err
 sh_css_capture_get_input_resolution(unsigned int *width,
                                    unsigned int *height);
-
-/* See comments for sh_css_preview_next_stage_needs_alloc() */
-bool
-sh_css_capture_next_stage_needs_alloc(void);
-
 /* ===== VIDEO ===== */
 
 /* Start the video ISP for one frame:
@@ -512,10 +497,6 @@ enum sh_css_err
 sh_css_video_get_input_resolution(unsigned int *width,
                                  unsigned int *height);
 
-/* See comments for sh_css_preview_next_stage_needs_alloc() */
-bool
-sh_css_video_next_stage_needs_alloc(void);
-
 /* Generate a luminance histogram from a frame. The width of the frame
  * cannot exceed 640 pixels and the frame must be a yuv420 frame.
  */
index b037f51..1e18ce0 100644 (file)
@@ -286,12 +286,6 @@ sh_css_params_write_to_ddr(const struct sh_css_binary *binary_info);
 void
 sh_css_params_set_current_binary(const struct sh_css_binary *binary);
 
-/* swap 3a double buffers. This should be called when handling an
-   interrupt that indicates that statistics are ready.
-   This also swaps the DIS buffers. */
-void
-sh_css_params_swap_3a_buffers(void);
-
 enum sh_css_err
 sh_css_params_init(void);
 
index d09d4a4..f8344e2 100644 (file)
@@ -137,14 +137,6 @@ static size_t fpn_tbl_size,
              tetra_ratb_x_size,
              tetra_ratb_y_size;
 
-/* Double buffering for 3A */
-static void *s3a_tables[2],
-           *s3a_tables_hi[2],
-           *s3a_tables_lo[2],
-           *dis_hor_projections[2],
-           *dis_ver_projections[2];
-static unsigned int curr_valid_buffer;
-
 /* local buffers, used to re-order the 3a statistics in vmem-format */
 static unsigned short s3a_tbl_hi_buf[ISP_S3ATBL_HI_LO_STRIDE *
                                     SH_CSS_MAX_BQ_GRID_HEIGHT],
@@ -647,8 +639,8 @@ sh_css_get_dis_projections(int *horizontal_projections,
                     hor_num_3a, ver_num_3a, i;
        int *hor_ptr_3a  = horizontal_projections,
            *ver_ptr_3a  = vertical_projections,
-           *hor_ptr_isp = dis_hor_projections[curr_valid_buffer],
-           *ver_ptr_isp = dis_ver_projections[curr_valid_buffer];
+           *hor_ptr_isp = ddr_ptrs.sdis_hor_proj,
+           *ver_ptr_isp = ddr_ptrs.sdis_ver_proj;
 
        if (current_3a_binary == NULL)
                return;
@@ -679,7 +671,7 @@ get_3a_stats_from_dmem(struct sh_css_3a_output *output)
                        out_height = current_3a_binary->s3atbl_height,
                        i;
        struct sh_css_3a_output
-                       *ddr_ptr = s3a_tables[curr_valid_buffer],
+                       *ddr_ptr = ddr_ptrs.s3a_tbl,
                        *out_ptr = output;
 
        for (i = 0; i < out_height; i++) {
@@ -713,8 +705,8 @@ get_3a_stats_from_vmem(struct sh_css_3a_output *output)
        chunk = max(chunk, 1);
        bytes = ISP_S3ATBL_HI_LO_STRIDE_BYTES * out_height;
 
-       hrt_isp_css_mm_load(s3a_tables_hi[curr_valid_buffer], hi, bytes);
-       hrt_isp_css_mm_load(s3a_tables_lo[curr_valid_buffer], lo, bytes);
+       hrt_isp_css_mm_load(ddr_ptrs.s3a_tbl_hi, hi, bytes);
+       hrt_isp_css_mm_load(ddr_ptrs.s3a_tbl_lo, lo, bytes);
 
        for (y = 0; y < out_height; y++) {
                elm_start = y * ISP_S3ATBL_HI_LO_STRIDE;
@@ -1613,37 +1605,21 @@ reallocate_buffers(const struct sh_css_binary *binary)
                                             SCTBL_BYTES(binary), &err);
        }
        if (binary->info->enable_s3a && binary->info->s3atbl_use_dmem) {
-               unsigned int size = s3a_tbl_size;
-               changed |= reallocate_cached_buffer(&s3a_tables[0],
-                                                   &size,
-                                                   S3ATBL_BYTES(binary), &err);
-               changed |= reallocate_cached_buffer(&s3a_tables[1],
+               changed |= reallocate_cached_buffer(&ddr_ptrs.s3a_tbl,
                                                    &s3a_tbl_size,
                                                    S3ATBL_BYTES(binary), &err);
        }
        if (binary->info->enable_s3a && !binary->info->s3atbl_use_dmem) {
-               unsigned int hi_size = s3a_tbl_hi_size,
-                            lo_size = s3a_tbl_lo_size;
-               changed |= reallocate_cached_buffer(&s3a_tables_hi[0],
-                                                   &hi_size,
-                                                   S3ATBL_HI_LO_BYTES(binary),
-                                                   &err);
-               changed |= reallocate_cached_buffer(&s3a_tables_hi[1],
+               changed |= reallocate_cached_buffer(&ddr_ptrs.s3a_tbl_hi,
                                                    &s3a_tbl_hi_size,
                                                    S3ATBL_HI_LO_BYTES(binary),
                                                    &err);
-               changed |= reallocate_cached_buffer(&s3a_tables_lo[0],
-                                                   &lo_size,
-                                                   S3ATBL_HI_LO_BYTES(binary),
-                                                   &err);
-               changed |= reallocate_cached_buffer(&s3a_tables_lo[1],
+               changed |= reallocate_cached_buffer(&ddr_ptrs.s3a_tbl_lo,
                                                    &s3a_tbl_lo_size,
                                                    S3ATBL_HI_LO_BYTES(binary),
                                                    &err);
        }
        if (binary->info->enable_dis) {
-               unsigned int hor_size = sdis_hor_proj_size,
-                            ver_size = sdis_ver_proj_size;
                changed |= reallocate_buffer(&ddr_ptrs.sdis_hor_coef,
                                             &sdis_hor_coef_size,
                                             SDIS_HOR_COEF_TBL_BYTES(binary),
@@ -1652,19 +1628,11 @@ reallocate_buffers(const struct sh_css_binary *binary)
                                             &sdis_ver_coef_size,
                                             SDIS_VER_COEF_TBL_BYTES(binary),
                                             &err);
-               changed |= reallocate_buffer(&dis_hor_projections[0],
-                                            &hor_size,
-                                            SDIS_HOR_PROJ_TBL_BYTES(binary),
-                                            &err);
-               changed |= reallocate_buffer(&dis_hor_projections[1],
+               changed |= reallocate_buffer(&ddr_ptrs.sdis_hor_proj,
                                             &sdis_hor_proj_size,
                                             SDIS_HOR_PROJ_TBL_BYTES(binary),
                                             &err);
-               changed |= reallocate_buffer(&dis_ver_projections[0],
-                                            &ver_size,
-                                            SDIS_VER_PROJ_TBL_BYTES(binary),
-                                            &err);
-               changed |= reallocate_buffer(&dis_ver_projections[1],
+               changed |= reallocate_buffer(&ddr_ptrs.sdis_ver_proj,
                                             &sdis_ver_proj_size,
                                             SDIS_VER_PROJ_TBL_BYTES(binary),
                                             &err);
@@ -1712,12 +1680,6 @@ reallocate_buffers(const struct sh_css_binary *binary)
        return err;
 }
 
-void
-sh_css_params_swap_3a_buffers(void)
-{
-       curr_valid_buffer = 1-curr_valid_buffer;
-}
-
 enum sh_css_err
 sh_css_params_init(void)
 {
@@ -1759,6 +1721,7 @@ sh_css_params_init(void)
                return sh_css_err_cannot_allocate_memory;
        }
        /* Copy XMEM address map to XMEM for SP access */
+       hrt_isp_css_mm_store(sp_ddr_ptrs, &ddr_ptrs, sizeof(ddr_ptrs));
        sh_css_set_3a_config(&default_3a_config);
        sh_css_set_wb_config(&default_wb_config);
        sh_css_set_cc_config(&default_cc_config);
@@ -1780,7 +1743,6 @@ sh_css_params_init(void)
        morph_table_changed = true;
        sc_table = NULL;
        sc_table_changed = false;
-       curr_valid_buffer = 0;
        return sh_css_success;
 }
 
@@ -1806,18 +1768,13 @@ sh_css_params_uninit(void)
        safe_free(ddr_ptrs.macc_tbl);
        safe_free(ddr_ptrs.fpn_tbl);
        safe_free(ddr_ptrs.sc_tbl);
-       safe_free(s3a_tables[0]);
-       safe_free(s3a_tables[1]);
-       safe_free(s3a_tables_hi[0]);
-       safe_free(s3a_tables_hi[1]);
-       safe_free(s3a_tables_lo[0]);
-       safe_free(s3a_tables_lo[1]);
-       safe_free(dis_hor_projections[0]);
-       safe_free(dis_hor_projections[1]);
-       safe_free(dis_ver_projections[0]);
-       safe_free(dis_ver_projections[1]);
+       safe_free(ddr_ptrs.s3a_tbl);
+       safe_free(ddr_ptrs.s3a_tbl_hi);
+       safe_free(ddr_ptrs.s3a_tbl_lo);
        safe_free(ddr_ptrs.sdis_hor_coef);
        safe_free(ddr_ptrs.sdis_ver_coef);
+       safe_free(ddr_ptrs.sdis_hor_proj);
+       safe_free(ddr_ptrs.sdis_ver_proj);
        safe_free(ddr_ptrs.tetra_r_x);
        safe_free(ddr_ptrs.tetra_r_y);
        safe_free(ddr_ptrs.tetra_gr_x);
@@ -1908,21 +1865,11 @@ enum sh_css_err
 sh_css_params_write_to_ddr(const struct sh_css_binary *binary)
 {
        enum sh_css_err err;
-       unsigned int free_buffer = 1-curr_valid_buffer;
 
        err = reallocate_buffers(binary);
        if (err != sh_css_success)
                return err;
 
-       /* Make sure the SP firmware uses the right (free) buffer */
-       ddr_ptrs.s3a_tbl       = s3a_tables[free_buffer];
-       ddr_ptrs.s3a_tbl_hi    = s3a_tables_hi[free_buffer];
-       ddr_ptrs.s3a_tbl_lo    = s3a_tables_lo[free_buffer];
-       ddr_ptrs.sdis_hor_proj = dis_hor_projections[free_buffer];
-       ddr_ptrs.sdis_ver_proj = dis_ver_projections[free_buffer];
-
-       hrt_isp_css_mm_store(sp_ddr_ptrs, &ddr_ptrs, sizeof(ddr_ptrs));
-
        if (fpn_table_changed && binary->info->enable_fpnr) {
                if (isp_parameters.fpn_enabled) {
                        store_fpntbl(ddr_ptrs.fpn_tbl);
@@ -2134,8 +2081,8 @@ sh_css_get_isp_dis_projections(int *horizontal_projections,
        unsigned int hor_num_isp, ver_num_isp, i;
        int *hor_ptr     = horizontal_projections,
            *ver_ptr     = vertical_projections,
-           *hor_ptr_isp = dis_hor_projections[curr_valid_buffer],
-           *ver_ptr_isp = dis_ver_projections[curr_valid_buffer];
+           *hor_ptr_isp = ddr_ptrs.sdis_hor_proj,
+           *ver_ptr_isp = ddr_ptrs.sdis_ver_proj;
 
        if (current_3a_binary == NULL)
                return;
@@ -2160,7 +2107,7 @@ void *
 sh_css_store_sp_group_to_ddr(void)
 {
        hrt_isp_css_mm_store(xmem_sp_group_ptrs,
-                            &sh_css_sp_group,
-                            sizeof(struct sh_css_sp_group));
+                                    &sh_css_sp_group,
+                                    sizeof(struct sh_css_sp_group));
        return xmem_sp_group_ptrs;
 }
index 2ab7842..d7b9f4a 100644 (file)
@@ -252,7 +252,9 @@ struct atomisp_device {
        uint32_t irq_infos;
        struct mutex input_lock;
        struct mutex isp_lock;
+       struct mutex isp3a_lock;
        struct atomisp_tvnorm *tvnorm;
+       bool isp3a_stat_ready;
 
        struct atomisp_video_pipe_format *main_format;
        struct atomisp_video_pipe_format *vf_format;