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 INTEL_PERF_QUERY_H
25#define INTEL_PERF_QUERY_H
26
27#include <stdint.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33struct intel_device_info;
34
35struct intel_perf_config;
36struct intel_perf_context;
37struct intel_perf_query_object;
38
39bool
40intel_perf_open(struct intel_perf_context *perf_ctx,
41                int metrics_set_id,
42                int report_format,
43                int period_exponent,
44                int drm_fd,
45                uint32_t ctx_id,
46                bool enable);
47
48void
49intel_perf_close(struct intel_perf_context *perfquery,
50                 const struct intel_perf_query_info *query);
51
52bool intel_perf_oa_stream_ready(struct intel_perf_context *perf_ctx);
53
54ssize_t
55intel_perf_read_oa_stream(struct intel_perf_context *perf_ctx,
56                          void* buf,
57                          size_t nbytes);
58
59struct intel_perf_context *intel_perf_new_context(void *parent);
60
61void intel_perf_init_context(struct intel_perf_context *perf_ctx,
62                             struct intel_perf_config *perf_cfg,
63                             void * mem_ctx, /* ralloc context */
64                             void * ctx,  /* driver context (eg, brw_context) */
65                             void * bufmgr,  /* eg brw_bufmgr */
66                             const struct intel_device_info *devinfo,
67                             uint32_t hw_ctx,
68                             int drm_fd);
69
70const struct intel_perf_query_info* intel_perf_query_info(const struct intel_perf_query_object *);
71
72struct intel_perf_config *intel_perf_config(struct intel_perf_context *ctx);
73
74int intel_perf_active_queries(struct intel_perf_context *perf_ctx,
75                            const struct intel_perf_query_info *query);
76
77struct intel_perf_query_object *
78intel_perf_new_query(struct intel_perf_context *, unsigned query_index);
79
80
81bool intel_perf_begin_query(struct intel_perf_context *perf_ctx,
82                            struct intel_perf_query_object *query);
83void intel_perf_end_query(struct intel_perf_context *perf_ctx,
84                          struct intel_perf_query_object *query);
85void intel_perf_wait_query(struct intel_perf_context *perf_ctx,
86                           struct intel_perf_query_object *query,
87                           void *current_batch);
88bool intel_perf_is_query_ready(struct intel_perf_context *perf_ctx,
89                               struct intel_perf_query_object *query,
90                               void *current_batch);
91void intel_perf_delete_query(struct intel_perf_context *perf_ctx,
92                             struct intel_perf_query_object *query);
93void intel_perf_get_query_data(struct intel_perf_context *perf_ctx,
94                               struct intel_perf_query_object *query,
95                               void *current_batch,
96                               int data_size,
97                               unsigned *data,
98                               unsigned *bytes_written);
99
100void intel_perf_dump_query_count(struct intel_perf_context *perf_ctx);
101void intel_perf_dump_query(struct intel_perf_context *perf_ctx,
102                           struct intel_perf_query_object *obj,
103                           void *current_batch);
104
105#ifdef __cplusplus
106} // extern "C"
107#endif
108
109#endif /* INTEL_PERF_QUERY_H */
110