1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22bf215546Sopenharmony_ci
23bf215546Sopenharmony_ci/**
24bf215546Sopenharmony_ci * This file contains macros for immediate command submission.
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#ifndef R300_CS_H
28bf215546Sopenharmony_ci#define R300_CS_H
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "r300_reg.h"
31bf215546Sopenharmony_ci#include "r300_context.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci/* Yes, I know macros are ugly. However, they are much prettier than the code
34bf215546Sopenharmony_ci * that they neatly hide away, and don't have the cost of function setup,so
35bf215546Sopenharmony_ci * we're going to use them. */
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci/**
38bf215546Sopenharmony_ci * Command submission setup.
39bf215546Sopenharmony_ci */
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci#define CS_LOCALS(context) \
42bf215546Sopenharmony_ci    struct radeon_cmdbuf *cs_copy = &(context)->cs; \
43bf215546Sopenharmony_ci    struct radeon_winsys *cs_winsys = (context)->rws; \
44bf215546Sopenharmony_ci    int cs_count = 0; (void) cs_count; (void) cs_winsys;
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci#ifdef DEBUG
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci#define BEGIN_CS(size) do { \
49bf215546Sopenharmony_ci    assert(size <= (cs_copy->current.max_dw - cs_copy->current.cdw)); \
50bf215546Sopenharmony_ci    cs_count = size; \
51bf215546Sopenharmony_ci} while (0)
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci#define END_CS do { \
54bf215546Sopenharmony_ci    if (cs_count != 0) \
55bf215546Sopenharmony_ci        debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \
56bf215546Sopenharmony_ci                     cs_count, __FUNCTION__, __FILE__, __LINE__); \
57bf215546Sopenharmony_ci    cs_count = 0; \
58bf215546Sopenharmony_ci} while (0)
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci#define CS_USED_DW(x) cs_count -= (x)
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci#else
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci#define BEGIN_CS(size)
65bf215546Sopenharmony_ci#define END_CS
66bf215546Sopenharmony_ci#define CS_USED_DW(x)
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci#endif
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci/**
71bf215546Sopenharmony_ci * Writing pure DWORDs.
72bf215546Sopenharmony_ci */
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci#define OUT_CS(value) do { \
75bf215546Sopenharmony_ci    cs_copy->current.buf[cs_copy->current.cdw++] = (value); \
76bf215546Sopenharmony_ci    CS_USED_DW(1); \
77bf215546Sopenharmony_ci} while (0)
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci#define OUT_CS_32F(value) \
80bf215546Sopenharmony_ci    OUT_CS(fui(value))
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci#define OUT_CS_REG(register, value) do { \
83bf215546Sopenharmony_ci    OUT_CS(CP_PACKET0(register, 0)); \
84bf215546Sopenharmony_ci    OUT_CS(value); \
85bf215546Sopenharmony_ci} while (0)
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci/* Note: This expects count to be the number of registers,
88bf215546Sopenharmony_ci * not the actual packet0 count! */
89bf215546Sopenharmony_ci#define OUT_CS_REG_SEQ(register, count) \
90bf215546Sopenharmony_ci    OUT_CS(CP_PACKET0((register), ((count) - 1)))
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci#define OUT_CS_ONE_REG(register, count) \
93bf215546Sopenharmony_ci    OUT_CS(CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR)
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci#define OUT_CS_PKT3(op, count) \
96bf215546Sopenharmony_ci    OUT_CS(CP_PACKET3(op, count))
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci#define OUT_CS_TABLE(values, count) do { \
99bf215546Sopenharmony_ci    memcpy(cs_copy->current.buf + cs_copy->current.cdw, (values), (count) * 4); \
100bf215546Sopenharmony_ci    cs_copy->current.cdw += (count); \
101bf215546Sopenharmony_ci    CS_USED_DW(count); \
102bf215546Sopenharmony_ci} while (0)
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_ci/**
106bf215546Sopenharmony_ci * Writing buffers.
107bf215546Sopenharmony_ci */
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci#define OUT_CS_RELOC(r) do { \
110bf215546Sopenharmony_ci    assert((r)); \
111bf215546Sopenharmony_ci    assert((r)->buf); \
112bf215546Sopenharmony_ci    OUT_CS(0xc0001000); /* PKT3_NOP */ \
113bf215546Sopenharmony_ci    OUT_CS(cs_winsys->cs_lookup_buffer(cs_copy, (r)->buf) * 4); \
114bf215546Sopenharmony_ci} while (0)
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci/**
118bf215546Sopenharmony_ci * Command buffer emission.
119bf215546Sopenharmony_ci */
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci#define WRITE_CS_TABLE(values, count) do { \
122bf215546Sopenharmony_ci    assert(cs_count == 0); \
123bf215546Sopenharmony_ci    memcpy(cs_copy->current.buf + cs_copy->current.cdw, (values), (count) * 4); \
124bf215546Sopenharmony_ci    cs_copy->current.cdw += (count); \
125bf215546Sopenharmony_ci} while (0)
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci#endif /* R300_CS_H */
128