1 // SPDX-License-Identifier: GPL-2.0
3 * Support for Intel Camera Imaging ISP subsystem.
4 * Copyright (c) 2015, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #include "assert_support.h"
17 #include "sh_css_metrics.h"
22 #include "sh_css_internal.h"
24 #define MULTIPLE_PCS 0
27 #define RESUME_MASK 0x8
30 static bool pc_histogram_enabled;
31 static struct sh_css_pc_histogram *isp_histogram;
32 static struct sh_css_pc_histogram *sp_histogram;
34 struct sh_css_metrics sh_css_metrics;
37 sh_css_metrics_start_frame(void)
39 sh_css_metrics.frame_metrics.num_frames++;
43 clear_histogram(struct sh_css_pc_histogram *histogram)
49 for (i = 0; i < histogram->length; i++) {
50 histogram->run[i] = 0;
51 histogram->stall[i] = 0;
52 histogram->msink[i] = 0xFFFF;
57 sh_css_metrics_enable_pc_histogram(bool enable)
59 pc_histogram_enabled = enable;
63 make_histogram(struct sh_css_pc_histogram *histogram, unsigned int length)
67 if (histogram->length)
71 histogram->run = kvmalloc(length * sizeof(*histogram->run),
75 histogram->stall = kvmalloc(length * sizeof(*histogram->stall),
77 if (!histogram->stall)
79 histogram->msink = kvmalloc(length * sizeof(*histogram->msink),
81 if (!histogram->msink)
84 histogram->length = length;
85 clear_histogram(histogram);
89 insert_binary_metrics(struct sh_css_binary_metrics **l,
90 struct sh_css_binary_metrics *metrics)
96 for (; *l; l = &(*l)->next)
101 metrics->next = NULL;
105 sh_css_metrics_start_binary(struct sh_css_binary_metrics *metrics)
109 if (!pc_histogram_enabled)
112 isp_histogram = &metrics->isp_histogram;
113 sp_histogram = &metrics->sp_histogram;
114 make_histogram(isp_histogram, ISP_PMEM_DEPTH);
115 make_histogram(sp_histogram, SP_PMEM_DEPTH);
116 insert_binary_metrics(&sh_css_metrics.binary_metrics, metrics);
120 sh_css_metrics_sample_pcs(void)
128 if (!pc_histogram_enabled)
132 msink = isp_ctrl_load(ISP0_ID, ISP_CTRL_SINK_REG);
133 pc = isp_ctrl_load(ISP0_ID, ISP_PC_REG);
135 isp_histogram->msink[pc] &= msink;
136 stall = (msink != 0x7FF);
139 isp_histogram->stall[pc]++;
141 isp_histogram->run[pc]++;
144 if (sp_histogram && 0) {
145 msink = sp_ctrl_load(SP0_ID, SP_CTRL_SINK_REG);
146 pc = sp_ctrl_load(SP0_ID, SP_PC_REG);
147 sp_histogram->msink[pc] &= msink;
148 stall = (msink != 0x7FF);
150 sp_histogram->stall[pc]++;
152 sp_histogram->run[pc]++;