1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2019 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_PRIVATE_H
25bf215546Sopenharmony_ci#define INTEL_PERF_PRIVATE_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "intel_perf.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_cistatic inline uint64_t to_user_pointer(void *ptr)
30bf215546Sopenharmony_ci{
31bf215546Sopenharmony_ci   return (uintptr_t) ptr;
32bf215546Sopenharmony_ci}
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_cistatic inline uint64_t to_const_user_pointer(const void *ptr)
35bf215546Sopenharmony_ci{
36bf215546Sopenharmony_ci   return (uintptr_t) ptr;
37bf215546Sopenharmony_ci}
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_cistatic inline void
40bf215546Sopenharmony_ciintel_perf_query_add_stat_reg(struct intel_perf_query_info *query, uint32_t reg,
41bf215546Sopenharmony_ci                              uint32_t numerator, uint32_t denominator,
42bf215546Sopenharmony_ci                              const char *name, const char *description)
43bf215546Sopenharmony_ci{
44bf215546Sopenharmony_ci   struct intel_perf_query_counter *counter;
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci   assert(query->n_counters < query->max_counters);
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   counter = &query->counters[query->n_counters];
49bf215546Sopenharmony_ci   counter->name = counter->symbol_name = name;
50bf215546Sopenharmony_ci   counter->desc = description;
51bf215546Sopenharmony_ci   counter->type = INTEL_PERF_COUNTER_TYPE_RAW;
52bf215546Sopenharmony_ci   counter->data_type = INTEL_PERF_COUNTER_DATA_TYPE_UINT64;
53bf215546Sopenharmony_ci   counter->offset = sizeof(uint64_t) * query->n_counters;
54bf215546Sopenharmony_ci   counter->pipeline_stat.reg = reg;
55bf215546Sopenharmony_ci   counter->pipeline_stat.numerator = numerator;
56bf215546Sopenharmony_ci   counter->pipeline_stat.denominator = denominator;
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci   query->n_counters++;
59bf215546Sopenharmony_ci}
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cistatic inline void
62bf215546Sopenharmony_ciintel_perf_query_add_basic_stat_reg(struct intel_perf_query_info *query,
63bf215546Sopenharmony_ci                                    uint32_t reg, const char *name)
64bf215546Sopenharmony_ci{
65bf215546Sopenharmony_ci   intel_perf_query_add_stat_reg(query, reg, 1, 1, name, name);
66bf215546Sopenharmony_ci}
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_cistatic inline struct intel_perf_query_info *
69bf215546Sopenharmony_ciintel_perf_append_query_info(struct intel_perf_config *perf, int max_counters)
70bf215546Sopenharmony_ci{
71bf215546Sopenharmony_ci   struct intel_perf_query_info *query;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci   perf->queries = reralloc(perf, perf->queries,
74bf215546Sopenharmony_ci                            struct intel_perf_query_info,
75bf215546Sopenharmony_ci                            ++perf->n_queries);
76bf215546Sopenharmony_ci   query = &perf->queries[perf->n_queries - 1];
77bf215546Sopenharmony_ci   memset(query, 0, sizeof(*query));
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   query->perf = perf;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   if (max_counters > 0) {
82bf215546Sopenharmony_ci      query->max_counters = max_counters;
83bf215546Sopenharmony_ci      query->counters =
84bf215546Sopenharmony_ci         rzalloc_array(perf, struct intel_perf_query_counter, max_counters);
85bf215546Sopenharmony_ci   }
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   return query;
88bf215546Sopenharmony_ci}
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_civoid intel_perf_register_mdapi_statistic_query(struct intel_perf_config *perf_cfg,
91bf215546Sopenharmony_ci                                               const struct intel_device_info *devinfo);
92bf215546Sopenharmony_civoid intel_perf_register_mdapi_oa_query(struct intel_perf_config *perf,
93bf215546Sopenharmony_ci                                        const struct intel_device_info *devinfo);
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci#endif /* INTEL_PERF_PRIVATE_H */
97