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