1848b8605Smrg/*
2848b8605Smrg * Copyright 2012 Advanced Micro Devices, Inc.
3b8e80941Smrg * All Rights Reserved.
4848b8605Smrg *
5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6848b8605Smrg * copy of this software and associated documentation files (the "Software"),
7848b8605Smrg * to deal in the Software without restriction, including without limitation
8848b8605Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
9848b8605Smrg * license, and/or sell copies of the Software, and to permit persons to whom
10848b8605Smrg * the Software is furnished to do so, subject to the following conditions:
11848b8605Smrg *
12848b8605Smrg * The above copyright notice and this permission notice (including the next
13848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
14848b8605Smrg * Software.
15848b8605Smrg *
16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19848b8605Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20848b8605Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21848b8605Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22848b8605Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
23848b8605Smrg */
24848b8605Smrg
25848b8605Smrg#ifndef SI_PM4_H
26848b8605Smrg#define SI_PM4_H
27848b8605Smrg
28b8e80941Smrg#include "radeon/radeon_winsys.h"
29848b8605Smrg
30b8e80941Smrg#define SI_PM4_MAX_DW		176
31b8e80941Smrg#define SI_PM4_MAX_BO		3
32848b8605Smrg
33848b8605Smrg// forward defines
34848b8605Smrgstruct si_context;
35b8e80941Smrg
36b8e80941Smrg/* State atoms are callbacks which write a sequence of packets into a GPU
37b8e80941Smrg * command buffer (AKA indirect buffer, AKA IB, AKA command stream, AKA CS).
38b8e80941Smrg */
39b8e80941Smrgstruct si_atom {
40b8e80941Smrg	void (*emit)(struct si_context *ctx);
41b8e80941Smrg};
42848b8605Smrg
43848b8605Smrgstruct si_pm4_state
44848b8605Smrg{
45b8e80941Smrg	/* optional indirect buffer */
46b8e80941Smrg	struct si_resource	*indirect_buffer;
47b8e80941Smrg
48848b8605Smrg	/* PKT3_SET_*_REG handling */
49848b8605Smrg	unsigned	last_opcode;
50848b8605Smrg	unsigned	last_reg;
51848b8605Smrg	unsigned	last_pm4;
52848b8605Smrg
53848b8605Smrg	/* commands for the DE */
54848b8605Smrg	unsigned	ndw;
55848b8605Smrg	uint32_t	pm4[SI_PM4_MAX_DW];
56848b8605Smrg
57848b8605Smrg	/* BO's referenced by this state */
58848b8605Smrg	unsigned		nbo;
59b8e80941Smrg	struct si_resource	*bo[SI_PM4_MAX_BO];
60848b8605Smrg	enum radeon_bo_usage	bo_usage[SI_PM4_MAX_BO];
61848b8605Smrg	enum radeon_bo_priority	bo_priority[SI_PM4_MAX_BO];
62848b8605Smrg
63b8e80941Smrg	/* For shader states only */
64b8e80941Smrg	struct si_shader *shader;
65b8e80941Smrg	struct si_atom atom;
66848b8605Smrg};
67848b8605Smrg
68848b8605Smrgvoid si_pm4_cmd_begin(struct si_pm4_state *state, unsigned opcode);
69848b8605Smrgvoid si_pm4_cmd_add(struct si_pm4_state *state, uint32_t dw);
70848b8605Smrgvoid si_pm4_cmd_end(struct si_pm4_state *state, bool predicate);
71848b8605Smrg
72848b8605Smrgvoid si_pm4_set_reg(struct si_pm4_state *state, unsigned reg, uint32_t val);
73848b8605Smrgvoid si_pm4_add_bo(struct si_pm4_state *state,
74b8e80941Smrg		   struct si_resource *bo,
75848b8605Smrg		   enum radeon_bo_usage usage,
76848b8605Smrg		   enum radeon_bo_priority priority);
77b8e80941Smrgvoid si_pm4_upload_indirect_buffer(struct si_context *sctx,
78b8e80941Smrg				   struct si_pm4_state *state);
79848b8605Smrg
80b8e80941Smrgvoid si_pm4_clear_state(struct si_pm4_state *state);
81848b8605Smrgvoid si_pm4_free_state(struct si_context *sctx,
82848b8605Smrg		       struct si_pm4_state *state,
83848b8605Smrg		       unsigned idx);
84848b8605Smrg
85848b8605Smrgvoid si_pm4_emit(struct si_context *sctx, struct si_pm4_state *state);
86848b8605Smrgvoid si_pm4_reset_emitted(struct si_context *sctx);
87848b8605Smrg
88848b8605Smrg#endif
89