1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"),
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * on the rights to use, copy, modify, merge, publish, distribute, sub
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * license, and/or sell copies of the Software, and to permit persons to whom
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the Software is furnished to do so, subject to the following conditions:
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the next
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * paragraph) shall be included in all copies or substantial portions of the
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software.
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * USE OR OTHER DEALINGS IN THE SOFTWARE.
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Authors:
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *      Jerome Glisse
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef R600_H
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define R600_H
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "../../winsys/radeon/drm/radeon_winsys.h"
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_double_list.h"
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_transfer.h"
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "radeonsi_resource.h"
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define R600_ERR(fmt, args...) \
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	fprintf(stderr, "EE %s:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args)
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct winsys_handle;
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum radeon_family {
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	CHIP_UNKNOWN,
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	CHIP_CAYMAN,
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	CHIP_TAHITI,
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	CHIP_PITCAIRN,
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	CHIP_VERDE,
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	CHIP_LAST,
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum chip_class {
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	CAYMAN,
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	TAHITI,
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct r600_tiling_info {
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned num_channels;
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned num_banks;
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned group_bytes;
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* R600/R700 STATES */
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct r600_query {
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	union {
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		uint64_t			u64;
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		boolean				b;
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		struct pipe_query_data_so_statistics so;
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	} result;
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* The kind of query */
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned				type;
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Offset of the first result for current query */
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned				results_start;
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Offset of the next free result after current query data */
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned				results_end;
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Size of the result in memory for both begin_query and end_query,
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 * this can be one or two numbers, or it could even be a size of a structure. */
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned				result_size;
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* The buffer where query results are stored. It's used as a ring,
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 * data blocks for current query are stored sequentially from
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 * results_start to results_end, with wrapping on the buffer end */
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	struct si_resource			*buffer;
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* The number of dwords for begin_query or end_query. */
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned				num_cs_dw;
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* linked list of queries */
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	struct list_head			list;
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct r600_so_target {
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	struct pipe_stream_output_target b;
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* The buffer where BUFFER_FILLED_SIZE is stored. */
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	struct si_resource	*filled_size;
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned		stride;
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned		so_index;
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define R600_CONTEXT_DST_CACHES_DIRTY	(1 << 1)
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define R600_CONTEXT_CHECK_EVENT_FLUSH	(1 << 2)
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct r600_context;
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct r600_screen;
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid si_get_backend_mask(struct r600_context *ctx);
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid si_context_flush(struct r600_context *ctx, unsigned flags);
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned query_type);
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid r600_context_query_destroy(struct r600_context *ctx, struct r600_query *query);
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgboolean r600_context_query_result(struct r600_context *ctx,
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				struct r600_query *query,
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				boolean wait, void *vresult);
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid r600_query_begin(struct r600_context *ctx, struct r600_query *query);
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid r600_query_end(struct r600_context *ctx, struct r600_query *query);
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid r600_context_queries_suspend(struct r600_context *ctx);
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid r600_context_queries_resume(struct r600_context *ctx);
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid r600_query_predication(struct r600_context *ctx, struct r600_query *query, int operation,
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			    int flag_wait);
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid si_context_emit_fence(struct r600_context *ctx, struct si_resource *fence,
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           unsigned offset, unsigned value);
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid r600_context_draw_opaque_count(struct r600_context *ctx, struct r600_so_target *t);
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid si_need_cs_space(struct r600_context *ctx, unsigned num_dw, boolean count_draw_in);
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgint si_context_init(struct r600_context *ctx);
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
124