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 return query;
42 }
43
44 static struct intel_perf_query_info *
hsw_query_alloc(struct intel_perf_config * perf,int ncounters)45 hsw_query_alloc(struct intel_perf_config *perf, int ncounters)
46 {
47 struct intel_perf_query_info *query = intel_query_alloc(perf, ncounters);
48 query->oa_format = I915_OA_FORMAT_A45_B8_C8;
49 /* Accumulation buffer offsets... */
50 query->gpu_time_offset = 0;
51 query->a_offset = query->gpu_time_offset + 1;
52 query->b_offset = query->a_offset + 45;
53 query->c_offset = query->b_offset + 8;
54 query->perfcnt_offset = query->c_offset + 8;
55 query->rpstat_offset = query->perfcnt_offset + 2;
56 return query;
57 }
58
59 static struct intel_perf_query_info *
bdw_query_alloc(struct intel_perf_config * perf,int ncounters)60 bdw_query_alloc(struct intel_perf_config *perf, int ncounters)
61 {
62 struct intel_perf_query_info *query = intel_query_alloc(perf, ncounters);
63 query->oa_format = I915_OA_FORMAT_A32u40_A4u32_B8_C8;
64 /* Accumulation buffer offsets... */
65 query->gpu_time_offset = 0;
66 query->gpu_clock_offset = query->gpu_time_offset + 1;
67 query->a_offset = query->gpu_clock_offset + 1;
68 query->b_offset = query->a_offset + 36;
69 query->c_offset = query->b_offset + 8;
70 query->perfcnt_offset = query->c_offset + 8;
71 query->rpstat_offset = query->perfcnt_offset + 2;
72 return query;
73 }
74
75 struct intel_perf_query_counter_data {
76 uint16_t name_idx;
77 uint16_t desc_idx;
78 uint16_t symbol_name_idx;
79 uint16_t category_idx;
80 enum intel_perf_counter_type type;
81 enum intel_perf_counter_data_type data_type;
82 enum intel_perf_counter_units units;
83 };
84
85 #endif /* INTEL_PERF_SETUP_H */
86