14a49301eSmrg/*
24a49301eSmrg * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
34a49301eSmrg *
44a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
54a49301eSmrg * copy of this software and associated documentation files (the "Software"),
64a49301eSmrg * to deal in the Software without restriction, including without limitation
74a49301eSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub
84a49301eSmrg * license, and/or sell copies of the Software, and to permit persons to whom
94a49301eSmrg * the Software is furnished to do so, subject to the following conditions:
104a49301eSmrg *
114a49301eSmrg * The above copyright notice and this permission notice (including the next
124a49301eSmrg * paragraph) shall be included in all copies or substantial portions of the
134a49301eSmrg * Software.
144a49301eSmrg *
154a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
164a49301eSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
174a49301eSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
184a49301eSmrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
194a49301eSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
204a49301eSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
214a49301eSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE. */
224a49301eSmrg
233464ebd5Sriastradh/**
243464ebd5Sriastradh * This file contains macros for immediate command submission.
253464ebd5Sriastradh */
263464ebd5Sriastradh
274a49301eSmrg#ifndef R300_CS_H
284a49301eSmrg#define R300_CS_H
294a49301eSmrg
304a49301eSmrg#include "r300_reg.h"
313464ebd5Sriastradh#include "r300_context.h"
324a49301eSmrg
334a49301eSmrg/* Yes, I know macros are ugly. However, they are much prettier than the code
344a49301eSmrg * that they neatly hide away, and don't have the cost of function setup,so
354a49301eSmrg * we're going to use them. */
364a49301eSmrg
373464ebd5Sriastradh/**
383464ebd5Sriastradh * Command submission setup.
393464ebd5Sriastradh */
404a49301eSmrg
414a49301eSmrg#define CS_LOCALS(context) \
427ec681f3Smrg    struct radeon_cmdbuf *cs_copy = &(context)->cs; \
433464ebd5Sriastradh    struct radeon_winsys *cs_winsys = (context)->rws; \
443464ebd5Sriastradh    int cs_count = 0; (void) cs_count; (void) cs_winsys;
454a49301eSmrg
463464ebd5Sriastradh#ifdef DEBUG
474a49301eSmrg
484a49301eSmrg#define BEGIN_CS(size) do { \
4901e04c3fSmrg    assert(size <= (cs_copy->current.max_dw - cs_copy->current.cdw)); \
504a49301eSmrg    cs_count = size; \
514a49301eSmrg} while (0)
524a49301eSmrg
533464ebd5Sriastradh#define END_CS do { \
543464ebd5Sriastradh    if (cs_count != 0) \
553464ebd5Sriastradh        debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \
563464ebd5Sriastradh                     cs_count, __FUNCTION__, __FILE__, __LINE__); \
573464ebd5Sriastradh    cs_count = 0; \
584a49301eSmrg} while (0)
594a49301eSmrg
603464ebd5Sriastradh#define CS_USED_DW(x) cs_count -= (x)
613464ebd5Sriastradh
623464ebd5Sriastradh#else
633464ebd5Sriastradh
643464ebd5Sriastradh#define BEGIN_CS(size)
653464ebd5Sriastradh#define END_CS
663464ebd5Sriastradh#define CS_USED_DW(x)
673464ebd5Sriastradh
683464ebd5Sriastradh#endif
693464ebd5Sriastradh
703464ebd5Sriastradh/**
713464ebd5Sriastradh * Writing pure DWORDs.
723464ebd5Sriastradh */
733464ebd5Sriastradh
743464ebd5Sriastradh#define OUT_CS(value) do { \
7501e04c3fSmrg    cs_copy->current.buf[cs_copy->current.cdw++] = (value); \
763464ebd5Sriastradh    CS_USED_DW(1); \
774a49301eSmrg} while (0)
784a49301eSmrg
793464ebd5Sriastradh#define OUT_CS_32F(value) \
803464ebd5Sriastradh    OUT_CS(fui(value))
813464ebd5Sriastradh
824a49301eSmrg#define OUT_CS_REG(register, value) do { \
833464ebd5Sriastradh    OUT_CS(CP_PACKET0(register, 0)); \
843464ebd5Sriastradh    OUT_CS(value); \
854a49301eSmrg} while (0)
864a49301eSmrg
874a49301eSmrg/* Note: This expects count to be the number of registers,
884a49301eSmrg * not the actual packet0 count! */
893464ebd5Sriastradh#define OUT_CS_REG_SEQ(register, count) \
903464ebd5Sriastradh    OUT_CS(CP_PACKET0((register), ((count) - 1)))
914a49301eSmrg
923464ebd5Sriastradh#define OUT_CS_ONE_REG(register, count) \
933464ebd5Sriastradh    OUT_CS(CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR)
944a49301eSmrg
953464ebd5Sriastradh#define OUT_CS_PKT3(op, count) \
963464ebd5Sriastradh    OUT_CS(CP_PACKET3(op, count))
97cdc920a0Smrg
983464ebd5Sriastradh#define OUT_CS_TABLE(values, count) do { \
9901e04c3fSmrg    memcpy(cs_copy->current.buf + cs_copy->current.cdw, (values), (count) * 4); \
10001e04c3fSmrg    cs_copy->current.cdw += (count); \
1013464ebd5Sriastradh    CS_USED_DW(count); \
1024a49301eSmrg} while (0)
1034a49301eSmrg
1044a49301eSmrg
1053464ebd5Sriastradh/**
10601e04c3fSmrg * Writing buffers.
1073464ebd5Sriastradh */
1084a49301eSmrg
1093464ebd5Sriastradh#define OUT_CS_RELOC(r) do { \
1103464ebd5Sriastradh    assert((r)); \
11101e04c3fSmrg    assert((r)->buf); \
112af69d88dSmrg    OUT_CS(0xc0001000); /* PKT3_NOP */ \
11301e04c3fSmrg    OUT_CS(cs_winsys->cs_lookup_buffer(cs_copy, (r)->buf) * 4); \
1144a49301eSmrg} while (0)
1154a49301eSmrg
1164a49301eSmrg
1173464ebd5Sriastradh/**
1183464ebd5Sriastradh * Command buffer emission.
1193464ebd5Sriastradh */
1204a49301eSmrg
1213464ebd5Sriastradh#define WRITE_CS_TABLE(values, count) do { \
1223464ebd5Sriastradh    assert(cs_count == 0); \
12301e04c3fSmrg    memcpy(cs_copy->current.buf + cs_copy->current.cdw, (values), (count) * 4); \
12401e04c3fSmrg    cs_copy->current.cdw += (count); \
1254a49301eSmrg} while (0)
1264a49301eSmrg
1274a49301eSmrg#endif /* R300_CS_H */
128