1/* savage_common.h -- Public header for the savage driver (IOCTLs)
2 *
3 * Copyright 2004  Felix Kuehling
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#ifndef SAVAGE_COMMON_H
27#define SAVAGE_COMMON_H
28
29#include <inttypes.h>
30
31/* Savage-specific ioctls
32 */
33#define DRM_SAVAGE_BCI_INIT		0x00
34#define DRM_SAVAGE_BCI_CMDBUF           0x01
35#define DRM_SAVAGE_BCI_EVENT_EMIT	0x02
36#define DRM_SAVAGE_BCI_EVENT_WAIT	0x03
37
38#define SAVAGE_DMA_PCI	1
39#define SAVAGE_DMA_AGP	3
40typedef struct {
41	enum {
42		SAVAGE_INIT_BCI = 1,
43		SAVAGE_CLEANUP_BCI = 2
44	} func;
45	unsigned int sarea_priv_offset;
46
47	/* some parameters */
48	unsigned int cob_size;
49	unsigned int bci_threshold_lo, bci_threshold_hi;
50	unsigned int dma_type;
51
52	/* frame buffer layout */
53	unsigned int fb_bpp;
54	unsigned int front_offset, front_pitch;
55	unsigned int back_offset, back_pitch;
56	unsigned int depth_bpp;
57	unsigned int depth_offset, depth_pitch;
58
59	/* local textures */
60	unsigned int texture_offset;
61	unsigned int texture_size;
62
63	/* physical locations of non-permanent maps */
64	unsigned long status_offset;
65	unsigned long buffers_offset;
66	unsigned long agp_textures_offset;
67	unsigned long cmd_dma_offset;
68} drmSAVAGEInit;
69
70typedef union drmSAVAGECmdHeader drmSAVAGECmdHeader;
71typedef struct {
72				/* command buffer in client's address space */
73	drmSAVAGECmdHeader *cmd_addr;
74	unsigned int size;	/* size of the command buffer in 64bit units */
75
76	unsigned int dma_idx;	/* DMA buffer index to use */
77	int discard;		/* discard DMA buffer when done */
78				/* vertex buffer in client's address space */
79	unsigned int *vb_addr;
80	unsigned int vb_size;	/* size of client vertex buffer in bytes */
81	unsigned int vb_stride;	/* stride of vertices in 32bit words */
82				/* boxes in client's address space */
83	drm_clip_rect_t *box_addr;
84	unsigned int nbox;	/* number of clipping boxes */
85} drmSAVAGECmdbuf;
86
87#define SAVAGE_WAIT_2D  0x1 /* wait for 2D idle before updating event tag */
88#define SAVAGE_WAIT_3D  0x2 /* wait for 3D idle before updating event tag */
89#define SAVAGE_WAIT_IRQ 0x4 /* emit or wait for IRQ, not implemented yet */
90typedef struct {
91	unsigned int count;
92	unsigned int flags;
93} drmSAVAGEEventEmit, drmSAVAGEEventWait;
94
95/* Commands for the cmdbuf ioctl
96 */
97#define SAVAGE_CMD_STATE	0  /* a range of state registers */
98#define SAVAGE_CMD_DMA_PRIM	1  /* vertices from DMA buffer */
99#define SAVAGE_CMD_VTX_PRIM	2  /* vertices from client vertex buffer */
100#define SAVAGE_CMD_DMA_IDX	3  /* indexed vertices from DMA buffer */
101#define SAVAGE_CMD_VTX_IDX	4  /* indexed vertices client vertex buffer */
102#define SAVAGE_CMD_CLEAR	5  /* clear buffers */
103#define SAVAGE_CMD_SWAP		6  /* swap buffers */
104
105/* Primitive types
106*/
107#define SAVAGE_PRIM_TRILIST	0  /* triangle list */
108#define SAVAGE_PRIM_TRISTRIP	1  /* triangle strip */
109#define SAVAGE_PRIM_TRIFAN	2  /* triangle fan */
110#define SAVAGE_PRIM_TRILIST_201	3  /* reorder verts for correct flat
111				    * shading on s3d */
112
113/* Skip flags (vertex format)
114 */
115#define SAVAGE_SKIP_Z		0x01
116#define SAVAGE_SKIP_W		0x02
117#define SAVAGE_SKIP_C0		0x04
118#define SAVAGE_SKIP_C1		0x08
119#define SAVAGE_SKIP_S0		0x10
120#define SAVAGE_SKIP_T0		0x20
121#define SAVAGE_SKIP_ST0		0x30
122#define SAVAGE_SKIP_S1		0x40
123#define SAVAGE_SKIP_T1		0x80
124#define SAVAGE_SKIP_ST1		0xc0
125#define SAVAGE_SKIP_ALL_S3D	0x3f
126#define SAVAGE_SKIP_ALL_S4	0xff
127
128/* Buffer names for clear command
129 */
130#define SAVAGE_FRONT		0x1
131#define SAVAGE_BACK		0x2
132#define SAVAGE_DEPTH		0x4
133
134/* 64-bit command header
135 */
136union drmSAVAGECmdHeader {
137	struct {
138		unsigned char cmd;	/* command */
139		unsigned char pad0;
140		unsigned short pad1;
141		unsigned short pad2;
142		unsigned short pad3;
143	} cmd; /* generic */
144	struct {
145		unsigned char cmd;
146		unsigned char global;	/* need idle engine? */
147		unsigned short count;	/* number of consecutive registers */
148		unsigned short start;	/* first register */
149		unsigned short pad3;
150	} state; /* SAVAGE_CMD_STATE */
151	struct {
152		unsigned char cmd;
153		unsigned char prim;	/* primitive type */
154		unsigned short skip;	/* vertex format (skip flags) */
155		unsigned short count;	/* number of vertices */
156		unsigned short start;	/* first vertex in DMA/vertex buffer */
157	} prim; /* SAVAGE_CMD_DMA_PRIM, SAVAGE_CMD_VB_PRIM */
158	struct {
159		unsigned char cmd;
160		unsigned char prim;
161		unsigned short skip;
162		unsigned short count;	/* number of indices that follow */
163		unsigned short pad3;
164	} idx; /* SAVAGE_CMD_DMA_IDX, SAVAGE_CMD_VB_IDX */
165	struct {
166		unsigned char cmd;
167		unsigned char pad0;
168		unsigned short pad1;
169		unsigned int flags;
170	} clear0; /* SAVAGE_CMD_CLEAR */
171	struct {
172		unsigned int mask;
173		unsigned int value;
174	} clear1; /* SAVAGE_CMD_CLEAR data */
175};
176
177#endif /* SAVAGE_COMMON_H */
178