1 /*
2 * Copyright © 2018 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef INTEL_PERF_SETUP_H
25 #define INTEL_PERF_SETUP_H
26
27 #include "perf/intel_perf.h"
28
29 #define MIN(a, b) ((a < b) ? (a) : (b))
30 #define MAX(a, b) ((a > b) ? (a) : (b))
31
32 static struct intel_perf_query_info *
intel_query_alloc(struct intel_perf_config * perf,int ncounters)33 intel_query_alloc(struct intel_perf_config *perf, int ncounters)
34 {
35 struct intel_perf_query_info *query = rzalloc(perf, struct intel_perf_query_info);
36 query->perf = perf;
37 query->kind = INTEL_PERF_QUERY_TYPE_OA;
38 query->n_counters = 0;
39 query->oa_metrics_set_id = 0; /* determined at runtime, via sysfs */
40 query->counters = rzalloc_array(query, struct intel_perf_query_counter, ncounters);
41
42 /* Accumulation buffer offsets... */
43 if (perf->devinfo.verx10 <= 75) {
44 query->oa_format = I915_OA_FORMAT_A45_B8_C8;
45 query->gpu_time_offset = 0;
46 query->a_offset = query->gpu_time_offset + 1;
47 query->b_offset = query->a_offset + 45;
48 query->c_offset = query->b_offset + 8;
49 query->perfcnt_offset = query->c_offset + 8;
50 query->rpstat_offset = query->perfcnt_offset + 2;
51 } else if (perf->devinfo.verx10 <= 120) {
52 query->oa_format = I915_OA_FORMAT_A32u40_A4u32_B8_C8;
53 query->gpu_time_offset = 0;
54 query->gpu_clock_offset = query->gpu_time_offset + 1;
55 query->a_offset = query->gpu_clock_offset + 1;
56 query->b_offset = query->a_offset + 36;
57 query->c_offset = query->b_offset + 8;
58 query->perfcnt_offset = query->c_offset + 8;
59 query->rpstat_offset = query->perfcnt_offset + 2;
60 } else {
61 query->oa_format = I915_OA_FORMAT_A24u40_A14u32_B8_C8;
62 query->gpu_time_offset = 0;
63 query->gpu_clock_offset = query->gpu_time_offset + 1;
64 query->a_offset = query->gpu_clock_offset + 1;
65 query->b_offset = query->a_offset + 38;
66 query->c_offset = query->b_offset + 8;
67 query->perfcnt_offset = query->c_offset + 8;
68 query->rpstat_offset = query->perfcnt_offset + 2;
69 }
70
71 return query;
72 }
73
74 struct intel_perf_query_counter_data {
75 uint32_t name_idx;
76 uint32_t desc_idx;
77 uint32_t symbol_name_idx;
78 uint32_t category_idx;
79 enum intel_perf_counter_type type;
80 enum intel_perf_counter_data_type data_type;
81 enum intel_perf_counter_units units;
82 };
83
84 #endif /* INTEL_PERF_SETUP_H */
85