summaryrefslogtreecommitdiff
path: root/r600_hwapi.h
blob: 6fa713b8ea7aa76dcfed3f3003d60516e24bc64a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * r600_demo
 *
 * Copyright (C) 2008-2009  Matthias Hopf
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef __R600_HWAPI_H__
#define __R600_HWAPI_H__

/*
 * This defines hardware api related stuff
 */

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <endian.h>


#if BYTE_ORDER == BIG_ENDIAN
#  define SWAP16(A)  ((((unsigned short)(A) & 0xff00) >> 8) |	\
		      (((unsigned short)(A) & 0x00ff) << 8))
#  define SWAP32(A)  ((((CARD32)(A) & 0xff000000) >> 24) |	\
		      (((CARD32)(A) & 0x00ff0000) >> 8)  |	\
		      (((CARD32)(A) & 0x0000ff00) << 8)  |	\
		      (((CARD32)(A) & 0x000000ff) << 24))
#else
#  define SWAP16(A)  (A)
#  define SWAP32(A)  (A)
#endif


#define DEBUG(x) do { x } while (0)			/* Always, on r600_demo */

/*
 * Internal stuff needed for API
 */

extern volatile void *registers;
extern int indirect_end, indirect_size;
extern uint32_t *indirect;


void flush_cmds (void);


/*
 * Register access
 */
static inline uint32_t reg_read32 (uint32_t reg)
{
    uint32_t v;
    v = * (volatile uint32_t *) (registers+reg);
    return SWAP32 (v);
}

static inline void reg_write32 (uint32_t reg, uint32_t v)
{
    * (volatile uint32_t *) (registers+reg) = SWAP32 (v);
}


/*
 * Packet Macros + Routines
 */

/* Preamble. Allocate space for dwords uint32_t values. If not enough space
 * is available, bail out.
 * In a production driver this can even be a NOP. Real buffer allocation has
 * to be done beforehand. */
/* For r600demo this is trivial. */
#define CMD_BUFFER_PREAMBLE(dwords)		\
    checkCmdBufferSpace (dwords)


/* Preamble, without space checking. Use with care. */
/* For r600demo this is trivial. */
#define CMD_BUFFER_NOCHECK_PREAMBLE		\
    ((void) 0)


/* Check for additional space for dwords uint32_t values. If not enough space
 * is available, bail out. */
/* For r600demo this is trivial. */
#define CMD_BUFFER_ALLOC(dwords)		\
    checkCmdBufferSpace (dwords)


/* Space checker for debugging purposes. Bail out if not enough space. */
/* Always enabled in r600demo. */
#define CMD_BUFFER_DEBUG_AVAIL(dwords)		\
    checkCmdBufferSpace (dwords)


/* Emit a single uint32_t value */
#define E32(dword)				\
    do {					\
	CMD_BUFFER_DEBUG_AVAIL (1);		\
	indirect[indirect_end>>2] = (dword);	\
	indirect_end += 4;			\
    } while (0)


static inline void checkCmdBufferSpace (int dwords)
{
    if (indirect_end + 4*dwords >= indirect_size) {
	fprintf (stderr, "Insufficient indirect buffer size (have %d, need %d) - aborting\n",
		 dwords, (indirect_size-indirect_end)/4);
	exit (1);
    }
}


#endif