diff --git a/drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver1.c b/drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver1.c index 9924c07d43..07447c5a7a 100644 --- a/drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver1.c +++ b/drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver1.c @@ -3968,58 +3968,49 @@ static int cam_ife_csid_ver1_rx_bottom_half_handler( evt_payload->irq_status[CAM_IFE_CSID_IRQ_REG_RX]); if (irq_status) { - len += scnprintf(log_buf, CAM_IFE_CSID_LOG_BUF_LEN - len, - "Fatal Errors:\n"); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "Fatal Errors:\n"); if (irq_status & IFE_CSID_VER1_RX_LANE0_FIFO_OVERFLOW) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "RX_ERROR_LANE0_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n", soc_info->applied_src_clk_rate); if (irq_status & IFE_CSID_VER1_RX_LANE1_FIFO_OVERFLOW) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "RX_ERROR_LANE1_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n", soc_info->applied_src_clk_rate); if (irq_status & IFE_CSID_VER1_RX_LANE2_FIFO_OVERFLOW) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "RX_ERROR_LANE2_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n", soc_info->applied_src_clk_rate); if (irq_status & IFE_CSID_VER1_RX_LANE3_FIFO_OVERFLOW) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "RX_ERROR_LANE3_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n", soc_info->applied_src_clk_rate); if (irq_status & IFE_CSID_VER1_RX_TG_FIFO_OVERFLOW) { event_type |= CAM_ISP_HW_ERROR_CSID_FIFO_OVERFLOW; - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "RX_ERROR_TPG_FIFO_OVERFLOW: Backpressure from IFE\n"); } if (irq_status & IFE_CSID_VER1_RX_CPHY_PH_CRC) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "CPHY_PH_CRC: Pkt Hdr CRC mismatch\n"); if (irq_status & IFE_CSID_VER1_RX_STREAM_UNDERFLOW) { val = cam_io_r_mb(soc_info->reg_map[0].mem_base + csi2_reg->captured_long_pkt_0_addr); - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "ERROR_STREAM_UNDERFLOW: Fewer bytes rcvd than WC:%d in pkt hdr\n", val & 0xFFFF); } if (irq_status & IFE_CSID_VER1_RX_ERROR_ECC) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "DPHY_ERROR_ECC: Pkt hdr errors unrecoverable\n"); } @@ -4027,30 +4018,26 @@ static int cam_ife_csid_ver1_rx_bottom_half_handler( csi2_reg->part_fatal_err_mask; if (irq_status) { - len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "Recoverable-errors:\n"); if (irq_status & IFE_CSID_VER1_RX_CPHY_EOT_RECEPTION) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "CPHY_EOT_RECEPTION: No EOT on lane/s, is_EPD: %d, PHY_Type: %s(%u)\n", csid_hw->rx_cfg.epd_supported, (csid_hw->rx_cfg.lane_type) ? "cphy" : "dphy", csid_hw->rx_cfg.lane_type); if (irq_status & IFE_CSID_VER1_RX_CPHY_SOT_RECEPTION) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "CPHY_SOT_RECEPTION: Less SOTs on lane/s\n"); if (irq_status & IFE_CSID_VER1_RX_ERROR_CRC) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "CPHY_ERROR_CRC: Long pkt payload CRC mismatch\n"); if (irq_status & IFE_CSID_VER1_RX_UNBOUNDED_FRAME) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "UNBOUNDED_FRAME: Frame started with EOF or No EOF\n"); } @@ -4058,14 +4045,13 @@ static int cam_ife_csid_ver1_rx_bottom_half_handler( csi2_reg->non_fatal_err_mask; if (irq_status) { - len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "Non-fatal errors:\n"); if (irq_status & IFE_CSID_VER1_RX_MMAPPED_VC_DT) { val = cam_io_r_mb(soc_info->reg_map[0].mem_base + csi2_reg->captured_long_pkt_0_addr); - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "MMAPPED_VC_DT: VC:%d DT:%d mapped to more than 1 csid paths\n", (val >> 22), ((val >> 16) & 0x3F)); } @@ -4115,8 +4101,7 @@ static int cam_ife_csid_ver1_path_bottom_half_handler( while (irq_status) { if ((irq_status & 0x1)) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "%s\n", ver1_path_irq_desc[bit_pos]); bit_pos++; irq_status >>= 1; diff --git a/drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver2.c b/drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver2.c index a7ad82bf64..991dcd9a6e 100644 --- a/drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver2.c +++ b/drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver2.c @@ -882,7 +882,7 @@ static int cam_ife_csid_ver2_rx_err_bottom_half( uint8_t *log_buf = NULL; uint32_t irq_status; uint32_t rx_irq_status = 0; - uint32_t len = 0; + size_t len = 0; uint32_t val = 0; uint32_t event_type = 0; bool fatal_err_detected = false; @@ -907,52 +907,45 @@ static int cam_ife_csid_ver2_rx_err_bottom_half( csi2_reg->fatal_err_mask; if (irq_status) { - len += scnprintf(log_buf, CAM_IFE_CSID_LOG_BUF_LEN - len, - "Fatal Errors:\n"); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "Fatal Errors:"); if (irq_status & IFE_CSID_VER2_RX_LANE0_FIFO_OVERFLOW) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "RX_ERROR_LANE0_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n", + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "RX_ERROR_LANE0_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz", soc_info->applied_src_clk_rate); if (irq_status & IFE_CSID_VER2_RX_LANE1_FIFO_OVERFLOW) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "RX_ERROR_LANE1_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n", + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "RX_ERROR_LANE1_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz", soc_info->applied_src_clk_rate); if (irq_status & IFE_CSID_VER2_RX_LANE2_FIFO_OVERFLOW) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "RX_ERROR_LANE2_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n", + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "RX_ERROR_LANE2_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz", soc_info->applied_src_clk_rate); if (irq_status & IFE_CSID_VER2_RX_LANE3_FIFO_OVERFLOW) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "RX_ERROR_LANE3_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n", + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "RX_ERROR_LANE3_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz", soc_info->applied_src_clk_rate); if (irq_status & IFE_CSID_VER2_RX_ERROR_CPHY_PH_CRC) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "CPHY_PH_CRC: Pkt Hdr CRC mismatch\n"); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "CPHY_PH_CRC: Pkt Hdr CRC mismatch"); if (irq_status & IFE_CSID_VER2_RX_STREAM_UNDERFLOW) { val = cam_io_r_mb(soc_info->reg_map[0].mem_base + csi2_reg->captured_long_pkt_0_addr); - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "ERROR_STREAM_UNDERFLOW: Fewer bytes rcvd than WC:%d in pkt hdr\n", + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "ERROR_STREAM_UNDERFLOW: Fewer bytes rcvd than WC:%d in pkt hdr", val & 0xFFFF); } if (irq_status & IFE_CSID_VER2_RX_ERROR_ECC) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "DPHY_ERROR_ECC: Pkt hdr errors unrecoverable\n"); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "DPHY_ERROR_ECC: Pkt hdr errors unrecoverable"); rx_irq_status |= irq_status; fatal_err_detected = true; @@ -962,31 +955,27 @@ static int cam_ife_csid_ver2_rx_err_bottom_half( csi2_reg->part_fatal_err_mask; if (irq_status) { - len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len, - "Recoverable-errors:\n"); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "Recoverable-errors:"); if (irq_status & IFE_CSID_VER2_RX_CPHY_EOT_RECEPTION) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "CPHY_EOT_RECEPTION: No EOT on lane/s, is_EPD: %d, PHY_Type: %s(%u) \n", + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "CPHY_EOT_RECEPTION: No EOT on lane/s, is_EPD: %d, PHY_Type: %s(%u) ", csid_hw->rx_cfg.epd_supported, (csid_hw->rx_cfg.lane_type) ? "cphy" : "dphy", csid_hw->rx_cfg.lane_type); if (irq_status & IFE_CSID_VER2_RX_CPHY_SOT_RECEPTION) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "CPHY_SOT_RECEPTION: Less SOTs on lane/s\n"); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "CPHY_SOT_RECEPTION: Less SOTs on lane/s"); if (irq_status & IFE_CSID_VER2_RX_ERROR_CRC) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "CPHY_ERROR_CRC: Long pkt payload CRC mismatch\n"); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "CPHY_ERROR_CRC: Long pkt payload CRC mismatch"); if (irq_status & IFE_CSID_VER2_RX_UNBOUNDED_FRAME) - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "UNBOUNDED_FRAME: Frame started with EOF or No EOF\n"); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "UNBOUNDED_FRAME: Frame started with EOF or No EOF"); rx_irq_status |= irq_status; fatal_err_detected = true; @@ -996,16 +985,15 @@ static int cam_ife_csid_ver2_rx_err_bottom_half( csi2_reg->non_fatal_err_mask; if (irq_status) { - len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len, - "Non-fatal-errors:\n"); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "Non-fatal-errors:"); if (irq_status & IFE_CSID_VER2_RX_MMAPPED_VC_DT) { val = cam_io_r_mb(soc_info->reg_map[0].mem_base + csi2_reg->captured_long_pkt_0_addr); - len += scnprintf(log_buf + len, - CAM_IFE_CSID_LOG_BUF_LEN - len, - "MMAPPED_VC_DT: VC:%d DT:%d mapped to more than 1 csid paths\n", + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, + "MMAPPED_VC_DT: VC:%d DT:%d mapped to more than 1 csid paths", (val >> 22), ((val >> 16) & 0x3F)); } } @@ -1104,7 +1092,7 @@ static int cam_ife_csid_ver2_parse_path_irq_status( uint32_t bit_pos = 0; uint32_t status; uint32_t sof_irq_debug_en = 0; - uint32_t len = 0; + size_t len = 0; uint8_t *log_buf = NULL; log_buf = csid_hw->log_buf; @@ -1115,8 +1103,8 @@ static int cam_ife_csid_ver2_parse_path_irq_status( status = irq_status & err_mask; while (status) { if (status & 0x1 ) - len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len, - "\n%s", ver2_path_irq_desc[bit_pos].desc); + CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "%s", + ver2_path_irq_desc[bit_pos].desc); bit_pos++; status >>= 1; } diff --git a/drivers/cam_isp/isp_hw_mgr/isp_hw/sfe_hw/sfe_top/cam_sfe_top.c b/drivers/cam_isp/isp_hw_mgr/isp_hw/sfe_hw/sfe_top/cam_sfe_top.c index 3033b02592..ba4e51c9d6 100644 --- a/drivers/cam_isp/isp_hw_mgr/isp_hw/sfe_hw/sfe_top/cam_sfe_top.c +++ b/drivers/cam_isp/isp_hw_mgr/isp_hw/sfe_hw/sfe_top/cam_sfe_top.c @@ -389,7 +389,8 @@ static void cam_sfe_top_check_module_status( const struct cam_sfe_top_debug_info status_list[][8]) { bool found = false; - uint32_t i, j, val = 0, len = 0; + uint32_t i, j, val = 0; + size_t len = 0; uint8_t log_buf[1024]; if (!status_list) @@ -406,11 +407,9 @@ static void cam_sfe_top_check_module_status( if (val == 0 || val == 5) continue; - len += scnprintf(log_buf + len, 1024 - - len, "\nCAM_INFO: %s [I:%u V:%u R:%u]", + CAM_INFO_BUF(CAM_SFE, log_buf, 1024, &len, "%s [I:%u V:%u R:%u]", status_list[i][j].clc_name, - ((val >> 2) & 1), ((val >> 1) & 1), - (val & 1)); + ((val >> 2) & 1), ((val >> 1) & 1), (val & 1)); found = true; } if (found) diff --git a/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_top_ver4.c b/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_top_ver4.c index 0f98d3c5eb..7ab8352f5a 100644 --- a/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_top_ver4.c +++ b/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_top_ver4.c @@ -852,7 +852,8 @@ static void cam_vfe_top_ver4_check_module_status( const struct cam_vfe_top_debug_info status_list[][8]) { bool found = false; - uint32_t i, j, val = 0, len = 0; + uint32_t i, j, val = 0; + size_t len = 0; uint8_t log_buf[1024]; if (!status_list) @@ -869,10 +870,9 @@ static void cam_vfe_top_ver4_check_module_status( if (val == 0 || val == 5) continue; - len += scnprintf(log_buf + len, 1024 - - len, "\nCAM_INFO: %s [I:%u V:%u R:%u]", - status_list[i][j].clc_name, ((val >> 2) & 1), - ((val >> 1) & 1), (val & 1)); + CAM_INFO_BUF(CAM_ISP, log_buf, 1024, &len, "%s [I:%u V:%u R:%u]", + status_list[i][j].clc_name, + ((val >> 2) & 1), ((val >> 1) & 1), (val & 1)); found = true; } if (found) @@ -889,7 +889,8 @@ static void cam_vfe_top_ver4_print_debug_reg_status( struct cam_vfe_top_ver4_reg_offset_common *common_reg; uint32_t val = 0; uint32_t num_reg = 0; - uint32_t i = 0, j, len = 0; + uint32_t i = 0, j; + size_t len = 0; uint8_t *log_buf; uint32_t *reg_val = NULL; struct cam_hw_soc_info *soc_info; @@ -908,17 +909,14 @@ static void cam_vfe_top_ver4_print_debug_reg_status( return; while (i < num_reg) { - len += scnprintf(log_buf + len, CAM_VFE_LEN_LOG_BUF - len, - "VFE[%u]: Top Debug Status", - soc_info->index); for(j = 0; j < 4 && i < num_reg; j++, i++) { val = cam_io_r(base + common_reg->top_debug[i]); reg_val[i] = val; - len += scnprintf(log_buf + len, CAM_VFE_LEN_LOG_BUF - - len, "\nstatus %2d : 0x%08x", i, val); + CAM_INFO_BUF(CAM_ISP, log_buf, CAM_VFE_LEN_LOG_BUF, &len, + "status %2d : 0x%08x", i, val); } - CAM_INFO(CAM_ISP, "%s", log_buf); + CAM_INFO(CAM_ISP, "VFE[%u]: Top Debug Status: %s", soc_info->index, log_buf); len = 0; memset(log_buf, 0, sizeof(uint8_t)*CAM_VFE_LEN_LOG_BUF); } diff --git a/drivers/cam_utils/cam_debug_util.c b/drivers/cam_utils/cam_debug_util.c index dad0a25a05..87a5aa526d 100644 --- a/drivers/cam_utils/cam_debug_util.c +++ b/drivers/cam_utils/cam_debug_util.c @@ -257,58 +257,66 @@ const char *cam_get_tag_name(unsigned int tag_id) return name; } -void cam_debug_log(unsigned int module_id, unsigned int priority, - const char *func, const int line, const char *fmt, ...) +static inline void __cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, + unsigned int tag, unsigned int module_id, const char *func, const int line, + const bool is_final_print, const char *fmt, va_list args) +{ + size_t buf_len = *len; + + if (is_final_print) + buf_len += scnprintf(buf + buf_len, (buf_size - buf_len), "%s: %s: %s: %d: ", + cam_get_tag_name(tag), cam_get_module_name(module_id), func, line); + else + buf_len += scnprintf(buf + buf_len, (buf_size - buf_len), "\n%-8s: %s:\t", + cam_get_tag_name(tag), cam_get_module_name(module_id)); + buf_len += vscnprintf(buf + buf_len, (buf_size - buf_len), fmt, args); + + *len = buf_len; +} + +void cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, unsigned int tag, + unsigned int module_id, const char *fmt, ...) { va_list args; va_start(args, fmt); - - if ((debug_mdl & module_id) && (priority >= debug_priority)) { - char str_buffer[STR_BUFFER_MAX_LENGTH]; - - vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args); - - if ((debug_type == 0) || (debug_type == 2)) { - pr_info("CAM_DBG: %s: %s: %d: %s\n", - cam_get_module_name(module_id), - func, line, str_buffer); - } - - if ((debug_type == 1) || (debug_type == 2)) { - char trace_buffer[STR_BUFFER_MAX_LENGTH]; - - snprintf(trace_buffer, sizeof(trace_buffer), - "%s: %s: %s: %d: %s", - cam_get_tag_name(CAM_TYPE_DBG), - cam_get_module_name(module_id), - func, line, str_buffer); - trace_cam_log_debug(trace_buffer); - } - } - + __cam_print_to_buffer(buf, buf_size, len, tag, module_id, "", 0, false, fmt, args); va_end(args); } +void cam_debug_log(unsigned int module_id, unsigned int priority, + const char *func, const int line, const char *fmt, ...) +{ + if ((debug_mdl & module_id) && (priority >= debug_priority)) { + char str_buf[STR_BUFFER_MAX_LENGTH]; + size_t len = 0; + va_list args; + + va_start(args, fmt); + __cam_print_to_buffer(str_buf, STR_BUFFER_MAX_LENGTH, &len, CAM_TYPE_DBG, module_id, + func, line, true, fmt, args); + + if ((debug_type == 0) || (debug_type == 2)) + pr_info("%s\n", str_buf); + if ((debug_type == 1) || (debug_type == 2)) + trace_cam_log_debug(str_buf); + + va_end(args); + } +} + void cam_debug_trace(unsigned int tag, unsigned int module_id, const char *func, const int line, const char *fmt, ...) { - char str_buffer[STR_BUFFER_MAX_LENGTH]; - va_list args; - if ((tag == CAM_TYPE_TRACE) || (debug_type == 1) || (debug_type == 2)) { - char trace_buffer[STR_BUFFER_MAX_LENGTH]; + char str_buf[STR_BUFFER_MAX_LENGTH]; + size_t len = 0; + va_list args; va_start(args, fmt); - - vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args); - - snprintf(trace_buffer, sizeof(trace_buffer), - "%s: %s: %s: %d: %s", - cam_get_tag_name(tag), cam_get_module_name(module_id), - func, line, str_buffer); - trace_cam_log_debug(trace_buffer); - + __cam_print_to_buffer(str_buf, STR_BUFFER_MAX_LENGTH, &len, CAM_TYPE_TRACE, + module_id, func, line, true, fmt, args); + trace_cam_log_debug(str_buf); va_end(args); } } diff --git a/drivers/cam_utils/cam_debug_util.h b/drivers/cam_utils/cam_debug_util.h index 807ac83da7..c002de2e8c 100644 --- a/drivers/cam_utils/cam_debug_util.h +++ b/drivers/cam_utils/cam_debug_util.h @@ -331,6 +331,40 @@ const char *cam_get_module_name(unsigned int module_id); fmt, ##args); \ }) +/** + * cam_print_to_buffer + * @brief: Function to print to camera logs to a buffer. Don't use directly. Use macros + * provided below. + * + * @buf: Buffer to print into + * @buf_size: Total size of the buffer + * @len: Pointer to variable used to keep track of the length + * @tag: Log level tag to be prefixed + * @module_id: Module id tag to be prefixed + * @fmt: Formatted string which needs to be print in log + * @args: Arguments which needs to be print in log + */ +void cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, unsigned int tag, + unsigned int module_id, const char *fmt, ...); + +/** + * CAM_[ERR/WARN/INFO]_BUF + * @brief: Macro to print a new line into log buffer. + * + * @module_id: Module id tag to be prefixed + * @buf: Buffer to print into + * @buf_size: Total size of the buffer + * @len: Pointer to the variable used to keep track of the length + * @fmt: Formatted string which needs to be print in log + * @args: Arguments which needs to be print in log + */ +#define CAM_ERR_BUF(module_id, buf, buf_size, len, fmt, args...) \ + cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_ERR, module_id, fmt, ##args) +#define CAM_WARN_BUF(module_id, buf, buf_size, len, fmt, args...) \ + cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_WARN, module_id, fmt, ##args) +#define CAM_INFO_BUF(module_id, buf, buf_size, len, fmt, args...) \ + cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_INFO, module_id, fmt, ##args) + /** * @brief : API to get camera debug settings * @return const struct camera_debug_settings pointer.