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