blob: b54b8967dcd23be75f1ca2ca5653938058c4453f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* radeon_drv.h -- Private header for radeon driver -*- linux-c -*-
2 *
3 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
4 * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
5 * All rights reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 * Kevin E. Martin <martin@valinux.com>
28 * Gareth Hughes <gareth@valinux.com>
29 */
30
31#ifndef __RADEON_DRV_H__
32#define __RADEON_DRV_H__
33
34/* General customization:
35 */
36
37#define DRIVER_AUTHOR "Gareth Hughes, Keith Whitwell, others."
38
39#define DRIVER_NAME "radeon"
40#define DRIVER_DESC "ATI Radeon"
Dave Airlied6fece02006-06-24 17:04:07 +100041#define DRIVER_DATE "20060524"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* Interface history:
44 *
45 * 1.1 - ??
46 * 1.2 - Add vertex2 ioctl (keith)
47 * - Add stencil capability to clear ioctl (gareth, keith)
48 * - Increase MAX_TEXTURE_LEVELS (brian)
49 * 1.3 - Add cmdbuf ioctl (keith)
50 * - Add support for new radeon packets (keith)
51 * - Add getparam ioctl (keith)
52 * - Add flip-buffers ioctl, deprecate fullscreen foo (keith).
53 * 1.4 - Add scratch registers to get_param ioctl.
54 * 1.5 - Add r200 packets to cmdbuf ioctl
55 * - Add r200 function to init ioctl
56 * - Add 'scalar2' instruction to cmdbuf
57 * 1.6 - Add static GART memory manager
58 * Add irq handler (won't be turned on unless X server knows to)
59 * Add irq ioctls and irq_active getparam.
60 * Add wait command for cmdbuf ioctl
61 * Add GART offset query for getparam
62 * 1.7 - Add support for cube map registers: R200_PP_CUBIC_FACES_[0..5]
63 * and R200_PP_CUBIC_OFFSET_F1_[0..5].
64 * Added packets R200_EMIT_PP_CUBIC_FACES_[0..5] and
65 * R200_EMIT_PP_CUBIC_OFFSETS_[0..5]. (brian)
66 * 1.8 - Remove need to call cleanup ioctls on last client exit (keith)
67 * Add 'GET' queries for starting additional clients on different VT's.
68 * 1.9 - Add DRM_IOCTL_RADEON_CP_RESUME ioctl.
69 * Add texture rectangle support for r100.
70 * 1.10- Add SETPARAM ioctl; first parameter to set is FB_LOCATION, which
Dave Airlieb5e89ed2005-09-25 14:28:13 +100071 * clients use to tell the DRM where they think the framebuffer is
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * located in the card's address space
73 * 1.11- Add packet R200_EMIT_RB3D_BLENDCOLOR to support GL_EXT_blend_color
74 * and GL_EXT_blend_[func|equation]_separate on r200
75 * 1.12- Add R300 CP microcode support - this just loads the CP on r300
Dave Airlied985c102006-01-02 21:32:48 +110076 * (No 3D support yet - just microcode loading).
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 * 1.13- Add packet R200_EMIT_TCL_POINT_SPRITE_CNTL for ARB_point_parameters
78 * - Add hyperz support, add hyperz flags to clear ioctl.
79 * 1.14- Add support for color tiling
80 * - Add R100/R200 surface allocation/free support
81 * 1.15- Add support for texture micro tiling
82 * - Add support for r100 cube maps
83 * 1.16- Add R200_EMIT_PP_TRI_PERF_CNTL packet to support brilinear
84 * texture filtering on r200
Dave Airlie414ed532005-08-16 20:43:16 +100085 * 1.17- Add initial support for R300 (3D).
Dave Airlie9d176012005-09-11 19:55:53 +100086 * 1.18- Add support for GL_ATI_fragment_shader, new packets
87 * R200_EMIT_PP_AFS_0/1, R200_EMIT_PP_TXCTLALL_0-5 (replaces
88 * R200_EMIT_PP_TXFILTER_0-5, 2 more regs) and R200_EMIT_ATF_TFACTOR
89 * (replaces R200_EMIT_TFACTOR_0 (8 consts instead of 6)
Dave Airlieea98a922005-09-11 20:28:11 +100090 * 1.19- Add support for gart table in FB memory and PCIE r300
Dave Airlied985c102006-01-02 21:32:48 +110091 * 1.20- Add support for r300 texrect
92 * 1.21- Add support for card type getparam
Dave Airlie4e5e2e22006-02-18 15:51:35 +110093 * 1.22- Add support for texture cache flushes (R300_TX_CNTL)
Dave Airlied5ea7022006-03-19 19:37:55 +110094 * 1.23- Add new radeon memory map work from benh
Dave Airlieee4621f2006-03-19 19:45:26 +110095 * 1.24- Add general-purpose packet for manipulating scratch registers (r300)
Dave Airlied6fece02006-06-24 17:04:07 +100096 * 1.25- Add support for r200 vertex programs (R200_EMIT_VAP_PVS_CNTL,
97 * new packet type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 */
99#define DRIVER_MAJOR 1
Dave Airlied6fece02006-06-24 17:04:07 +1000100#define DRIVER_MINOR 25
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define DRIVER_PATCHLEVEL 0
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/*
104 * Radeon chip families
105 */
106enum radeon_family {
107 CHIP_R100,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 CHIP_RV100,
Dave Airliedfab1152006-03-19 20:01:37 +1100109 CHIP_RS100,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 CHIP_RV200,
111 CHIP_RS200,
Dave Airliedfab1152006-03-19 20:01:37 +1100112 CHIP_R200,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 CHIP_RV250,
Dave Airliedfab1152006-03-19 20:01:37 +1100114 CHIP_RS300,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 CHIP_RV280,
116 CHIP_R300,
Dave Airlie414ed532005-08-16 20:43:16 +1000117 CHIP_R350,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 CHIP_RV350,
Dave Airliedfab1152006-03-19 20:01:37 +1100119 CHIP_RV380,
Dave Airlie414ed532005-08-16 20:43:16 +1000120 CHIP_R420,
Dave Airliedfab1152006-03-19 20:01:37 +1100121 CHIP_RV410,
122 CHIP_RS400,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 CHIP_LAST,
124};
125
126enum radeon_cp_microcode_version {
127 UCODE_R100,
128 UCODE_R200,
129 UCODE_R300,
130};
131
132/*
133 * Chip flags
134 */
135enum radeon_chip_flags {
136 CHIP_FAMILY_MASK = 0x0000ffffUL,
137 CHIP_FLAGS_MASK = 0xffff0000UL,
138 CHIP_IS_MOBILITY = 0x00010000UL,
139 CHIP_IS_IGP = 0x00020000UL,
140 CHIP_SINGLE_CRTC = 0x00040000UL,
141 CHIP_IS_AGP = 0x00080000UL,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000142 CHIP_HAS_HIERZ = 0x00100000UL,
Dave Airlieea98a922005-09-11 20:28:11 +1000143 CHIP_IS_PCIE = 0x00200000UL,
Dave Airlief3dd5c32006-03-25 18:09:46 +1100144 CHIP_NEW_MEMMAP = 0x00400000UL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145};
146
Dave Airlied5ea7022006-03-19 19:37:55 +1100147#define GET_RING_HEAD(dev_priv) (dev_priv->writeback_works ? \
148 DRM_READ32( (dev_priv)->ring_rptr, 0 ) : RADEON_READ(RADEON_CP_RB_RPTR))
Dave Airlied985c102006-01-02 21:32:48 +1100149#define SET_RING_HEAD(dev_priv,val) DRM_WRITE32( (dev_priv)->ring_rptr, 0, (val) )
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151typedef struct drm_radeon_freelist {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000152 unsigned int age;
153 drm_buf_t *buf;
154 struct drm_radeon_freelist *next;
155 struct drm_radeon_freelist *prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156} drm_radeon_freelist_t;
157
158typedef struct drm_radeon_ring_buffer {
159 u32 *start;
160 u32 *end;
161 int size;
162 int size_l2qw;
163
164 u32 tail;
165 u32 tail_mask;
166 int space;
167
168 int high_mark;
169} drm_radeon_ring_buffer_t;
170
171typedef struct drm_radeon_depth_clear_t {
172 u32 rb3d_cntl;
173 u32 rb3d_zstencilcntl;
174 u32 se_cntl;
175} drm_radeon_depth_clear_t;
176
177struct drm_radeon_driver_file_fields {
178 int64_t radeon_fb_delta;
179};
180
181struct mem_block {
182 struct mem_block *next;
183 struct mem_block *prev;
184 int start;
185 int size;
186 DRMFILE filp; /* 0: free, -1: heap, other: real files */
187};
188
189struct radeon_surface {
190 int refcount;
191 u32 lower;
192 u32 upper;
193 u32 flags;
194};
195
196struct radeon_virt_surface {
197 int surface_index;
198 u32 lower;
199 u32 upper;
200 u32 flags;
201 DRMFILE filp;
202};
203
204typedef struct drm_radeon_private {
205 drm_radeon_ring_buffer_t ring;
206 drm_radeon_sarea_t *sarea_priv;
207
208 u32 fb_location;
Dave Airlied5ea7022006-03-19 19:37:55 +1100209 u32 fb_size;
210 int new_memmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 int gart_size;
213 u32 gart_vm_start;
214 unsigned long gart_buffers_offset;
215
216 int cp_mode;
217 int cp_running;
218
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000219 drm_radeon_freelist_t *head;
220 drm_radeon_freelist_t *tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 int last_buf;
222 volatile u32 *scratch;
223 int writeback_works;
224
225 int usec_timeout;
226
227 int microcode_version;
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 struct {
230 u32 boxes;
231 int freelist_timeouts;
232 int freelist_loops;
233 int requested_bufs;
234 int last_frame_reads;
235 int last_clear_reads;
236 int clears;
237 int texture_uploads;
238 } stats;
239
240 int do_boxes;
241 int page_flipping;
242 int current_page;
243
244 u32 color_fmt;
245 unsigned int front_offset;
246 unsigned int front_pitch;
247 unsigned int back_offset;
248 unsigned int back_pitch;
249
250 u32 depth_fmt;
251 unsigned int depth_offset;
252 unsigned int depth_pitch;
253
254 u32 front_pitch_offset;
255 u32 back_pitch_offset;
256 u32 depth_pitch_offset;
257
258 drm_radeon_depth_clear_t depth_clear;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 unsigned long ring_offset;
261 unsigned long ring_rptr_offset;
262 unsigned long buffers_offset;
263 unsigned long gart_textures_offset;
264
265 drm_local_map_t *sarea;
266 drm_local_map_t *mmio;
267 drm_local_map_t *cp_ring;
268 drm_local_map_t *ring_rptr;
269 drm_local_map_t *gart_textures;
270
271 struct mem_block *gart_heap;
272 struct mem_block *fb_heap;
273
274 /* SW interrupt */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000275 wait_queue_head_t swi_queue;
276 atomic_t swi_emitted;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 struct radeon_surface surfaces[RADEON_MAX_SURFACES];
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000279 struct radeon_virt_surface virt_surfaces[2 * RADEON_MAX_SURFACES];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000281 unsigned long pcigart_offset;
282 drm_ati_pcigart_info gart_info;
Dave Airlieea98a922005-09-11 20:28:11 +1000283
Dave Airlieee4621f2006-03-19 19:45:26 +1100284 u32 scratch_ages[5];
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 /* starting from here on, data is preserved accross an open */
287 uint32_t flags; /* see radeon_chip_flags */
288} drm_radeon_private_t;
289
290typedef struct drm_radeon_buf_priv {
291 u32 age;
292} drm_radeon_buf_priv_t;
293
Dave Airlieb3a83632005-09-30 18:37:36 +1000294typedef struct drm_radeon_kcmd_buffer {
295 int bufsz;
296 char *buf;
297 int nbox;
298 drm_clip_rect_t __user *boxes;
299} drm_radeon_kcmd_buffer_t;
300
Dave Airlie689b9d72005-09-30 17:09:07 +1000301extern int radeon_no_wb;
Dave Airlieb3a83632005-09-30 18:37:36 +1000302extern drm_ioctl_desc_t radeon_ioctls[];
303extern int radeon_max_ioctl;
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 /* radeon_cp.c */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000306extern int radeon_cp_init(DRM_IOCTL_ARGS);
307extern int radeon_cp_start(DRM_IOCTL_ARGS);
308extern int radeon_cp_stop(DRM_IOCTL_ARGS);
309extern int radeon_cp_reset(DRM_IOCTL_ARGS);
310extern int radeon_cp_idle(DRM_IOCTL_ARGS);
311extern int radeon_cp_resume(DRM_IOCTL_ARGS);
312extern int radeon_engine_reset(DRM_IOCTL_ARGS);
313extern int radeon_fullscreen(DRM_IOCTL_ARGS);
314extern int radeon_cp_buffers(DRM_IOCTL_ARGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000316extern void radeon_freelist_reset(drm_device_t * dev);
317extern drm_buf_t *radeon_freelist_get(drm_device_t * dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000319extern int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000321extern int radeon_do_cp_idle(drm_radeon_private_t * dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323extern int radeon_driver_preinit(struct drm_device *dev, unsigned long flags);
Dave Airlie836cf042005-07-10 19:27:04 +1000324extern int radeon_presetup(struct drm_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325extern int radeon_driver_postcleanup(struct drm_device *dev);
326
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000327extern int radeon_mem_alloc(DRM_IOCTL_ARGS);
328extern int radeon_mem_free(DRM_IOCTL_ARGS);
329extern int radeon_mem_init_heap(DRM_IOCTL_ARGS);
330extern void radeon_mem_takedown(struct mem_block **heap);
331extern void radeon_mem_release(DRMFILE filp, struct mem_block *heap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 /* radeon_irq.c */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000334extern int radeon_irq_emit(DRM_IOCTL_ARGS);
335extern int radeon_irq_wait(DRM_IOCTL_ARGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000337extern void radeon_do_release(drm_device_t * dev);
338extern int radeon_driver_vblank_wait(drm_device_t * dev,
339 unsigned int *sequence);
340extern irqreturn_t radeon_driver_irq_handler(DRM_IRQ_ARGS);
341extern void radeon_driver_irq_preinstall(drm_device_t * dev);
342extern void radeon_driver_irq_postinstall(drm_device_t * dev);
343extern void radeon_driver_irq_uninstall(drm_device_t * dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Dave Airlie22eae942005-11-10 22:16:34 +1100345extern int radeon_driver_load(struct drm_device *dev, unsigned long flags);
346extern int radeon_driver_unload(struct drm_device *dev);
347extern int radeon_driver_firstopen(struct drm_device *dev);
348extern void radeon_driver_preclose(drm_device_t * dev, DRMFILE filp);
349extern void radeon_driver_postclose(drm_device_t * dev, drm_file_t * filp);
350extern void radeon_driver_lastclose(drm_device_t * dev);
351extern int radeon_driver_open(drm_device_t * dev, drm_file_t * filp_priv);
Dave Airlie9a186642005-06-23 21:29:18 +1000352extern long radeon_compat_ioctl(struct file *filp, unsigned int cmd,
353 unsigned long arg);
354
Dave Airlie414ed532005-08-16 20:43:16 +1000355/* r300_cmdbuf.c */
356extern void r300_init_reg_flags(void);
357
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000358extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
359 drm_file_t * filp_priv,
Dave Airlieb3a83632005-09-30 18:37:36 +1000360 drm_radeon_kcmd_buffer_t * cmdbuf);
Dave Airlie414ed532005-08-16 20:43:16 +1000361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362/* Flags for stats.boxes
363 */
364#define RADEON_BOX_DMA_IDLE 0x1
365#define RADEON_BOX_RING_FULL 0x2
366#define RADEON_BOX_FLIP 0x4
367#define RADEON_BOX_WAIT_IDLE 0x8
368#define RADEON_BOX_TEXTURE_LOAD 0x10
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370/* Register definitions, register access macros and drmAddMap constants
371 * for Radeon kernel driver.
372 */
373
374#define RADEON_AGP_COMMAND 0x0f60
Dave Airlied985c102006-01-02 21:32:48 +1100375#define RADEON_AGP_COMMAND_PCI_CONFIG 0x0060 /* offset in PCI config */
376# define RADEON_AGP_ENABLE (1<<8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#define RADEON_AUX_SCISSOR_CNTL 0x26f0
378# define RADEON_EXCLUSIVE_SCISSOR_0 (1 << 24)
379# define RADEON_EXCLUSIVE_SCISSOR_1 (1 << 25)
380# define RADEON_EXCLUSIVE_SCISSOR_2 (1 << 26)
381# define RADEON_SCISSOR_0_ENABLE (1 << 28)
382# define RADEON_SCISSOR_1_ENABLE (1 << 29)
383# define RADEON_SCISSOR_2_ENABLE (1 << 30)
384
385#define RADEON_BUS_CNTL 0x0030
386# define RADEON_BUS_MASTER_DIS (1 << 6)
387
388#define RADEON_CLOCK_CNTL_DATA 0x000c
389# define RADEON_PLL_WR_EN (1 << 7)
390#define RADEON_CLOCK_CNTL_INDEX 0x0008
391#define RADEON_CONFIG_APER_SIZE 0x0108
Dave Airlied985c102006-01-02 21:32:48 +1100392#define RADEON_CONFIG_MEMSIZE 0x00f8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393#define RADEON_CRTC_OFFSET 0x0224
394#define RADEON_CRTC_OFFSET_CNTL 0x0228
395# define RADEON_CRTC_TILE_EN (1 << 15)
396# define RADEON_CRTC_OFFSET_FLIP_CNTL (1 << 16)
397#define RADEON_CRTC2_OFFSET 0x0324
398#define RADEON_CRTC2_OFFSET_CNTL 0x0328
399
Dave Airlieea98a922005-09-11 20:28:11 +1000400#define RADEON_PCIE_INDEX 0x0030
401#define RADEON_PCIE_DATA 0x0034
402#define RADEON_PCIE_TX_GART_CNTL 0x10
403# define RADEON_PCIE_TX_GART_EN (1 << 0)
404# define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_PASS_THRU (0<<1)
405# define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_CLAMP_LO (1<<1)
406# define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD (3<<1)
407# define RADEON_PCIE_TX_GART_MODE_32_128_CACHE (0<<3)
408# define RADEON_PCIE_TX_GART_MODE_8_4_128_CACHE (1<<3)
409# define RADEON_PCIE_TX_GART_CHK_RW_VALID_EN (1<<5)
410# define RADEON_PCIE_TX_GART_INVALIDATE_TLB (1<<8)
411#define RADEON_PCIE_TX_DISCARD_RD_ADDR_LO 0x11
412#define RADEON_PCIE_TX_DISCARD_RD_ADDR_HI 0x12
413#define RADEON_PCIE_TX_GART_BASE 0x13
414#define RADEON_PCIE_TX_GART_START_LO 0x14
415#define RADEON_PCIE_TX_GART_START_HI 0x15
416#define RADEON_PCIE_TX_GART_END_LO 0x16
417#define RADEON_PCIE_TX_GART_END_HI 0x17
418
Dave Airlie414ed532005-08-16 20:43:16 +1000419#define RADEON_MPP_TB_CONFIG 0x01c0
420#define RADEON_MEM_CNTL 0x0140
421#define RADEON_MEM_SDRAM_MODE_REG 0x0158
422#define RADEON_AGP_BASE 0x0170
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424#define RADEON_RB3D_COLOROFFSET 0x1c40
425#define RADEON_RB3D_COLORPITCH 0x1c48
426
427#define RADEON_DP_GUI_MASTER_CNTL 0x146c
428# define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
429# define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
430# define RADEON_GMC_BRUSH_SOLID_COLOR (13 << 4)
431# define RADEON_GMC_BRUSH_NONE (15 << 4)
432# define RADEON_GMC_DST_16BPP (4 << 8)
433# define RADEON_GMC_DST_24BPP (5 << 8)
434# define RADEON_GMC_DST_32BPP (6 << 8)
435# define RADEON_GMC_DST_DATATYPE_SHIFT 8
436# define RADEON_GMC_SRC_DATATYPE_COLOR (3 << 12)
437# define RADEON_DP_SRC_SOURCE_MEMORY (2 << 24)
438# define RADEON_DP_SRC_SOURCE_HOST_DATA (3 << 24)
439# define RADEON_GMC_CLR_CMP_CNTL_DIS (1 << 28)
440# define RADEON_GMC_WR_MSK_DIS (1 << 30)
441# define RADEON_ROP3_S 0x00cc0000
442# define RADEON_ROP3_P 0x00f00000
443#define RADEON_DP_WRITE_MASK 0x16cc
444#define RADEON_DST_PITCH_OFFSET 0x142c
445#define RADEON_DST_PITCH_OFFSET_C 0x1c80
446# define RADEON_DST_TILE_LINEAR (0 << 30)
447# define RADEON_DST_TILE_MACRO (1 << 30)
448# define RADEON_DST_TILE_MICRO (2 << 30)
449# define RADEON_DST_TILE_BOTH (3 << 30)
450
451#define RADEON_SCRATCH_REG0 0x15e0
452#define RADEON_SCRATCH_REG1 0x15e4
453#define RADEON_SCRATCH_REG2 0x15e8
454#define RADEON_SCRATCH_REG3 0x15ec
455#define RADEON_SCRATCH_REG4 0x15f0
456#define RADEON_SCRATCH_REG5 0x15f4
457#define RADEON_SCRATCH_UMSK 0x0770
458#define RADEON_SCRATCH_ADDR 0x0774
459
460#define RADEON_SCRATCHOFF( x ) (RADEON_SCRATCH_REG_OFFSET + 4*(x))
461
462#define GET_SCRATCH( x ) (dev_priv->writeback_works \
463 ? DRM_READ32( dev_priv->ring_rptr, RADEON_SCRATCHOFF(x) ) \
464 : RADEON_READ( RADEON_SCRATCH_REG0 + 4*(x) ) )
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define RADEON_GEN_INT_CNTL 0x0040
467# define RADEON_CRTC_VBLANK_MASK (1 << 0)
468# define RADEON_GUI_IDLE_INT_ENABLE (1 << 19)
469# define RADEON_SW_INT_ENABLE (1 << 25)
470
471#define RADEON_GEN_INT_STATUS 0x0044
472# define RADEON_CRTC_VBLANK_STAT (1 << 0)
473# define RADEON_CRTC_VBLANK_STAT_ACK (1 << 0)
474# define RADEON_GUI_IDLE_INT_TEST_ACK (1 << 19)
475# define RADEON_SW_INT_TEST (1 << 25)
476# define RADEON_SW_INT_TEST_ACK (1 << 25)
477# define RADEON_SW_INT_FIRE (1 << 26)
478
479#define RADEON_HOST_PATH_CNTL 0x0130
480# define RADEON_HDP_SOFT_RESET (1 << 26)
481# define RADEON_HDP_WC_TIMEOUT_MASK (7 << 28)
482# define RADEON_HDP_WC_TIMEOUT_28BCLK (7 << 28)
483
484#define RADEON_ISYNC_CNTL 0x1724
485# define RADEON_ISYNC_ANY2D_IDLE3D (1 << 0)
486# define RADEON_ISYNC_ANY3D_IDLE2D (1 << 1)
487# define RADEON_ISYNC_TRIG2D_IDLE3D (1 << 2)
488# define RADEON_ISYNC_TRIG3D_IDLE2D (1 << 3)
489# define RADEON_ISYNC_WAIT_IDLEGUI (1 << 4)
490# define RADEON_ISYNC_CPSCRATCH_IDLEGUI (1 << 5)
491
492#define RADEON_RBBM_GUICNTL 0x172c
493# define RADEON_HOST_DATA_SWAP_NONE (0 << 0)
494# define RADEON_HOST_DATA_SWAP_16BIT (1 << 0)
495# define RADEON_HOST_DATA_SWAP_32BIT (2 << 0)
496# define RADEON_HOST_DATA_SWAP_HDW (3 << 0)
497
498#define RADEON_MC_AGP_LOCATION 0x014c
499#define RADEON_MC_FB_LOCATION 0x0148
500#define RADEON_MCLK_CNTL 0x0012
501# define RADEON_FORCEON_MCLKA (1 << 16)
502# define RADEON_FORCEON_MCLKB (1 << 17)
503# define RADEON_FORCEON_YCLKA (1 << 18)
504# define RADEON_FORCEON_YCLKB (1 << 19)
505# define RADEON_FORCEON_MC (1 << 20)
506# define RADEON_FORCEON_AIC (1 << 21)
507
508#define RADEON_PP_BORDER_COLOR_0 0x1d40
509#define RADEON_PP_BORDER_COLOR_1 0x1d44
510#define RADEON_PP_BORDER_COLOR_2 0x1d48
511#define RADEON_PP_CNTL 0x1c38
512# define RADEON_SCISSOR_ENABLE (1 << 1)
513#define RADEON_PP_LUM_MATRIX 0x1d00
514#define RADEON_PP_MISC 0x1c14
515#define RADEON_PP_ROT_MATRIX_0 0x1d58
516#define RADEON_PP_TXFILTER_0 0x1c54
517#define RADEON_PP_TXOFFSET_0 0x1c5c
518#define RADEON_PP_TXFILTER_1 0x1c6c
519#define RADEON_PP_TXFILTER_2 0x1c84
520
521#define RADEON_RB2D_DSTCACHE_CTLSTAT 0x342c
522# define RADEON_RB2D_DC_FLUSH (3 << 0)
523# define RADEON_RB2D_DC_FREE (3 << 2)
524# define RADEON_RB2D_DC_FLUSH_ALL 0xf
525# define RADEON_RB2D_DC_BUSY (1 << 31)
526#define RADEON_RB3D_CNTL 0x1c3c
527# define RADEON_ALPHA_BLEND_ENABLE (1 << 0)
528# define RADEON_PLANE_MASK_ENABLE (1 << 1)
529# define RADEON_DITHER_ENABLE (1 << 2)
530# define RADEON_ROUND_ENABLE (1 << 3)
531# define RADEON_SCALE_DITHER_ENABLE (1 << 4)
532# define RADEON_DITHER_INIT (1 << 5)
533# define RADEON_ROP_ENABLE (1 << 6)
534# define RADEON_STENCIL_ENABLE (1 << 7)
535# define RADEON_Z_ENABLE (1 << 8)
536# define RADEON_ZBLOCK16 (1 << 15)
537#define RADEON_RB3D_DEPTHOFFSET 0x1c24
538#define RADEON_RB3D_DEPTHCLEARVALUE 0x3230
539#define RADEON_RB3D_DEPTHPITCH 0x1c28
540#define RADEON_RB3D_PLANEMASK 0x1d84
541#define RADEON_RB3D_STENCILREFMASK 0x1d7c
542#define RADEON_RB3D_ZCACHE_MODE 0x3250
543#define RADEON_RB3D_ZCACHE_CTLSTAT 0x3254
544# define RADEON_RB3D_ZC_FLUSH (1 << 0)
545# define RADEON_RB3D_ZC_FREE (1 << 2)
546# define RADEON_RB3D_ZC_FLUSH_ALL 0x5
547# define RADEON_RB3D_ZC_BUSY (1 << 31)
548#define RADEON_RB3D_ZSTENCILCNTL 0x1c2c
549# define RADEON_Z_TEST_MASK (7 << 4)
550# define RADEON_Z_TEST_ALWAYS (7 << 4)
551# define RADEON_Z_HIERARCHY_ENABLE (1 << 8)
552# define RADEON_STENCIL_TEST_ALWAYS (7 << 12)
553# define RADEON_STENCIL_S_FAIL_REPLACE (2 << 16)
554# define RADEON_STENCIL_ZPASS_REPLACE (2 << 20)
555# define RADEON_STENCIL_ZFAIL_REPLACE (2 << 24)
556# define RADEON_Z_COMPRESSION_ENABLE (1 << 28)
557# define RADEON_FORCE_Z_DIRTY (1 << 29)
558# define RADEON_Z_WRITE_ENABLE (1 << 30)
559# define RADEON_Z_DECOMPRESSION_ENABLE (1 << 31)
560#define RADEON_RBBM_SOFT_RESET 0x00f0
561# define RADEON_SOFT_RESET_CP (1 << 0)
562# define RADEON_SOFT_RESET_HI (1 << 1)
563# define RADEON_SOFT_RESET_SE (1 << 2)
564# define RADEON_SOFT_RESET_RE (1 << 3)
565# define RADEON_SOFT_RESET_PP (1 << 4)
566# define RADEON_SOFT_RESET_E2 (1 << 5)
567# define RADEON_SOFT_RESET_RB (1 << 6)
568# define RADEON_SOFT_RESET_HDP (1 << 7)
569#define RADEON_RBBM_STATUS 0x0e40
570# define RADEON_RBBM_FIFOCNT_MASK 0x007f
571# define RADEON_RBBM_ACTIVE (1 << 31)
572#define RADEON_RE_LINE_PATTERN 0x1cd0
573#define RADEON_RE_MISC 0x26c4
574#define RADEON_RE_TOP_LEFT 0x26c0
575#define RADEON_RE_WIDTH_HEIGHT 0x1c44
576#define RADEON_RE_STIPPLE_ADDR 0x1cc8
577#define RADEON_RE_STIPPLE_DATA 0x1ccc
578
579#define RADEON_SCISSOR_TL_0 0x1cd8
580#define RADEON_SCISSOR_BR_0 0x1cdc
581#define RADEON_SCISSOR_TL_1 0x1ce0
582#define RADEON_SCISSOR_BR_1 0x1ce4
583#define RADEON_SCISSOR_TL_2 0x1ce8
584#define RADEON_SCISSOR_BR_2 0x1cec
585#define RADEON_SE_COORD_FMT 0x1c50
586#define RADEON_SE_CNTL 0x1c4c
587# define RADEON_FFACE_CULL_CW (0 << 0)
588# define RADEON_BFACE_SOLID (3 << 1)
589# define RADEON_FFACE_SOLID (3 << 3)
590# define RADEON_FLAT_SHADE_VTX_LAST (3 << 6)
591# define RADEON_DIFFUSE_SHADE_FLAT (1 << 8)
592# define RADEON_DIFFUSE_SHADE_GOURAUD (2 << 8)
593# define RADEON_ALPHA_SHADE_FLAT (1 << 10)
594# define RADEON_ALPHA_SHADE_GOURAUD (2 << 10)
595# define RADEON_SPECULAR_SHADE_FLAT (1 << 12)
596# define RADEON_SPECULAR_SHADE_GOURAUD (2 << 12)
597# define RADEON_FOG_SHADE_FLAT (1 << 14)
598# define RADEON_FOG_SHADE_GOURAUD (2 << 14)
599# define RADEON_VPORT_XY_XFORM_ENABLE (1 << 24)
600# define RADEON_VPORT_Z_XFORM_ENABLE (1 << 25)
601# define RADEON_VTX_PIX_CENTER_OGL (1 << 27)
602# define RADEON_ROUND_MODE_TRUNC (0 << 28)
603# define RADEON_ROUND_PREC_8TH_PIX (1 << 30)
604#define RADEON_SE_CNTL_STATUS 0x2140
605#define RADEON_SE_LINE_WIDTH 0x1db8
606#define RADEON_SE_VPORT_XSCALE 0x1d98
607#define RADEON_SE_ZBIAS_FACTOR 0x1db0
608#define RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED 0x2210
609#define RADEON_SE_TCL_OUTPUT_VTX_FMT 0x2254
610#define RADEON_SE_TCL_VECTOR_INDX_REG 0x2200
611# define RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT 16
612# define RADEON_VEC_INDX_DWORD_COUNT_SHIFT 28
613#define RADEON_SE_TCL_VECTOR_DATA_REG 0x2204
614#define RADEON_SE_TCL_SCALAR_INDX_REG 0x2208
615# define RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT 16
616#define RADEON_SE_TCL_SCALAR_DATA_REG 0x220C
617#define RADEON_SURFACE_ACCESS_FLAGS 0x0bf8
618#define RADEON_SURFACE_ACCESS_CLR 0x0bfc
619#define RADEON_SURFACE_CNTL 0x0b00
620# define RADEON_SURF_TRANSLATION_DIS (1 << 8)
621# define RADEON_NONSURF_AP0_SWP_MASK (3 << 20)
622# define RADEON_NONSURF_AP0_SWP_LITTLE (0 << 20)
623# define RADEON_NONSURF_AP0_SWP_BIG16 (1 << 20)
624# define RADEON_NONSURF_AP0_SWP_BIG32 (2 << 20)
625# define RADEON_NONSURF_AP1_SWP_MASK (3 << 22)
626# define RADEON_NONSURF_AP1_SWP_LITTLE (0 << 22)
627# define RADEON_NONSURF_AP1_SWP_BIG16 (1 << 22)
628# define RADEON_NONSURF_AP1_SWP_BIG32 (2 << 22)
629#define RADEON_SURFACE0_INFO 0x0b0c
630# define RADEON_SURF_PITCHSEL_MASK (0x1ff << 0)
631# define RADEON_SURF_TILE_MODE_MASK (3 << 16)
632# define RADEON_SURF_TILE_MODE_MACRO (0 << 16)
633# define RADEON_SURF_TILE_MODE_MICRO (1 << 16)
634# define RADEON_SURF_TILE_MODE_32BIT_Z (2 << 16)
635# define RADEON_SURF_TILE_MODE_16BIT_Z (3 << 16)
636#define RADEON_SURFACE0_LOWER_BOUND 0x0b04
637#define RADEON_SURFACE0_UPPER_BOUND 0x0b08
638# define RADEON_SURF_ADDRESS_FIXED_MASK (0x3ff << 0)
639#define RADEON_SURFACE1_INFO 0x0b1c
640#define RADEON_SURFACE1_LOWER_BOUND 0x0b14
641#define RADEON_SURFACE1_UPPER_BOUND 0x0b18
642#define RADEON_SURFACE2_INFO 0x0b2c
643#define RADEON_SURFACE2_LOWER_BOUND 0x0b24
644#define RADEON_SURFACE2_UPPER_BOUND 0x0b28
645#define RADEON_SURFACE3_INFO 0x0b3c
646#define RADEON_SURFACE3_LOWER_BOUND 0x0b34
647#define RADEON_SURFACE3_UPPER_BOUND 0x0b38
648#define RADEON_SURFACE4_INFO 0x0b4c
649#define RADEON_SURFACE4_LOWER_BOUND 0x0b44
650#define RADEON_SURFACE4_UPPER_BOUND 0x0b48
651#define RADEON_SURFACE5_INFO 0x0b5c
652#define RADEON_SURFACE5_LOWER_BOUND 0x0b54
653#define RADEON_SURFACE5_UPPER_BOUND 0x0b58
654#define RADEON_SURFACE6_INFO 0x0b6c
655#define RADEON_SURFACE6_LOWER_BOUND 0x0b64
656#define RADEON_SURFACE6_UPPER_BOUND 0x0b68
657#define RADEON_SURFACE7_INFO 0x0b7c
658#define RADEON_SURFACE7_LOWER_BOUND 0x0b74
659#define RADEON_SURFACE7_UPPER_BOUND 0x0b78
660#define RADEON_SW_SEMAPHORE 0x013c
661
662#define RADEON_WAIT_UNTIL 0x1720
663# define RADEON_WAIT_CRTC_PFLIP (1 << 0)
Dave Airlied985c102006-01-02 21:32:48 +1100664# define RADEON_WAIT_2D_IDLE (1 << 14)
665# define RADEON_WAIT_3D_IDLE (1 << 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666# define RADEON_WAIT_2D_IDLECLEAN (1 << 16)
667# define RADEON_WAIT_3D_IDLECLEAN (1 << 17)
668# define RADEON_WAIT_HOST_IDLECLEAN (1 << 18)
669
670#define RADEON_RB3D_ZMASKOFFSET 0x3234
671#define RADEON_RB3D_ZSTENCILCNTL 0x1c2c
672# define RADEON_DEPTH_FORMAT_16BIT_INT_Z (0 << 0)
673# define RADEON_DEPTH_FORMAT_24BIT_INT_Z (2 << 0)
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675/* CP registers */
676#define RADEON_CP_ME_RAM_ADDR 0x07d4
677#define RADEON_CP_ME_RAM_RADDR 0x07d8
678#define RADEON_CP_ME_RAM_DATAH 0x07dc
679#define RADEON_CP_ME_RAM_DATAL 0x07e0
680
681#define RADEON_CP_RB_BASE 0x0700
682#define RADEON_CP_RB_CNTL 0x0704
683# define RADEON_BUF_SWAP_32BIT (2 << 16)
Michel Dänzerae1b1a482006-08-07 20:37:46 +1000684# define RADEON_RB_NO_UPDATE (1 << 27)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#define RADEON_CP_RB_RPTR_ADDR 0x070c
686#define RADEON_CP_RB_RPTR 0x0710
687#define RADEON_CP_RB_WPTR 0x0714
688
689#define RADEON_CP_RB_WPTR_DELAY 0x0718
690# define RADEON_PRE_WRITE_TIMER_SHIFT 0
691# define RADEON_PRE_WRITE_LIMIT_SHIFT 23
692
693#define RADEON_CP_IB_BASE 0x0738
694
695#define RADEON_CP_CSQ_CNTL 0x0740
696# define RADEON_CSQ_CNT_PRIMARY_MASK (0xff << 0)
697# define RADEON_CSQ_PRIDIS_INDDIS (0 << 28)
698# define RADEON_CSQ_PRIPIO_INDDIS (1 << 28)
699# define RADEON_CSQ_PRIBM_INDDIS (2 << 28)
700# define RADEON_CSQ_PRIPIO_INDBM (3 << 28)
701# define RADEON_CSQ_PRIBM_INDBM (4 << 28)
702# define RADEON_CSQ_PRIPIO_INDPIO (15 << 28)
703
704#define RADEON_AIC_CNTL 0x01d0
705# define RADEON_PCIGART_TRANSLATE_EN (1 << 0)
706#define RADEON_AIC_STAT 0x01d4
707#define RADEON_AIC_PT_BASE 0x01d8
708#define RADEON_AIC_LO_ADDR 0x01dc
709#define RADEON_AIC_HI_ADDR 0x01e0
710#define RADEON_AIC_TLB_ADDR 0x01e4
711#define RADEON_AIC_TLB_DATA 0x01e8
712
713/* CP command packets */
714#define RADEON_CP_PACKET0 0x00000000
715# define RADEON_ONE_REG_WR (1 << 15)
716#define RADEON_CP_PACKET1 0x40000000
717#define RADEON_CP_PACKET2 0x80000000
718#define RADEON_CP_PACKET3 0xC0000000
Dave Airlie414ed532005-08-16 20:43:16 +1000719# define RADEON_CP_NOP 0x00001000
720# define RADEON_CP_NEXT_CHAR 0x00001900
721# define RADEON_CP_PLY_NEXTSCAN 0x00001D00
722# define RADEON_CP_SET_SCISSORS 0x00001E00
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000723 /* GEN_INDX_PRIM is unsupported starting with R300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724# define RADEON_3D_RNDR_GEN_INDX_PRIM 0x00002300
725# define RADEON_WAIT_FOR_IDLE 0x00002600
726# define RADEON_3D_DRAW_VBUF 0x00002800
727# define RADEON_3D_DRAW_IMMD 0x00002900
728# define RADEON_3D_DRAW_INDX 0x00002A00
Dave Airlie414ed532005-08-16 20:43:16 +1000729# define RADEON_CP_LOAD_PALETTE 0x00002C00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730# define RADEON_3D_LOAD_VBPNTR 0x00002F00
731# define RADEON_MPEG_IDCT_MACROBLOCK 0x00003000
732# define RADEON_MPEG_IDCT_MACROBLOCK_REV 0x00003100
733# define RADEON_3D_CLEAR_ZMASK 0x00003200
Dave Airlie414ed532005-08-16 20:43:16 +1000734# define RADEON_CP_INDX_BUFFER 0x00003300
735# define RADEON_CP_3D_DRAW_VBUF_2 0x00003400
736# define RADEON_CP_3D_DRAW_IMMD_2 0x00003500
737# define RADEON_CP_3D_DRAW_INDX_2 0x00003600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738# define RADEON_3D_CLEAR_HIZ 0x00003700
Dave Airlie414ed532005-08-16 20:43:16 +1000739# define RADEON_CP_3D_CLEAR_CMASK 0x00003802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740# define RADEON_CNTL_HOSTDATA_BLT 0x00009400
741# define RADEON_CNTL_PAINT_MULTI 0x00009A00
742# define RADEON_CNTL_BITBLT_MULTI 0x00009B00
743# define RADEON_CNTL_SET_SCISSORS 0xC0001E00
744
745#define RADEON_CP_PACKET_MASK 0xC0000000
746#define RADEON_CP_PACKET_COUNT_MASK 0x3fff0000
747#define RADEON_CP_PACKET0_REG_MASK 0x000007ff
748#define RADEON_CP_PACKET1_REG0_MASK 0x000007ff
749#define RADEON_CP_PACKET1_REG1_MASK 0x003ff800
750
751#define RADEON_VTX_Z_PRESENT (1 << 31)
752#define RADEON_VTX_PKCOLOR_PRESENT (1 << 3)
753
754#define RADEON_PRIM_TYPE_NONE (0 << 0)
755#define RADEON_PRIM_TYPE_POINT (1 << 0)
756#define RADEON_PRIM_TYPE_LINE (2 << 0)
757#define RADEON_PRIM_TYPE_LINE_STRIP (3 << 0)
758#define RADEON_PRIM_TYPE_TRI_LIST (4 << 0)
759#define RADEON_PRIM_TYPE_TRI_FAN (5 << 0)
760#define RADEON_PRIM_TYPE_TRI_STRIP (6 << 0)
761#define RADEON_PRIM_TYPE_TRI_TYPE2 (7 << 0)
762#define RADEON_PRIM_TYPE_RECT_LIST (8 << 0)
763#define RADEON_PRIM_TYPE_3VRT_POINT_LIST (9 << 0)
764#define RADEON_PRIM_TYPE_3VRT_LINE_LIST (10 << 0)
765#define RADEON_PRIM_TYPE_MASK 0xf
766#define RADEON_PRIM_WALK_IND (1 << 4)
767#define RADEON_PRIM_WALK_LIST (2 << 4)
768#define RADEON_PRIM_WALK_RING (3 << 4)
769#define RADEON_COLOR_ORDER_BGRA (0 << 6)
770#define RADEON_COLOR_ORDER_RGBA (1 << 6)
771#define RADEON_MAOS_ENABLE (1 << 7)
772#define RADEON_VTX_FMT_R128_MODE (0 << 8)
773#define RADEON_VTX_FMT_RADEON_MODE (1 << 8)
774#define RADEON_NUM_VERTICES_SHIFT 16
775
776#define RADEON_COLOR_FORMAT_CI8 2
777#define RADEON_COLOR_FORMAT_ARGB1555 3
778#define RADEON_COLOR_FORMAT_RGB565 4
779#define RADEON_COLOR_FORMAT_ARGB8888 6
780#define RADEON_COLOR_FORMAT_RGB332 7
781#define RADEON_COLOR_FORMAT_RGB8 9
782#define RADEON_COLOR_FORMAT_ARGB4444 15
783
784#define RADEON_TXFORMAT_I8 0
785#define RADEON_TXFORMAT_AI88 1
786#define RADEON_TXFORMAT_RGB332 2
787#define RADEON_TXFORMAT_ARGB1555 3
788#define RADEON_TXFORMAT_RGB565 4
789#define RADEON_TXFORMAT_ARGB4444 5
790#define RADEON_TXFORMAT_ARGB8888 6
791#define RADEON_TXFORMAT_RGBA8888 7
792#define RADEON_TXFORMAT_Y8 8
793#define RADEON_TXFORMAT_VYUY422 10
794#define RADEON_TXFORMAT_YVYU422 11
795#define RADEON_TXFORMAT_DXT1 12
796#define RADEON_TXFORMAT_DXT23 14
797#define RADEON_TXFORMAT_DXT45 15
798
799#define R200_PP_TXCBLEND_0 0x2f00
800#define R200_PP_TXCBLEND_1 0x2f10
801#define R200_PP_TXCBLEND_2 0x2f20
802#define R200_PP_TXCBLEND_3 0x2f30
803#define R200_PP_TXCBLEND_4 0x2f40
804#define R200_PP_TXCBLEND_5 0x2f50
805#define R200_PP_TXCBLEND_6 0x2f60
806#define R200_PP_TXCBLEND_7 0x2f70
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000807#define R200_SE_TCL_LIGHT_MODEL_CTL_0 0x2268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808#define R200_PP_TFACTOR_0 0x2ee0
809#define R200_SE_VTX_FMT_0 0x2088
810#define R200_SE_VAP_CNTL 0x2080
811#define R200_SE_TCL_MATRIX_SEL_0 0x2230
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000812#define R200_SE_TCL_TEX_PROC_CTL_2 0x22a8
813#define R200_SE_TCL_UCP_VERT_BLEND_CTL 0x22c0
814#define R200_PP_TXFILTER_5 0x2ca0
815#define R200_PP_TXFILTER_4 0x2c80
816#define R200_PP_TXFILTER_3 0x2c60
817#define R200_PP_TXFILTER_2 0x2c40
818#define R200_PP_TXFILTER_1 0x2c20
819#define R200_PP_TXFILTER_0 0x2c00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820#define R200_PP_TXOFFSET_5 0x2d78
821#define R200_PP_TXOFFSET_4 0x2d60
822#define R200_PP_TXOFFSET_3 0x2d48
823#define R200_PP_TXOFFSET_2 0x2d30
824#define R200_PP_TXOFFSET_1 0x2d18
825#define R200_PP_TXOFFSET_0 0x2d00
826
827#define R200_PP_CUBIC_FACES_0 0x2c18
828#define R200_PP_CUBIC_FACES_1 0x2c38
829#define R200_PP_CUBIC_FACES_2 0x2c58
830#define R200_PP_CUBIC_FACES_3 0x2c78
831#define R200_PP_CUBIC_FACES_4 0x2c98
832#define R200_PP_CUBIC_FACES_5 0x2cb8
833#define R200_PP_CUBIC_OFFSET_F1_0 0x2d04
834#define R200_PP_CUBIC_OFFSET_F2_0 0x2d08
835#define R200_PP_CUBIC_OFFSET_F3_0 0x2d0c
836#define R200_PP_CUBIC_OFFSET_F4_0 0x2d10
837#define R200_PP_CUBIC_OFFSET_F5_0 0x2d14
838#define R200_PP_CUBIC_OFFSET_F1_1 0x2d1c
839#define R200_PP_CUBIC_OFFSET_F2_1 0x2d20
840#define R200_PP_CUBIC_OFFSET_F3_1 0x2d24
841#define R200_PP_CUBIC_OFFSET_F4_1 0x2d28
842#define R200_PP_CUBIC_OFFSET_F5_1 0x2d2c
843#define R200_PP_CUBIC_OFFSET_F1_2 0x2d34
844#define R200_PP_CUBIC_OFFSET_F2_2 0x2d38
845#define R200_PP_CUBIC_OFFSET_F3_2 0x2d3c
846#define R200_PP_CUBIC_OFFSET_F4_2 0x2d40
847#define R200_PP_CUBIC_OFFSET_F5_2 0x2d44
848#define R200_PP_CUBIC_OFFSET_F1_3 0x2d4c
849#define R200_PP_CUBIC_OFFSET_F2_3 0x2d50
850#define R200_PP_CUBIC_OFFSET_F3_3 0x2d54
851#define R200_PP_CUBIC_OFFSET_F4_3 0x2d58
852#define R200_PP_CUBIC_OFFSET_F5_3 0x2d5c
853#define R200_PP_CUBIC_OFFSET_F1_4 0x2d64
854#define R200_PP_CUBIC_OFFSET_F2_4 0x2d68
855#define R200_PP_CUBIC_OFFSET_F3_4 0x2d6c
856#define R200_PP_CUBIC_OFFSET_F4_4 0x2d70
857#define R200_PP_CUBIC_OFFSET_F5_4 0x2d74
858#define R200_PP_CUBIC_OFFSET_F1_5 0x2d7c
859#define R200_PP_CUBIC_OFFSET_F2_5 0x2d80
860#define R200_PP_CUBIC_OFFSET_F3_5 0x2d84
861#define R200_PP_CUBIC_OFFSET_F4_5 0x2d88
862#define R200_PP_CUBIC_OFFSET_F5_5 0x2d8c
863
864#define R200_RE_AUX_SCISSOR_CNTL 0x26f0
865#define R200_SE_VTE_CNTL 0x20b0
866#define R200_SE_TCL_OUTPUT_VTX_COMP_SEL 0x2250
867#define R200_PP_TAM_DEBUG3 0x2d9c
868#define R200_PP_CNTL_X 0x2cc4
869#define R200_SE_VAP_CNTL_STATUS 0x2140
870#define R200_RE_SCISSOR_TL_0 0x1cd8
871#define R200_RE_SCISSOR_TL_1 0x1ce0
872#define R200_RE_SCISSOR_TL_2 0x1ce8
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000873#define R200_RB3D_DEPTHXY_OFFSET 0x1d60
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874#define R200_RE_AUX_SCISSOR_CNTL 0x26f0
875#define R200_SE_VTX_STATE_CNTL 0x2180
876#define R200_RE_POINTSIZE 0x2648
877#define R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0 0x2254
878
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000879#define RADEON_PP_TEX_SIZE_0 0x1d04 /* NPOT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880#define RADEON_PP_TEX_SIZE_1 0x1d0c
881#define RADEON_PP_TEX_SIZE_2 0x1d14
882
883#define RADEON_PP_CUBIC_FACES_0 0x1d24
884#define RADEON_PP_CUBIC_FACES_1 0x1d28
885#define RADEON_PP_CUBIC_FACES_2 0x1d2c
886#define RADEON_PP_CUBIC_OFFSET_T0_0 0x1dd0 /* bits [31:5] */
887#define RADEON_PP_CUBIC_OFFSET_T1_0 0x1e00
888#define RADEON_PP_CUBIC_OFFSET_T2_0 0x1e14
889
Dave Airlief2a22792006-06-24 16:55:34 +1000890#define RADEON_SE_TCL_STATE_FLUSH 0x2284
891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892#define SE_VAP_CNTL__TCL_ENA_MASK 0x00000001
893#define SE_VAP_CNTL__FORCE_W_TO_ONE_MASK 0x00010000
894#define SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT 0x00000012
895#define SE_VTE_CNTL__VTX_XY_FMT_MASK 0x00000100
896#define SE_VTE_CNTL__VTX_Z_FMT_MASK 0x00000200
897#define SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK 0x00000001
898#define SE_VTX_FMT_0__VTX_W0_PRESENT_MASK 0x00000002
899#define SE_VTX_FMT_0__VTX_COLOR_0_FMT__SHIFT 0x0000000b
900#define R200_3D_DRAW_IMMD_2 0xC0003500
901#define R200_SE_VTX_FMT_1 0x208c
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000902#define R200_RE_CNTL 0x1c50
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904#define R200_RB3D_BLENDCOLOR 0x3218
905
906#define R200_SE_TCL_POINT_SPRITE_CNTL 0x22c4
907
908#define R200_PP_TRI_PERF 0x2cf8
909
Dave Airlie9d176012005-09-11 19:55:53 +1000910#define R200_PP_AFS_0 0x2f80
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000911#define R200_PP_AFS_1 0x2f00 /* same as txcblend_0 */
Dave Airlie9d176012005-09-11 19:55:53 +1000912
Dave Airlied6fece02006-06-24 17:04:07 +1000913#define R200_VAP_PVS_CNTL_1 0x22D0
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915/* Constants */
916#define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
917
918#define RADEON_LAST_FRAME_REG RADEON_SCRATCH_REG0
919#define RADEON_LAST_DISPATCH_REG RADEON_SCRATCH_REG1
920#define RADEON_LAST_CLEAR_REG RADEON_SCRATCH_REG2
921#define RADEON_LAST_SWI_REG RADEON_SCRATCH_REG3
922#define RADEON_LAST_DISPATCH 1
923
924#define RADEON_MAX_VB_AGE 0x7fffffff
925#define RADEON_MAX_VB_VERTS (0xffff)
926
927#define RADEON_RING_HIGH_MARK 128
928
Dave Airlieea98a922005-09-11 20:28:11 +1000929#define RADEON_PCIGART_TABLE_SIZE (32*1024)
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931#define RADEON_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
932#define RADEON_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, (reg), (val) )
933#define RADEON_READ8(reg) DRM_READ8( dev_priv->mmio, (reg) )
934#define RADEON_WRITE8(reg,val) DRM_WRITE8( dev_priv->mmio, (reg), (val) )
935
936#define RADEON_WRITE_PLL( addr, val ) \
937do { \
938 RADEON_WRITE8( RADEON_CLOCK_CNTL_INDEX, \
939 ((addr) & 0x1f) | RADEON_PLL_WR_EN ); \
940 RADEON_WRITE( RADEON_CLOCK_CNTL_DATA, (val) ); \
941} while (0)
942
Dave Airlieea98a922005-09-11 20:28:11 +1000943#define RADEON_WRITE_PCIE( addr, val ) \
944do { \
945 RADEON_WRITE8( RADEON_PCIE_INDEX, \
946 ((addr) & 0xff)); \
947 RADEON_WRITE( RADEON_PCIE_DATA, (val) ); \
948} while (0)
949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950#define CP_PACKET0( reg, n ) \
951 (RADEON_CP_PACKET0 | ((n) << 16) | ((reg) >> 2))
952#define CP_PACKET0_TABLE( reg, n ) \
953 (RADEON_CP_PACKET0 | RADEON_ONE_REG_WR | ((n) << 16) | ((reg) >> 2))
954#define CP_PACKET1( reg0, reg1 ) \
955 (RADEON_CP_PACKET1 | (((reg1) >> 2) << 15) | ((reg0) >> 2))
956#define CP_PACKET2() \
957 (RADEON_CP_PACKET2)
958#define CP_PACKET3( pkt, n ) \
959 (RADEON_CP_PACKET3 | (pkt) | ((n) << 16))
960
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961/* ================================================================
962 * Engine control helper macros
963 */
964
965#define RADEON_WAIT_UNTIL_2D_IDLE() do { \
966 OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
967 OUT_RING( (RADEON_WAIT_2D_IDLECLEAN | \
968 RADEON_WAIT_HOST_IDLECLEAN) ); \
969} while (0)
970
971#define RADEON_WAIT_UNTIL_3D_IDLE() do { \
972 OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
973 OUT_RING( (RADEON_WAIT_3D_IDLECLEAN | \
974 RADEON_WAIT_HOST_IDLECLEAN) ); \
975} while (0)
976
977#define RADEON_WAIT_UNTIL_IDLE() do { \
978 OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
979 OUT_RING( (RADEON_WAIT_2D_IDLECLEAN | \
980 RADEON_WAIT_3D_IDLECLEAN | \
981 RADEON_WAIT_HOST_IDLECLEAN) ); \
982} while (0)
983
984#define RADEON_WAIT_UNTIL_PAGE_FLIPPED() do { \
985 OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
986 OUT_RING( RADEON_WAIT_CRTC_PFLIP ); \
987} while (0)
988
989#define RADEON_FLUSH_CACHE() do { \
990 OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \
991 OUT_RING( RADEON_RB2D_DC_FLUSH ); \
992} while (0)
993
994#define RADEON_PURGE_CACHE() do { \
995 OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \
996 OUT_RING( RADEON_RB2D_DC_FLUSH_ALL ); \
997} while (0)
998
999#define RADEON_FLUSH_ZCACHE() do { \
1000 OUT_RING( CP_PACKET0( RADEON_RB3D_ZCACHE_CTLSTAT, 0 ) ); \
1001 OUT_RING( RADEON_RB3D_ZC_FLUSH ); \
1002} while (0)
1003
1004#define RADEON_PURGE_ZCACHE() do { \
1005 OUT_RING( CP_PACKET0( RADEON_RB3D_ZCACHE_CTLSTAT, 0 ) ); \
1006 OUT_RING( RADEON_RB3D_ZC_FLUSH_ALL ); \
1007} while (0)
1008
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009/* ================================================================
1010 * Misc helper macros
1011 */
1012
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001013/* Perfbox functionality only.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 */
1015#define RING_SPACE_TEST_WITH_RETURN( dev_priv ) \
1016do { \
1017 if (!(dev_priv->stats.boxes & RADEON_BOX_DMA_IDLE)) { \
1018 u32 head = GET_RING_HEAD( dev_priv ); \
1019 if (head == dev_priv->ring.tail) \
1020 dev_priv->stats.boxes |= RADEON_BOX_DMA_IDLE; \
1021 } \
1022} while (0)
1023
1024#define VB_AGE_TEST_WITH_RETURN( dev_priv ) \
1025do { \
1026 drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv; \
1027 if ( sarea_priv->last_dispatch >= RADEON_MAX_VB_AGE ) { \
1028 int __ret = radeon_do_cp_idle( dev_priv ); \
1029 if ( __ret ) return __ret; \
1030 sarea_priv->last_dispatch = 0; \
1031 radeon_freelist_reset( dev ); \
1032 } \
1033} while (0)
1034
1035#define RADEON_DISPATCH_AGE( age ) do { \
1036 OUT_RING( CP_PACKET0( RADEON_LAST_DISPATCH_REG, 0 ) ); \
1037 OUT_RING( age ); \
1038} while (0)
1039
1040#define RADEON_FRAME_AGE( age ) do { \
1041 OUT_RING( CP_PACKET0( RADEON_LAST_FRAME_REG, 0 ) ); \
1042 OUT_RING( age ); \
1043} while (0)
1044
1045#define RADEON_CLEAR_AGE( age ) do { \
1046 OUT_RING( CP_PACKET0( RADEON_LAST_CLEAR_REG, 0 ) ); \
1047 OUT_RING( age ); \
1048} while (0)
1049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050/* ================================================================
1051 * Ring control
1052 */
1053
1054#define RADEON_VERBOSE 0
1055
1056#define RING_LOCALS int write, _nr; unsigned int mask; u32 *ring;
1057
1058#define BEGIN_RING( n ) do { \
1059 if ( RADEON_VERBOSE ) { \
1060 DRM_INFO( "BEGIN_RING( %d ) in %s\n", \
1061 n, __FUNCTION__ ); \
1062 } \
1063 if ( dev_priv->ring.space <= (n) * sizeof(u32) ) { \
1064 COMMIT_RING(); \
1065 radeon_wait_ring( dev_priv, (n) * sizeof(u32) ); \
1066 } \
1067 _nr = n; dev_priv->ring.space -= (n) * sizeof(u32); \
1068 ring = dev_priv->ring.start; \
1069 write = dev_priv->ring.tail; \
1070 mask = dev_priv->ring.tail_mask; \
1071} while (0)
1072
1073#define ADVANCE_RING() do { \
1074 if ( RADEON_VERBOSE ) { \
1075 DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n", \
1076 write, dev_priv->ring.tail ); \
1077 } \
1078 if (((dev_priv->ring.tail + _nr) & mask) != write) { \
1079 DRM_ERROR( \
1080 "ADVANCE_RING(): mismatch: nr: %x write: %x line: %d\n", \
1081 ((dev_priv->ring.tail + _nr) & mask), \
1082 write, __LINE__); \
1083 } else \
1084 dev_priv->ring.tail = write; \
1085} while (0)
1086
1087#define COMMIT_RING() do { \
1088 /* Flush writes to ring */ \
1089 DRM_MEMORYBARRIER(); \
1090 GET_RING_HEAD( dev_priv ); \
1091 RADEON_WRITE( RADEON_CP_RB_WPTR, dev_priv->ring.tail ); \
1092 /* read from PCI bus to ensure correct posting */ \
1093 RADEON_READ( RADEON_CP_RB_RPTR ); \
1094} while (0)
1095
1096#define OUT_RING( x ) do { \
1097 if ( RADEON_VERBOSE ) { \
1098 DRM_INFO( " OUT_RING( 0x%08x ) at 0x%x\n", \
1099 (unsigned int)(x), write ); \
1100 } \
1101 ring[write++] = (x); \
1102 write &= mask; \
1103} while (0)
1104
1105#define OUT_RING_REG( reg, val ) do { \
1106 OUT_RING( CP_PACKET0( reg, 0 ) ); \
1107 OUT_RING( val ); \
1108} while (0)
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110#define OUT_RING_TABLE( tab, sz ) do { \
1111 int _size = (sz); \
1112 int *_tab = (int *)(tab); \
1113 \
1114 if (write + _size > mask) { \
1115 int _i = (mask+1) - write; \
1116 _size -= _i; \
1117 while (_i > 0 ) { \
1118 *(int *)(ring + write) = *_tab++; \
1119 write++; \
1120 _i--; \
1121 } \
1122 write = 0; \
1123 _tab += _i; \
1124 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 while (_size > 0) { \
1126 *(ring + write) = *_tab++; \
1127 write++; \
1128 _size--; \
1129 } \
1130 write &= mask; \
1131} while (0)
1132
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001133#endif /* __RADEON_DRV_H__ */