1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (c) 2017 Etnaviv Project
3bf215546Sopenharmony_ci * Copyright (C) 2017 Zodiac Inflight Innovations
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license,
9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
13bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
14bf215546Sopenharmony_ci * of the Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci *
24bf215546Sopenharmony_ci * Authors:
25bf215546Sopenharmony_ci *    Rob Clark <robclark@freedesktop.org>
26bf215546Sopenharmony_ci *    Christian Gmeiner <christian.gmeiner@gmail.com>
27bf215546Sopenharmony_ci */
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#ifndef H_ETNAVIV_QUERY_HW
30bf215546Sopenharmony_ci#define H_ETNAVIV_QUERY_HW
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include "etnaviv_query.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_cistruct etna_acc_query;
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_cistruct etna_acc_sample_provider {
37bf215546Sopenharmony_ci   bool (*supports)(unsigned query_type);
38bf215546Sopenharmony_ci   struct etna_acc_query * (*allocate)(struct etna_context *ctx, unsigned query_type);
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci   void (*resume)(struct etna_acc_query *aq, struct etna_context *ctx);
41bf215546Sopenharmony_ci   void (*suspend)(struct etna_acc_query *aq, struct etna_context *ctx);
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci   bool (*result)(struct etna_acc_query *aq, void *buf,
44bf215546Sopenharmony_ci                  union pipe_query_result *result);
45bf215546Sopenharmony_ci};
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_cistruct etna_acc_query {
48bf215546Sopenharmony_ci   struct etna_query base;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci   struct pipe_resource *prsc;
51bf215546Sopenharmony_ci   unsigned samples;        /* number of samples stored in resource */
52bf215546Sopenharmony_ci   unsigned no_wait_cnt;    /* see etna_hw_get_query_result() */
53bf215546Sopenharmony_ci   struct list_head node;   /* list-node in ctx->active_hw_queries */
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci   const struct etna_acc_sample_provider *provider;
56bf215546Sopenharmony_ci};
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_cistatic inline struct etna_acc_query *
59bf215546Sopenharmony_cietna_acc_query(struct etna_query *q)
60bf215546Sopenharmony_ci{
61bf215546Sopenharmony_ci   return (struct etna_acc_query *)q;
62bf215546Sopenharmony_ci}
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_cistruct etna_query *
65bf215546Sopenharmony_cietna_acc_create_query(struct etna_context *ctx, unsigned query_type);
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_cistatic inline void
68bf215546Sopenharmony_cietna_acc_query_suspend(struct etna_acc_query *aq, struct etna_context *ctx)
69bf215546Sopenharmony_ci{
70bf215546Sopenharmony_ci   const struct etna_acc_sample_provider *p = aq->provider;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   p->suspend(aq, ctx);
73bf215546Sopenharmony_ci   aq->samples++;
74bf215546Sopenharmony_ci}
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_cistatic inline void
77bf215546Sopenharmony_cietna_acc_query_resume(struct etna_acc_query *aq, struct etna_context *ctx)
78bf215546Sopenharmony_ci{
79bf215546Sopenharmony_ci   const struct etna_acc_sample_provider *p = aq->provider;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   p->resume(aq, ctx);
82bf215546Sopenharmony_ci   aq->samples++;
83bf215546Sopenharmony_ci}
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci#endif
86