radeon_drv.h 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. /* 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. #ifndef __RADEON_DRV_H__
  31. #define __RADEON_DRV_H__
  32. /* General customization:
  33. */
  34. #define DRIVER_AUTHOR "Gareth Hughes, Keith Whitwell, others."
  35. #define DRIVER_NAME "radeon"
  36. #define DRIVER_DESC "ATI Radeon"
  37. #define DRIVER_DATE "20080528"
  38. /* Interface history:
  39. *
  40. * 1.1 - ??
  41. * 1.2 - Add vertex2 ioctl (keith)
  42. * - Add stencil capability to clear ioctl (gareth, keith)
  43. * - Increase MAX_TEXTURE_LEVELS (brian)
  44. * 1.3 - Add cmdbuf ioctl (keith)
  45. * - Add support for new radeon packets (keith)
  46. * - Add getparam ioctl (keith)
  47. * - Add flip-buffers ioctl, deprecate fullscreen foo (keith).
  48. * 1.4 - Add scratch registers to get_param ioctl.
  49. * 1.5 - Add r200 packets to cmdbuf ioctl
  50. * - Add r200 function to init ioctl
  51. * - Add 'scalar2' instruction to cmdbuf
  52. * 1.6 - Add static GART memory manager
  53. * Add irq handler (won't be turned on unless X server knows to)
  54. * Add irq ioctls and irq_active getparam.
  55. * Add wait command for cmdbuf ioctl
  56. * Add GART offset query for getparam
  57. * 1.7 - Add support for cube map registers: R200_PP_CUBIC_FACES_[0..5]
  58. * and R200_PP_CUBIC_OFFSET_F1_[0..5].
  59. * Added packets R200_EMIT_PP_CUBIC_FACES_[0..5] and
  60. * R200_EMIT_PP_CUBIC_OFFSETS_[0..5]. (brian)
  61. * 1.8 - Remove need to call cleanup ioctls on last client exit (keith)
  62. * Add 'GET' queries for starting additional clients on different VT's.
  63. * 1.9 - Add DRM_IOCTL_RADEON_CP_RESUME ioctl.
  64. * Add texture rectangle support for r100.
  65. * 1.10- Add SETPARAM ioctl; first parameter to set is FB_LOCATION, which
  66. * clients use to tell the DRM where they think the framebuffer is
  67. * located in the card's address space
  68. * 1.11- Add packet R200_EMIT_RB3D_BLENDCOLOR to support GL_EXT_blend_color
  69. * and GL_EXT_blend_[func|equation]_separate on r200
  70. * 1.12- Add R300 CP microcode support - this just loads the CP on r300
  71. * (No 3D support yet - just microcode loading).
  72. * 1.13- Add packet R200_EMIT_TCL_POINT_SPRITE_CNTL for ARB_point_parameters
  73. * - Add hyperz support, add hyperz flags to clear ioctl.
  74. * 1.14- Add support for color tiling
  75. * - Add R100/R200 surface allocation/free support
  76. * 1.15- Add support for texture micro tiling
  77. * - Add support for r100 cube maps
  78. * 1.16- Add R200_EMIT_PP_TRI_PERF_CNTL packet to support brilinear
  79. * texture filtering on r200
  80. * 1.17- Add initial support for R300 (3D).
  81. * 1.18- Add support for GL_ATI_fragment_shader, new packets
  82. * R200_EMIT_PP_AFS_0/1, R200_EMIT_PP_TXCTLALL_0-5 (replaces
  83. * R200_EMIT_PP_TXFILTER_0-5, 2 more regs) and R200_EMIT_ATF_TFACTOR
  84. * (replaces R200_EMIT_TFACTOR_0 (8 consts instead of 6)
  85. * 1.19- Add support for gart table in FB memory and PCIE r300
  86. * 1.20- Add support for r300 texrect
  87. * 1.21- Add support for card type getparam
  88. * 1.22- Add support for texture cache flushes (R300_TX_CNTL)
  89. * 1.23- Add new radeon memory map work from benh
  90. * 1.24- Add general-purpose packet for manipulating scratch registers (r300)
  91. * 1.25- Add support for r200 vertex programs (R200_EMIT_VAP_PVS_CNTL,
  92. * new packet type)
  93. * 1.26- Add support for variable size PCI(E) gart aperture
  94. * 1.27- Add support for IGP GART
  95. * 1.28- Add support for VBL on CRTC2
  96. * 1.29- R500 3D cmd buffer support
  97. */
  98. #define DRIVER_MAJOR 1
  99. #define DRIVER_MINOR 29
  100. #define DRIVER_PATCHLEVEL 0
  101. /*
  102. * Radeon chip families
  103. */
  104. enum radeon_family {
  105. CHIP_R100,
  106. CHIP_RV100,
  107. CHIP_RS100,
  108. CHIP_RV200,
  109. CHIP_RS200,
  110. CHIP_R200,
  111. CHIP_RV250,
  112. CHIP_RS300,
  113. CHIP_RV280,
  114. CHIP_R300,
  115. CHIP_R350,
  116. CHIP_RV350,
  117. CHIP_RV380,
  118. CHIP_R420,
  119. CHIP_RV410,
  120. CHIP_RS480,
  121. CHIP_RS690,
  122. CHIP_RV515,
  123. CHIP_R520,
  124. CHIP_RV530,
  125. CHIP_RV560,
  126. CHIP_RV570,
  127. CHIP_R580,
  128. CHIP_LAST,
  129. };
  130. enum radeon_cp_microcode_version {
  131. UCODE_R100,
  132. UCODE_R200,
  133. UCODE_R300,
  134. };
  135. /*
  136. * Chip flags
  137. */
  138. enum radeon_chip_flags {
  139. RADEON_FAMILY_MASK = 0x0000ffffUL,
  140. RADEON_FLAGS_MASK = 0xffff0000UL,
  141. RADEON_IS_MOBILITY = 0x00010000UL,
  142. RADEON_IS_IGP = 0x00020000UL,
  143. RADEON_SINGLE_CRTC = 0x00040000UL,
  144. RADEON_IS_AGP = 0x00080000UL,
  145. RADEON_HAS_HIERZ = 0x00100000UL,
  146. RADEON_IS_PCIE = 0x00200000UL,
  147. RADEON_NEW_MEMMAP = 0x00400000UL,
  148. RADEON_IS_PCI = 0x00800000UL,
  149. RADEON_IS_IGPGART = 0x01000000UL,
  150. };
  151. #define GET_RING_HEAD(dev_priv) (dev_priv->writeback_works ? \
  152. DRM_READ32( (dev_priv)->ring_rptr, 0 ) : RADEON_READ(RADEON_CP_RB_RPTR))
  153. #define SET_RING_HEAD(dev_priv,val) DRM_WRITE32( (dev_priv)->ring_rptr, 0, (val) )
  154. typedef struct drm_radeon_freelist {
  155. unsigned int age;
  156. struct drm_buf *buf;
  157. struct drm_radeon_freelist *next;
  158. struct drm_radeon_freelist *prev;
  159. } drm_radeon_freelist_t;
  160. typedef struct drm_radeon_ring_buffer {
  161. u32 *start;
  162. u32 *end;
  163. int size;
  164. int size_l2qw;
  165. int rptr_update; /* Double Words */
  166. int rptr_update_l2qw; /* log2 Quad Words */
  167. int fetch_size; /* Double Words */
  168. int fetch_size_l2ow; /* log2 Oct Words */
  169. u32 tail;
  170. u32 tail_mask;
  171. int space;
  172. int high_mark;
  173. } drm_radeon_ring_buffer_t;
  174. typedef struct drm_radeon_depth_clear_t {
  175. u32 rb3d_cntl;
  176. u32 rb3d_zstencilcntl;
  177. u32 se_cntl;
  178. } drm_radeon_depth_clear_t;
  179. struct drm_radeon_driver_file_fields {
  180. int64_t radeon_fb_delta;
  181. };
  182. struct mem_block {
  183. struct mem_block *next;
  184. struct mem_block *prev;
  185. int start;
  186. int size;
  187. struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
  188. };
  189. struct radeon_surface {
  190. int refcount;
  191. u32 lower;
  192. u32 upper;
  193. u32 flags;
  194. };
  195. struct radeon_virt_surface {
  196. int surface_index;
  197. u32 lower;
  198. u32 upper;
  199. u32 flags;
  200. struct drm_file *file_priv;
  201. };
  202. #define RADEON_FLUSH_EMITED (1 < 0)
  203. #define RADEON_PURGE_EMITED (1 < 1)
  204. typedef struct drm_radeon_private {
  205. drm_radeon_ring_buffer_t ring;
  206. drm_radeon_sarea_t *sarea_priv;
  207. u32 fb_location;
  208. u32 fb_size;
  209. int new_memmap;
  210. int gart_size;
  211. u32 gart_vm_start;
  212. unsigned long gart_buffers_offset;
  213. int cp_mode;
  214. int cp_running;
  215. drm_radeon_freelist_t *head;
  216. drm_radeon_freelist_t *tail;
  217. int last_buf;
  218. volatile u32 *scratch;
  219. int writeback_works;
  220. int usec_timeout;
  221. int microcode_version;
  222. struct {
  223. u32 boxes;
  224. int freelist_timeouts;
  225. int freelist_loops;
  226. int requested_bufs;
  227. int last_frame_reads;
  228. int last_clear_reads;
  229. int clears;
  230. int texture_uploads;
  231. } stats;
  232. int do_boxes;
  233. int page_flipping;
  234. u32 color_fmt;
  235. unsigned int front_offset;
  236. unsigned int front_pitch;
  237. unsigned int back_offset;
  238. unsigned int back_pitch;
  239. u32 depth_fmt;
  240. unsigned int depth_offset;
  241. unsigned int depth_pitch;
  242. u32 front_pitch_offset;
  243. u32 back_pitch_offset;
  244. u32 depth_pitch_offset;
  245. drm_radeon_depth_clear_t depth_clear;
  246. unsigned long ring_offset;
  247. unsigned long ring_rptr_offset;
  248. unsigned long buffers_offset;
  249. unsigned long gart_textures_offset;
  250. drm_local_map_t *sarea;
  251. drm_local_map_t *mmio;
  252. drm_local_map_t *cp_ring;
  253. drm_local_map_t *ring_rptr;
  254. drm_local_map_t *gart_textures;
  255. struct mem_block *gart_heap;
  256. struct mem_block *fb_heap;
  257. /* SW interrupt */
  258. wait_queue_head_t swi_queue;
  259. atomic_t swi_emitted;
  260. int vblank_crtc;
  261. uint32_t irq_enable_reg;
  262. int irq_enabled;
  263. uint32_t r500_disp_irq_reg;
  264. struct radeon_surface surfaces[RADEON_MAX_SURFACES];
  265. struct radeon_virt_surface virt_surfaces[2 * RADEON_MAX_SURFACES];
  266. unsigned long pcigart_offset;
  267. unsigned int pcigart_offset_set;
  268. struct drm_ati_pcigart_info gart_info;
  269. u32 scratch_ages[5];
  270. /* starting from here on, data is preserved accross an open */
  271. uint32_t flags; /* see radeon_chip_flags */
  272. unsigned long fb_aper_offset;
  273. int num_gb_pipes;
  274. int track_flush;
  275. } drm_radeon_private_t;
  276. typedef struct drm_radeon_buf_priv {
  277. u32 age;
  278. } drm_radeon_buf_priv_t;
  279. typedef struct drm_radeon_kcmd_buffer {
  280. int bufsz;
  281. char *buf;
  282. int nbox;
  283. struct drm_clip_rect __user *boxes;
  284. } drm_radeon_kcmd_buffer_t;
  285. extern int radeon_no_wb;
  286. extern struct drm_ioctl_desc radeon_ioctls[];
  287. extern int radeon_max_ioctl;
  288. /* Check whether the given hardware address is inside the framebuffer or the
  289. * GART area.
  290. */
  291. static __inline__ int radeon_check_offset(drm_radeon_private_t *dev_priv,
  292. u64 off)
  293. {
  294. u32 fb_start = dev_priv->fb_location;
  295. u32 fb_end = fb_start + dev_priv->fb_size - 1;
  296. u32 gart_start = dev_priv->gart_vm_start;
  297. u32 gart_end = gart_start + dev_priv->gart_size - 1;
  298. return ((off >= fb_start && off <= fb_end) ||
  299. (off >= gart_start && off <= gart_end));
  300. }
  301. /* radeon_cp.c */
  302. extern int radeon_cp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
  303. extern int radeon_cp_start(struct drm_device *dev, void *data, struct drm_file *file_priv);
  304. extern int radeon_cp_stop(struct drm_device *dev, void *data, struct drm_file *file_priv);
  305. extern int radeon_cp_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
  306. extern int radeon_cp_idle(struct drm_device *dev, void *data, struct drm_file *file_priv);
  307. extern int radeon_cp_resume(struct drm_device *dev, void *data, struct drm_file *file_priv);
  308. extern int radeon_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
  309. extern int radeon_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv);
  310. extern int radeon_cp_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
  311. extern u32 radeon_read_fb_location(drm_radeon_private_t *dev_priv);
  312. extern void radeon_freelist_reset(struct drm_device * dev);
  313. extern struct drm_buf *radeon_freelist_get(struct drm_device * dev);
  314. extern int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n);
  315. extern int radeon_do_cp_idle(drm_radeon_private_t * dev_priv);
  316. extern int radeon_driver_preinit(struct drm_device *dev, unsigned long flags);
  317. extern int radeon_presetup(struct drm_device *dev);
  318. extern int radeon_driver_postcleanup(struct drm_device *dev);
  319. extern int radeon_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
  320. extern int radeon_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
  321. extern int radeon_mem_init_heap(struct drm_device *dev, void *data, struct drm_file *file_priv);
  322. extern void radeon_mem_takedown(struct mem_block **heap);
  323. extern void radeon_mem_release(struct drm_file *file_priv,
  324. struct mem_block *heap);
  325. /* radeon_irq.c */
  326. extern int radeon_irq_emit(struct drm_device *dev, void *data, struct drm_file *file_priv);
  327. extern int radeon_irq_wait(struct drm_device *dev, void *data, struct drm_file *file_priv);
  328. extern void radeon_do_release(struct drm_device * dev);
  329. extern int radeon_driver_vblank_wait(struct drm_device * dev,
  330. unsigned int *sequence);
  331. extern int radeon_driver_vblank_wait2(struct drm_device * dev,
  332. unsigned int *sequence);
  333. extern irqreturn_t radeon_driver_irq_handler(DRM_IRQ_ARGS);
  334. extern void radeon_driver_irq_preinstall(struct drm_device * dev);
  335. extern void radeon_driver_irq_postinstall(struct drm_device * dev);
  336. extern void radeon_driver_irq_uninstall(struct drm_device * dev);
  337. extern void radeon_enable_interrupt(struct drm_device *dev);
  338. extern int radeon_vblank_crtc_get(struct drm_device *dev);
  339. extern int radeon_vblank_crtc_set(struct drm_device *dev, int64_t value);
  340. extern int radeon_driver_load(struct drm_device *dev, unsigned long flags);
  341. extern int radeon_driver_unload(struct drm_device *dev);
  342. extern int radeon_driver_firstopen(struct drm_device *dev);
  343. extern void radeon_driver_preclose(struct drm_device * dev, struct drm_file *file_priv);
  344. extern void radeon_driver_postclose(struct drm_device * dev, struct drm_file * filp);
  345. extern void radeon_driver_lastclose(struct drm_device * dev);
  346. extern int radeon_driver_open(struct drm_device * dev, struct drm_file * filp_priv);
  347. extern long radeon_compat_ioctl(struct file *filp, unsigned int cmd,
  348. unsigned long arg);
  349. /* r300_cmdbuf.c */
  350. extern void r300_init_reg_flags(struct drm_device *dev);
  351. extern int r300_do_cp_cmdbuf(struct drm_device * dev,
  352. struct drm_file *file_priv,
  353. drm_radeon_kcmd_buffer_t * cmdbuf);
  354. /* Flags for stats.boxes
  355. */
  356. #define RADEON_BOX_DMA_IDLE 0x1
  357. #define RADEON_BOX_RING_FULL 0x2
  358. #define RADEON_BOX_FLIP 0x4
  359. #define RADEON_BOX_WAIT_IDLE 0x8
  360. #define RADEON_BOX_TEXTURE_LOAD 0x10
  361. /* Register definitions, register access macros and drmAddMap constants
  362. * for Radeon kernel driver.
  363. */
  364. #define RADEON_AGP_COMMAND 0x0f60
  365. #define RADEON_AGP_COMMAND_PCI_CONFIG 0x0060 /* offset in PCI config */
  366. # define RADEON_AGP_ENABLE (1<<8)
  367. #define RADEON_AUX_SCISSOR_CNTL 0x26f0
  368. # define RADEON_EXCLUSIVE_SCISSOR_0 (1 << 24)
  369. # define RADEON_EXCLUSIVE_SCISSOR_1 (1 << 25)
  370. # define RADEON_EXCLUSIVE_SCISSOR_2 (1 << 26)
  371. # define RADEON_SCISSOR_0_ENABLE (1 << 28)
  372. # define RADEON_SCISSOR_1_ENABLE (1 << 29)
  373. # define RADEON_SCISSOR_2_ENABLE (1 << 30)
  374. #define RADEON_BUS_CNTL 0x0030
  375. # define RADEON_BUS_MASTER_DIS (1 << 6)
  376. #define RADEON_CLOCK_CNTL_DATA 0x000c
  377. # define RADEON_PLL_WR_EN (1 << 7)
  378. #define RADEON_CLOCK_CNTL_INDEX 0x0008
  379. #define RADEON_CONFIG_APER_SIZE 0x0108
  380. #define RADEON_CONFIG_MEMSIZE 0x00f8
  381. #define RADEON_CRTC_OFFSET 0x0224
  382. #define RADEON_CRTC_OFFSET_CNTL 0x0228
  383. # define RADEON_CRTC_TILE_EN (1 << 15)
  384. # define RADEON_CRTC_OFFSET_FLIP_CNTL (1 << 16)
  385. #define RADEON_CRTC2_OFFSET 0x0324
  386. #define RADEON_CRTC2_OFFSET_CNTL 0x0328
  387. #define RADEON_PCIE_INDEX 0x0030
  388. #define RADEON_PCIE_DATA 0x0034
  389. #define RADEON_PCIE_TX_GART_CNTL 0x10
  390. # define RADEON_PCIE_TX_GART_EN (1 << 0)
  391. # define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_PASS_THRU (0 << 1)
  392. # define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_CLAMP_LO (1 << 1)
  393. # define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD (3 << 1)
  394. # define RADEON_PCIE_TX_GART_MODE_32_128_CACHE (0 << 3)
  395. # define RADEON_PCIE_TX_GART_MODE_8_4_128_CACHE (1 << 3)
  396. # define RADEON_PCIE_TX_GART_CHK_RW_VALID_EN (1 << 5)
  397. # define RADEON_PCIE_TX_GART_INVALIDATE_TLB (1 << 8)
  398. #define RADEON_PCIE_TX_DISCARD_RD_ADDR_LO 0x11
  399. #define RADEON_PCIE_TX_DISCARD_RD_ADDR_HI 0x12
  400. #define RADEON_PCIE_TX_GART_BASE 0x13
  401. #define RADEON_PCIE_TX_GART_START_LO 0x14
  402. #define RADEON_PCIE_TX_GART_START_HI 0x15
  403. #define RADEON_PCIE_TX_GART_END_LO 0x16
  404. #define RADEON_PCIE_TX_GART_END_HI 0x17
  405. #define RS480_NB_MC_INDEX 0x168
  406. # define RS480_NB_MC_IND_WR_EN (1 << 8)
  407. #define RS480_NB_MC_DATA 0x16c
  408. #define RS690_MC_INDEX 0x78
  409. # define RS690_MC_INDEX_MASK 0x1ff
  410. # define RS690_MC_INDEX_WR_EN (1 << 9)
  411. # define RS690_MC_INDEX_WR_ACK 0x7f
  412. #define RS690_MC_DATA 0x7c
  413. /* MC indirect registers */
  414. #define RS480_MC_MISC_CNTL 0x18
  415. # define RS480_DISABLE_GTW (1 << 1)
  416. /* switch between MCIND GART and MM GART registers. 0 = mmgart, 1 = mcind gart */
  417. # define RS480_GART_INDEX_REG_EN (1 << 12)
  418. # define RS690_BLOCK_GFX_D3_EN (1 << 14)
  419. #define RS480_K8_FB_LOCATION 0x1e
  420. #define RS480_GART_FEATURE_ID 0x2b
  421. # define RS480_HANG_EN (1 << 11)
  422. # define RS480_TLB_ENABLE (1 << 18)
  423. # define RS480_P2P_ENABLE (1 << 19)
  424. # define RS480_GTW_LAC_EN (1 << 25)
  425. # define RS480_2LEVEL_GART (0 << 30)
  426. # define RS480_1LEVEL_GART (1 << 30)
  427. # define RS480_PDC_EN (1 << 31)
  428. #define RS480_GART_BASE 0x2c
  429. #define RS480_GART_CACHE_CNTRL 0x2e
  430. # define RS480_GART_CACHE_INVALIDATE (1 << 0) /* wait for it to clear */
  431. #define RS480_AGP_ADDRESS_SPACE_SIZE 0x38
  432. # define RS480_GART_EN (1 << 0)
  433. # define RS480_VA_SIZE_32MB (0 << 1)
  434. # define RS480_VA_SIZE_64MB (1 << 1)
  435. # define RS480_VA_SIZE_128MB (2 << 1)
  436. # define RS480_VA_SIZE_256MB (3 << 1)
  437. # define RS480_VA_SIZE_512MB (4 << 1)
  438. # define RS480_VA_SIZE_1GB (5 << 1)
  439. # define RS480_VA_SIZE_2GB (6 << 1)
  440. #define RS480_AGP_MODE_CNTL 0x39
  441. # define RS480_POST_GART_Q_SIZE (1 << 18)
  442. # define RS480_NONGART_SNOOP (1 << 19)
  443. # define RS480_AGP_RD_BUF_SIZE (1 << 20)
  444. # define RS480_REQ_TYPE_SNOOP_SHIFT 22
  445. # define RS480_REQ_TYPE_SNOOP_MASK 0x3
  446. # define RS480_REQ_TYPE_SNOOP_DIS (1 << 24)
  447. #define RS480_MC_MISC_UMA_CNTL 0x5f
  448. #define RS480_MC_MCLK_CNTL 0x7a
  449. #define RS480_MC_UMA_DUALCH_CNTL 0x86
  450. #define RS690_MC_FB_LOCATION 0x100
  451. #define RS690_MC_AGP_LOCATION 0x101
  452. #define RS690_MC_AGP_BASE 0x102
  453. #define RS690_MC_AGP_BASE_2 0x103
  454. #define R520_MC_IND_INDEX 0x70
  455. #define R520_MC_IND_WR_EN (1 << 24)
  456. #define R520_MC_IND_DATA 0x74
  457. #define RV515_MC_FB_LOCATION 0x01
  458. #define RV515_MC_AGP_LOCATION 0x02
  459. #define RV515_MC_AGP_BASE 0x03
  460. #define RV515_MC_AGP_BASE_2 0x04
  461. #define R520_MC_FB_LOCATION 0x04
  462. #define R520_MC_AGP_LOCATION 0x05
  463. #define R520_MC_AGP_BASE 0x06
  464. #define R520_MC_AGP_BASE_2 0x07
  465. #define RADEON_MPP_TB_CONFIG 0x01c0
  466. #define RADEON_MEM_CNTL 0x0140
  467. #define RADEON_MEM_SDRAM_MODE_REG 0x0158
  468. #define RADEON_AGP_BASE_2 0x015c /* r200+ only */
  469. #define RS480_AGP_BASE_2 0x0164
  470. #define RADEON_AGP_BASE 0x0170
  471. /* pipe config regs */
  472. #define R400_GB_PIPE_SELECT 0x402c
  473. #define R500_DYN_SCLK_PWMEM_PIPE 0x000d /* PLL */
  474. #define R500_SU_REG_DEST 0x42c8
  475. #define R300_GB_TILE_CONFIG 0x4018
  476. # define R300_ENABLE_TILING (1 << 0)
  477. # define R300_PIPE_COUNT_RV350 (0 << 1)
  478. # define R300_PIPE_COUNT_R300 (3 << 1)
  479. # define R300_PIPE_COUNT_R420_3P (6 << 1)
  480. # define R300_PIPE_COUNT_R420 (7 << 1)
  481. # define R300_TILE_SIZE_8 (0 << 4)
  482. # define R300_TILE_SIZE_16 (1 << 4)
  483. # define R300_TILE_SIZE_32 (2 << 4)
  484. # define R300_SUBPIXEL_1_12 (0 << 16)
  485. # define R300_SUBPIXEL_1_16 (1 << 16)
  486. #define R300_DST_PIPE_CONFIG 0x170c
  487. # define R300_PIPE_AUTO_CONFIG (1 << 31)
  488. #define R300_RB2D_DSTCACHE_MODE 0x3428
  489. # define R300_DC_AUTOFLUSH_ENABLE (1 << 8)
  490. # define R300_DC_DC_DISABLE_IGNORE_PE (1 << 17)
  491. #define RADEON_RB3D_COLOROFFSET 0x1c40
  492. #define RADEON_RB3D_COLORPITCH 0x1c48
  493. #define RADEON_SRC_X_Y 0x1590
  494. #define RADEON_DP_GUI_MASTER_CNTL 0x146c
  495. # define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
  496. # define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
  497. # define RADEON_GMC_BRUSH_SOLID_COLOR (13 << 4)
  498. # define RADEON_GMC_BRUSH_NONE (15 << 4)
  499. # define RADEON_GMC_DST_16BPP (4 << 8)
  500. # define RADEON_GMC_DST_24BPP (5 << 8)
  501. # define RADEON_GMC_DST_32BPP (6 << 8)
  502. # define RADEON_GMC_DST_DATATYPE_SHIFT 8
  503. # define RADEON_GMC_SRC_DATATYPE_COLOR (3 << 12)
  504. # define RADEON_DP_SRC_SOURCE_MEMORY (2 << 24)
  505. # define RADEON_DP_SRC_SOURCE_HOST_DATA (3 << 24)
  506. # define RADEON_GMC_CLR_CMP_CNTL_DIS (1 << 28)
  507. # define RADEON_GMC_WR_MSK_DIS (1 << 30)
  508. # define RADEON_ROP3_S 0x00cc0000
  509. # define RADEON_ROP3_P 0x00f00000
  510. #define RADEON_DP_WRITE_MASK 0x16cc
  511. #define RADEON_SRC_PITCH_OFFSET 0x1428
  512. #define RADEON_DST_PITCH_OFFSET 0x142c
  513. #define RADEON_DST_PITCH_OFFSET_C 0x1c80
  514. # define RADEON_DST_TILE_LINEAR (0 << 30)
  515. # define RADEON_DST_TILE_MACRO (1 << 30)
  516. # define RADEON_DST_TILE_MICRO (2 << 30)
  517. # define RADEON_DST_TILE_BOTH (3 << 30)
  518. #define RADEON_SCRATCH_REG0 0x15e0
  519. #define RADEON_SCRATCH_REG1 0x15e4
  520. #define RADEON_SCRATCH_REG2 0x15e8
  521. #define RADEON_SCRATCH_REG3 0x15ec
  522. #define RADEON_SCRATCH_REG4 0x15f0
  523. #define RADEON_SCRATCH_REG5 0x15f4
  524. #define RADEON_SCRATCH_UMSK 0x0770
  525. #define RADEON_SCRATCH_ADDR 0x0774
  526. #define RADEON_SCRATCHOFF( x ) (RADEON_SCRATCH_REG_OFFSET + 4*(x))
  527. #define GET_SCRATCH( x ) (dev_priv->writeback_works \
  528. ? DRM_READ32( dev_priv->ring_rptr, RADEON_SCRATCHOFF(x) ) \
  529. : RADEON_READ( RADEON_SCRATCH_REG0 + 4*(x) ) )
  530. #define RADEON_GEN_INT_CNTL 0x0040
  531. # define RADEON_CRTC_VBLANK_MASK (1 << 0)
  532. # define RADEON_CRTC2_VBLANK_MASK (1 << 9)
  533. # define RADEON_GUI_IDLE_INT_ENABLE (1 << 19)
  534. # define RADEON_SW_INT_ENABLE (1 << 25)
  535. #define RADEON_GEN_INT_STATUS 0x0044
  536. # define RADEON_CRTC_VBLANK_STAT (1 << 0)
  537. # define RADEON_CRTC_VBLANK_STAT_ACK (1 << 0)
  538. # define RADEON_CRTC2_VBLANK_STAT (1 << 9)
  539. # define RADEON_CRTC2_VBLANK_STAT_ACK (1 << 9)
  540. # define RADEON_GUI_IDLE_INT_TEST_ACK (1 << 19)
  541. # define RADEON_SW_INT_TEST (1 << 25)
  542. # define RADEON_SW_INT_TEST_ACK (1 << 25)
  543. # define RADEON_SW_INT_FIRE (1 << 26)
  544. #define RADEON_HOST_PATH_CNTL 0x0130
  545. # define RADEON_HDP_SOFT_RESET (1 << 26)
  546. # define RADEON_HDP_WC_TIMEOUT_MASK (7 << 28)
  547. # define RADEON_HDP_WC_TIMEOUT_28BCLK (7 << 28)
  548. #define RADEON_ISYNC_CNTL 0x1724
  549. # define RADEON_ISYNC_ANY2D_IDLE3D (1 << 0)
  550. # define RADEON_ISYNC_ANY3D_IDLE2D (1 << 1)
  551. # define RADEON_ISYNC_TRIG2D_IDLE3D (1 << 2)
  552. # define RADEON_ISYNC_TRIG3D_IDLE2D (1 << 3)
  553. # define RADEON_ISYNC_WAIT_IDLEGUI (1 << 4)
  554. # define RADEON_ISYNC_CPSCRATCH_IDLEGUI (1 << 5)
  555. #define RADEON_RBBM_GUICNTL 0x172c
  556. # define RADEON_HOST_DATA_SWAP_NONE (0 << 0)
  557. # define RADEON_HOST_DATA_SWAP_16BIT (1 << 0)
  558. # define RADEON_HOST_DATA_SWAP_32BIT (2 << 0)
  559. # define RADEON_HOST_DATA_SWAP_HDW (3 << 0)
  560. #define RADEON_MC_AGP_LOCATION 0x014c
  561. #define RADEON_MC_FB_LOCATION 0x0148
  562. #define RADEON_MCLK_CNTL 0x0012
  563. # define RADEON_FORCEON_MCLKA (1 << 16)
  564. # define RADEON_FORCEON_MCLKB (1 << 17)
  565. # define RADEON_FORCEON_YCLKA (1 << 18)
  566. # define RADEON_FORCEON_YCLKB (1 << 19)
  567. # define RADEON_FORCEON_MC (1 << 20)
  568. # define RADEON_FORCEON_AIC (1 << 21)
  569. #define RADEON_PP_BORDER_COLOR_0 0x1d40
  570. #define RADEON_PP_BORDER_COLOR_1 0x1d44
  571. #define RADEON_PP_BORDER_COLOR_2 0x1d48
  572. #define RADEON_PP_CNTL 0x1c38
  573. # define RADEON_SCISSOR_ENABLE (1 << 1)
  574. #define RADEON_PP_LUM_MATRIX 0x1d00
  575. #define RADEON_PP_MISC 0x1c14
  576. #define RADEON_PP_ROT_MATRIX_0 0x1d58
  577. #define RADEON_PP_TXFILTER_0 0x1c54
  578. #define RADEON_PP_TXOFFSET_0 0x1c5c
  579. #define RADEON_PP_TXFILTER_1 0x1c6c
  580. #define RADEON_PP_TXFILTER_2 0x1c84
  581. #define R300_RB2D_DSTCACHE_CTLSTAT 0x342c /* use R300_DSTCACHE_CTLSTAT */
  582. #define R300_DSTCACHE_CTLSTAT 0x1714
  583. # define R300_RB2D_DC_FLUSH (3 << 0)
  584. # define R300_RB2D_DC_FREE (3 << 2)
  585. # define R300_RB2D_DC_FLUSH_ALL 0xf
  586. # define R300_RB2D_DC_BUSY (1 << 31)
  587. #define RADEON_RB3D_CNTL 0x1c3c
  588. # define RADEON_ALPHA_BLEND_ENABLE (1 << 0)
  589. # define RADEON_PLANE_MASK_ENABLE (1 << 1)
  590. # define RADEON_DITHER_ENABLE (1 << 2)
  591. # define RADEON_ROUND_ENABLE (1 << 3)
  592. # define RADEON_SCALE_DITHER_ENABLE (1 << 4)
  593. # define RADEON_DITHER_INIT (1 << 5)
  594. # define RADEON_ROP_ENABLE (1 << 6)
  595. # define RADEON_STENCIL_ENABLE (1 << 7)
  596. # define RADEON_Z_ENABLE (1 << 8)
  597. # define RADEON_ZBLOCK16 (1 << 15)
  598. #define RADEON_RB3D_DEPTHOFFSET 0x1c24
  599. #define RADEON_RB3D_DEPTHCLEARVALUE 0x3230
  600. #define RADEON_RB3D_DEPTHPITCH 0x1c28
  601. #define RADEON_RB3D_PLANEMASK 0x1d84
  602. #define RADEON_RB3D_STENCILREFMASK 0x1d7c
  603. #define RADEON_RB3D_ZCACHE_MODE 0x3250
  604. #define RADEON_RB3D_ZCACHE_CTLSTAT 0x3254
  605. # define RADEON_RB3D_ZC_FLUSH (1 << 0)
  606. # define RADEON_RB3D_ZC_FREE (1 << 2)
  607. # define RADEON_RB3D_ZC_FLUSH_ALL 0x5
  608. # define RADEON_RB3D_ZC_BUSY (1 << 31)
  609. #define R300_ZB_ZCACHE_CTLSTAT 0x4f18
  610. # define R300_ZC_FLUSH (1 << 0)
  611. # define R300_ZC_FREE (1 << 1)
  612. # define R300_ZC_BUSY (1 << 31)
  613. #define RADEON_RB3D_DSTCACHE_CTLSTAT 0x325c
  614. # define RADEON_RB3D_DC_FLUSH (3 << 0)
  615. # define RADEON_RB3D_DC_FREE (3 << 2)
  616. # define RADEON_RB3D_DC_FLUSH_ALL 0xf
  617. # define RADEON_RB3D_DC_BUSY (1 << 31)
  618. #define R300_RB3D_DSTCACHE_CTLSTAT 0x4e4c
  619. # define R300_RB3D_DC_FLUSH (2 << 0)
  620. # define R300_RB3D_DC_FREE (2 << 2)
  621. # define R300_RB3D_DC_FINISH (1 << 4)
  622. #define RADEON_RB3D_ZSTENCILCNTL 0x1c2c
  623. # define RADEON_Z_TEST_MASK (7 << 4)
  624. # define RADEON_Z_TEST_ALWAYS (7 << 4)
  625. # define RADEON_Z_HIERARCHY_ENABLE (1 << 8)
  626. # define RADEON_STENCIL_TEST_ALWAYS (7 << 12)
  627. # define RADEON_STENCIL_S_FAIL_REPLACE (2 << 16)
  628. # define RADEON_STENCIL_ZPASS_REPLACE (2 << 20)
  629. # define RADEON_STENCIL_ZFAIL_REPLACE (2 << 24)
  630. # define RADEON_Z_COMPRESSION_ENABLE (1 << 28)
  631. # define RADEON_FORCE_Z_DIRTY (1 << 29)
  632. # define RADEON_Z_WRITE_ENABLE (1 << 30)
  633. # define RADEON_Z_DECOMPRESSION_ENABLE (1 << 31)
  634. #define RADEON_RBBM_SOFT_RESET 0x00f0
  635. # define RADEON_SOFT_RESET_CP (1 << 0)
  636. # define RADEON_SOFT_RESET_HI (1 << 1)
  637. # define RADEON_SOFT_RESET_SE (1 << 2)
  638. # define RADEON_SOFT_RESET_RE (1 << 3)
  639. # define RADEON_SOFT_RESET_PP (1 << 4)
  640. # define RADEON_SOFT_RESET_E2 (1 << 5)
  641. # define RADEON_SOFT_RESET_RB (1 << 6)
  642. # define RADEON_SOFT_RESET_HDP (1 << 7)
  643. /*
  644. * 6:0 Available slots in the FIFO
  645. * 8 Host Interface active
  646. * 9 CP request active
  647. * 10 FIFO request active
  648. * 11 Host Interface retry active
  649. * 12 CP retry active
  650. * 13 FIFO retry active
  651. * 14 FIFO pipeline busy
  652. * 15 Event engine busy
  653. * 16 CP command stream busy
  654. * 17 2D engine busy
  655. * 18 2D portion of render backend busy
  656. * 20 3D setup engine busy
  657. * 26 GA engine busy
  658. * 27 CBA 2D engine busy
  659. * 31 2D engine busy or 3D engine busy or FIFO not empty or CP busy or
  660. * command stream queue not empty or Ring Buffer not empty
  661. */
  662. #define RADEON_RBBM_STATUS 0x0e40
  663. /* Same as the previous RADEON_RBBM_STATUS; this is a mirror of that register. */
  664. /* #define RADEON_RBBM_STATUS 0x1740 */
  665. /* bits 6:0 are dword slots available in the cmd fifo */
  666. # define RADEON_RBBM_FIFOCNT_MASK 0x007f
  667. # define RADEON_HIRQ_ON_RBB (1 << 8)
  668. # define RADEON_CPRQ_ON_RBB (1 << 9)
  669. # define RADEON_CFRQ_ON_RBB (1 << 10)
  670. # define RADEON_HIRQ_IN_RTBUF (1 << 11)
  671. # define RADEON_CPRQ_IN_RTBUF (1 << 12)
  672. # define RADEON_CFRQ_IN_RTBUF (1 << 13)
  673. # define RADEON_PIPE_BUSY (1 << 14)
  674. # define RADEON_ENG_EV_BUSY (1 << 15)
  675. # define RADEON_CP_CMDSTRM_BUSY (1 << 16)
  676. # define RADEON_E2_BUSY (1 << 17)
  677. # define RADEON_RB2D_BUSY (1 << 18)
  678. # define RADEON_RB3D_BUSY (1 << 19) /* not used on r300 */
  679. # define RADEON_VAP_BUSY (1 << 20)
  680. # define RADEON_RE_BUSY (1 << 21) /* not used on r300 */
  681. # define RADEON_TAM_BUSY (1 << 22) /* not used on r300 */
  682. # define RADEON_TDM_BUSY (1 << 23) /* not used on r300 */
  683. # define RADEON_PB_BUSY (1 << 24) /* not used on r300 */
  684. # define RADEON_TIM_BUSY (1 << 25) /* not used on r300 */
  685. # define RADEON_GA_BUSY (1 << 26)
  686. # define RADEON_CBA2D_BUSY (1 << 27)
  687. # define RADEON_RBBM_ACTIVE (1 << 31)
  688. #define RADEON_RE_LINE_PATTERN 0x1cd0
  689. #define RADEON_RE_MISC 0x26c4
  690. #define RADEON_RE_TOP_LEFT 0x26c0
  691. #define RADEON_RE_WIDTH_HEIGHT 0x1c44
  692. #define RADEON_RE_STIPPLE_ADDR 0x1cc8
  693. #define RADEON_RE_STIPPLE_DATA 0x1ccc
  694. #define RADEON_SCISSOR_TL_0 0x1cd8
  695. #define RADEON_SCISSOR_BR_0 0x1cdc
  696. #define RADEON_SCISSOR_TL_1 0x1ce0
  697. #define RADEON_SCISSOR_BR_1 0x1ce4
  698. #define RADEON_SCISSOR_TL_2 0x1ce8
  699. #define RADEON_SCISSOR_BR_2 0x1cec
  700. #define RADEON_SE_COORD_FMT 0x1c50
  701. #define RADEON_SE_CNTL 0x1c4c
  702. # define RADEON_FFACE_CULL_CW (0 << 0)
  703. # define RADEON_BFACE_SOLID (3 << 1)
  704. # define RADEON_FFACE_SOLID (3 << 3)
  705. # define RADEON_FLAT_SHADE_VTX_LAST (3 << 6)
  706. # define RADEON_DIFFUSE_SHADE_FLAT (1 << 8)
  707. # define RADEON_DIFFUSE_SHADE_GOURAUD (2 << 8)
  708. # define RADEON_ALPHA_SHADE_FLAT (1 << 10)
  709. # define RADEON_ALPHA_SHADE_GOURAUD (2 << 10)
  710. # define RADEON_SPECULAR_SHADE_FLAT (1 << 12)
  711. # define RADEON_SPECULAR_SHADE_GOURAUD (2 << 12)
  712. # define RADEON_FOG_SHADE_FLAT (1 << 14)
  713. # define RADEON_FOG_SHADE_GOURAUD (2 << 14)
  714. # define RADEON_VPORT_XY_XFORM_ENABLE (1 << 24)
  715. # define RADEON_VPORT_Z_XFORM_ENABLE (1 << 25)
  716. # define RADEON_VTX_PIX_CENTER_OGL (1 << 27)
  717. # define RADEON_ROUND_MODE_TRUNC (0 << 28)
  718. # define RADEON_ROUND_PREC_8TH_PIX (1 << 30)
  719. #define RADEON_SE_CNTL_STATUS 0x2140
  720. #define RADEON_SE_LINE_WIDTH 0x1db8
  721. #define RADEON_SE_VPORT_XSCALE 0x1d98
  722. #define RADEON_SE_ZBIAS_FACTOR 0x1db0
  723. #define RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED 0x2210
  724. #define RADEON_SE_TCL_OUTPUT_VTX_FMT 0x2254
  725. #define RADEON_SE_TCL_VECTOR_INDX_REG 0x2200
  726. # define RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT 16
  727. # define RADEON_VEC_INDX_DWORD_COUNT_SHIFT 28
  728. #define RADEON_SE_TCL_VECTOR_DATA_REG 0x2204
  729. #define RADEON_SE_TCL_SCALAR_INDX_REG 0x2208
  730. # define RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT 16
  731. #define RADEON_SE_TCL_SCALAR_DATA_REG 0x220C
  732. #define RADEON_SURFACE_ACCESS_FLAGS 0x0bf8
  733. #define RADEON_SURFACE_ACCESS_CLR 0x0bfc
  734. #define RADEON_SURFACE_CNTL 0x0b00
  735. # define RADEON_SURF_TRANSLATION_DIS (1 << 8)
  736. # define RADEON_NONSURF_AP0_SWP_MASK (3 << 20)
  737. # define RADEON_NONSURF_AP0_SWP_LITTLE (0 << 20)
  738. # define RADEON_NONSURF_AP0_SWP_BIG16 (1 << 20)
  739. # define RADEON_NONSURF_AP0_SWP_BIG32 (2 << 20)
  740. # define RADEON_NONSURF_AP1_SWP_MASK (3 << 22)
  741. # define RADEON_NONSURF_AP1_SWP_LITTLE (0 << 22)
  742. # define RADEON_NONSURF_AP1_SWP_BIG16 (1 << 22)
  743. # define RADEON_NONSURF_AP1_SWP_BIG32 (2 << 22)
  744. #define RADEON_SURFACE0_INFO 0x0b0c
  745. # define RADEON_SURF_PITCHSEL_MASK (0x1ff << 0)
  746. # define RADEON_SURF_TILE_MODE_MASK (3 << 16)
  747. # define RADEON_SURF_TILE_MODE_MACRO (0 << 16)
  748. # define RADEON_SURF_TILE_MODE_MICRO (1 << 16)
  749. # define RADEON_SURF_TILE_MODE_32BIT_Z (2 << 16)
  750. # define RADEON_SURF_TILE_MODE_16BIT_Z (3 << 16)
  751. #define RADEON_SURFACE0_LOWER_BOUND 0x0b04
  752. #define RADEON_SURFACE0_UPPER_BOUND 0x0b08
  753. # define RADEON_SURF_ADDRESS_FIXED_MASK (0x3ff << 0)
  754. #define RADEON_SURFACE1_INFO 0x0b1c
  755. #define RADEON_SURFACE1_LOWER_BOUND 0x0b14
  756. #define RADEON_SURFACE1_UPPER_BOUND 0x0b18
  757. #define RADEON_SURFACE2_INFO 0x0b2c
  758. #define RADEON_SURFACE2_LOWER_BOUND 0x0b24
  759. #define RADEON_SURFACE2_UPPER_BOUND 0x0b28
  760. #define RADEON_SURFACE3_INFO 0x0b3c
  761. #define RADEON_SURFACE3_LOWER_BOUND 0x0b34
  762. #define RADEON_SURFACE3_UPPER_BOUND 0x0b38
  763. #define RADEON_SURFACE4_INFO 0x0b4c
  764. #define RADEON_SURFACE4_LOWER_BOUND 0x0b44
  765. #define RADEON_SURFACE4_UPPER_BOUND 0x0b48
  766. #define RADEON_SURFACE5_INFO 0x0b5c
  767. #define RADEON_SURFACE5_LOWER_BOUND 0x0b54
  768. #define RADEON_SURFACE5_UPPER_BOUND 0x0b58
  769. #define RADEON_SURFACE6_INFO 0x0b6c
  770. #define RADEON_SURFACE6_LOWER_BOUND 0x0b64
  771. #define RADEON_SURFACE6_UPPER_BOUND 0x0b68
  772. #define RADEON_SURFACE7_INFO 0x0b7c
  773. #define RADEON_SURFACE7_LOWER_BOUND 0x0b74
  774. #define RADEON_SURFACE7_UPPER_BOUND 0x0b78
  775. #define RADEON_SW_SEMAPHORE 0x013c
  776. #define RADEON_WAIT_UNTIL 0x1720
  777. # define RADEON_WAIT_CRTC_PFLIP (1 << 0)
  778. # define RADEON_WAIT_2D_IDLE (1 << 14)
  779. # define RADEON_WAIT_3D_IDLE (1 << 15)
  780. # define RADEON_WAIT_2D_IDLECLEAN (1 << 16)
  781. # define RADEON_WAIT_3D_IDLECLEAN (1 << 17)
  782. # define RADEON_WAIT_HOST_IDLECLEAN (1 << 18)
  783. #define RADEON_RB3D_ZMASKOFFSET 0x3234
  784. #define RADEON_RB3D_ZSTENCILCNTL 0x1c2c
  785. # define RADEON_DEPTH_FORMAT_16BIT_INT_Z (0 << 0)
  786. # define RADEON_DEPTH_FORMAT_24BIT_INT_Z (2 << 0)
  787. /* CP registers */
  788. #define RADEON_CP_ME_RAM_ADDR 0x07d4
  789. #define RADEON_CP_ME_RAM_RADDR 0x07d8
  790. #define RADEON_CP_ME_RAM_DATAH 0x07dc
  791. #define RADEON_CP_ME_RAM_DATAL 0x07e0
  792. #define RADEON_CP_RB_BASE 0x0700
  793. #define RADEON_CP_RB_CNTL 0x0704
  794. # define RADEON_BUF_SWAP_32BIT (2 << 16)
  795. # define RADEON_RB_NO_UPDATE (1 << 27)
  796. #define RADEON_CP_RB_RPTR_ADDR 0x070c
  797. #define RADEON_CP_RB_RPTR 0x0710
  798. #define RADEON_CP_RB_WPTR 0x0714
  799. #define RADEON_CP_RB_WPTR_DELAY 0x0718
  800. # define RADEON_PRE_WRITE_TIMER_SHIFT 0
  801. # define RADEON_PRE_WRITE_LIMIT_SHIFT 23
  802. #define RADEON_CP_IB_BASE 0x0738
  803. #define RADEON_CP_CSQ_CNTL 0x0740
  804. # define RADEON_CSQ_CNT_PRIMARY_MASK (0xff << 0)
  805. # define RADEON_CSQ_PRIDIS_INDDIS (0 << 28)
  806. # define RADEON_CSQ_PRIPIO_INDDIS (1 << 28)
  807. # define RADEON_CSQ_PRIBM_INDDIS (2 << 28)
  808. # define RADEON_CSQ_PRIPIO_INDBM (3 << 28)
  809. # define RADEON_CSQ_PRIBM_INDBM (4 << 28)
  810. # define RADEON_CSQ_PRIPIO_INDPIO (15 << 28)
  811. #define RADEON_AIC_CNTL 0x01d0
  812. # define RADEON_PCIGART_TRANSLATE_EN (1 << 0)
  813. #define RADEON_AIC_STAT 0x01d4
  814. #define RADEON_AIC_PT_BASE 0x01d8
  815. #define RADEON_AIC_LO_ADDR 0x01dc
  816. #define RADEON_AIC_HI_ADDR 0x01e0
  817. #define RADEON_AIC_TLB_ADDR 0x01e4
  818. #define RADEON_AIC_TLB_DATA 0x01e8
  819. /* CP command packets */
  820. #define RADEON_CP_PACKET0 0x00000000
  821. # define RADEON_ONE_REG_WR (1 << 15)
  822. #define RADEON_CP_PACKET1 0x40000000
  823. #define RADEON_CP_PACKET2 0x80000000
  824. #define RADEON_CP_PACKET3 0xC0000000
  825. # define RADEON_CP_NOP 0x00001000
  826. # define RADEON_CP_NEXT_CHAR 0x00001900
  827. # define RADEON_CP_PLY_NEXTSCAN 0x00001D00
  828. # define RADEON_CP_SET_SCISSORS 0x00001E00
  829. /* GEN_INDX_PRIM is unsupported starting with R300 */
  830. # define RADEON_3D_RNDR_GEN_INDX_PRIM 0x00002300
  831. # define RADEON_WAIT_FOR_IDLE 0x00002600
  832. # define RADEON_3D_DRAW_VBUF 0x00002800
  833. # define RADEON_3D_DRAW_IMMD 0x00002900
  834. # define RADEON_3D_DRAW_INDX 0x00002A00
  835. # define RADEON_CP_LOAD_PALETTE 0x00002C00
  836. # define RADEON_3D_LOAD_VBPNTR 0x00002F00
  837. # define RADEON_MPEG_IDCT_MACROBLOCK 0x00003000
  838. # define RADEON_MPEG_IDCT_MACROBLOCK_REV 0x00003100
  839. # define RADEON_3D_CLEAR_ZMASK 0x00003200
  840. # define RADEON_CP_INDX_BUFFER 0x00003300
  841. # define RADEON_CP_3D_DRAW_VBUF_2 0x00003400
  842. # define RADEON_CP_3D_DRAW_IMMD_2 0x00003500
  843. # define RADEON_CP_3D_DRAW_INDX_2 0x00003600
  844. # define RADEON_3D_CLEAR_HIZ 0x00003700
  845. # define RADEON_CP_3D_CLEAR_CMASK 0x00003802
  846. # define RADEON_CNTL_HOSTDATA_BLT 0x00009400
  847. # define RADEON_CNTL_PAINT_MULTI 0x00009A00
  848. # define RADEON_CNTL_BITBLT_MULTI 0x00009B00
  849. # define RADEON_CNTL_SET_SCISSORS 0xC0001E00
  850. #define RADEON_CP_PACKET_MASK 0xC0000000
  851. #define RADEON_CP_PACKET_COUNT_MASK 0x3fff0000
  852. #define RADEON_CP_PACKET0_REG_MASK 0x000007ff
  853. #define RADEON_CP_PACKET1_REG0_MASK 0x000007ff
  854. #define RADEON_CP_PACKET1_REG1_MASK 0x003ff800
  855. #define RADEON_VTX_Z_PRESENT (1 << 31)
  856. #define RADEON_VTX_PKCOLOR_PRESENT (1 << 3)
  857. #define RADEON_PRIM_TYPE_NONE (0 << 0)
  858. #define RADEON_PRIM_TYPE_POINT (1 << 0)
  859. #define RADEON_PRIM_TYPE_LINE (2 << 0)
  860. #define RADEON_PRIM_TYPE_LINE_STRIP (3 << 0)
  861. #define RADEON_PRIM_TYPE_TRI_LIST (4 << 0)
  862. #define RADEON_PRIM_TYPE_TRI_FAN (5 << 0)
  863. #define RADEON_PRIM_TYPE_TRI_STRIP (6 << 0)
  864. #define RADEON_PRIM_TYPE_TRI_TYPE2 (7 << 0)
  865. #define RADEON_PRIM_TYPE_RECT_LIST (8 << 0)
  866. #define RADEON_PRIM_TYPE_3VRT_POINT_LIST (9 << 0)
  867. #define RADEON_PRIM_TYPE_3VRT_LINE_LIST (10 << 0)
  868. #define RADEON_PRIM_TYPE_MASK 0xf
  869. #define RADEON_PRIM_WALK_IND (1 << 4)
  870. #define RADEON_PRIM_WALK_LIST (2 << 4)
  871. #define RADEON_PRIM_WALK_RING (3 << 4)
  872. #define RADEON_COLOR_ORDER_BGRA (0 << 6)
  873. #define RADEON_COLOR_ORDER_RGBA (1 << 6)
  874. #define RADEON_MAOS_ENABLE (1 << 7)
  875. #define RADEON_VTX_FMT_R128_MODE (0 << 8)
  876. #define RADEON_VTX_FMT_RADEON_MODE (1 << 8)
  877. #define RADEON_NUM_VERTICES_SHIFT 16
  878. #define RADEON_COLOR_FORMAT_CI8 2
  879. #define RADEON_COLOR_FORMAT_ARGB1555 3
  880. #define RADEON_COLOR_FORMAT_RGB565 4
  881. #define RADEON_COLOR_FORMAT_ARGB8888 6
  882. #define RADEON_COLOR_FORMAT_RGB332 7
  883. #define RADEON_COLOR_FORMAT_RGB8 9
  884. #define RADEON_COLOR_FORMAT_ARGB4444 15
  885. #define RADEON_TXFORMAT_I8 0
  886. #define RADEON_TXFORMAT_AI88 1
  887. #define RADEON_TXFORMAT_RGB332 2
  888. #define RADEON_TXFORMAT_ARGB1555 3
  889. #define RADEON_TXFORMAT_RGB565 4
  890. #define RADEON_TXFORMAT_ARGB4444 5
  891. #define RADEON_TXFORMAT_ARGB8888 6
  892. #define RADEON_TXFORMAT_RGBA8888 7
  893. #define RADEON_TXFORMAT_Y8 8
  894. #define RADEON_TXFORMAT_VYUY422 10
  895. #define RADEON_TXFORMAT_YVYU422 11
  896. #define RADEON_TXFORMAT_DXT1 12
  897. #define RADEON_TXFORMAT_DXT23 14
  898. #define RADEON_TXFORMAT_DXT45 15
  899. #define R200_PP_TXCBLEND_0 0x2f00
  900. #define R200_PP_TXCBLEND_1 0x2f10
  901. #define R200_PP_TXCBLEND_2 0x2f20
  902. #define R200_PP_TXCBLEND_3 0x2f30
  903. #define R200_PP_TXCBLEND_4 0x2f40
  904. #define R200_PP_TXCBLEND_5 0x2f50
  905. #define R200_PP_TXCBLEND_6 0x2f60
  906. #define R200_PP_TXCBLEND_7 0x2f70
  907. #define R200_SE_TCL_LIGHT_MODEL_CTL_0 0x2268
  908. #define R200_PP_TFACTOR_0 0x2ee0
  909. #define R200_SE_VTX_FMT_0 0x2088
  910. #define R200_SE_VAP_CNTL 0x2080
  911. #define R200_SE_TCL_MATRIX_SEL_0 0x2230
  912. #define R200_SE_TCL_TEX_PROC_CTL_2 0x22a8
  913. #define R200_SE_TCL_UCP_VERT_BLEND_CTL 0x22c0
  914. #define R200_PP_TXFILTER_5 0x2ca0
  915. #define R200_PP_TXFILTER_4 0x2c80
  916. #define R200_PP_TXFILTER_3 0x2c60
  917. #define R200_PP_TXFILTER_2 0x2c40
  918. #define R200_PP_TXFILTER_1 0x2c20
  919. #define R200_PP_TXFILTER_0 0x2c00
  920. #define R200_PP_TXOFFSET_5 0x2d78
  921. #define R200_PP_TXOFFSET_4 0x2d60
  922. #define R200_PP_TXOFFSET_3 0x2d48
  923. #define R200_PP_TXOFFSET_2 0x2d30
  924. #define R200_PP_TXOFFSET_1 0x2d18
  925. #define R200_PP_TXOFFSET_0 0x2d00
  926. #define R200_PP_CUBIC_FACES_0 0x2c18
  927. #define R200_PP_CUBIC_FACES_1 0x2c38
  928. #define R200_PP_CUBIC_FACES_2 0x2c58
  929. #define R200_PP_CUBIC_FACES_3 0x2c78
  930. #define R200_PP_CUBIC_FACES_4 0x2c98
  931. #define R200_PP_CUBIC_FACES_5 0x2cb8
  932. #define R200_PP_CUBIC_OFFSET_F1_0 0x2d04
  933. #define R200_PP_CUBIC_OFFSET_F2_0 0x2d08
  934. #define R200_PP_CUBIC_OFFSET_F3_0 0x2d0c
  935. #define R200_PP_CUBIC_OFFSET_F4_0 0x2d10
  936. #define R200_PP_CUBIC_OFFSET_F5_0 0x2d14
  937. #define R200_PP_CUBIC_OFFSET_F1_1 0x2d1c
  938. #define R200_PP_CUBIC_OFFSET_F2_1 0x2d20
  939. #define R200_PP_CUBIC_OFFSET_F3_1 0x2d24
  940. #define R200_PP_CUBIC_OFFSET_F4_1 0x2d28
  941. #define R200_PP_CUBIC_OFFSET_F5_1 0x2d2c
  942. #define R200_PP_CUBIC_OFFSET_F1_2 0x2d34
  943. #define R200_PP_CUBIC_OFFSET_F2_2 0x2d38
  944. #define R200_PP_CUBIC_OFFSET_F3_2 0x2d3c
  945. #define R200_PP_CUBIC_OFFSET_F4_2 0x2d40
  946. #define R200_PP_CUBIC_OFFSET_F5_2 0x2d44
  947. #define R200_PP_CUBIC_OFFSET_F1_3 0x2d4c
  948. #define R200_PP_CUBIC_OFFSET_F2_3 0x2d50
  949. #define R200_PP_CUBIC_OFFSET_F3_3 0x2d54
  950. #define R200_PP_CUBIC_OFFSET_F4_3 0x2d58
  951. #define R200_PP_CUBIC_OFFSET_F5_3 0x2d5c
  952. #define R200_PP_CUBIC_OFFSET_F1_4 0x2d64
  953. #define R200_PP_CUBIC_OFFSET_F2_4 0x2d68
  954. #define R200_PP_CUBIC_OFFSET_F3_4 0x2d6c
  955. #define R200_PP_CUBIC_OFFSET_F4_4 0x2d70
  956. #define R200_PP_CUBIC_OFFSET_F5_4 0x2d74
  957. #define R200_PP_CUBIC_OFFSET_F1_5 0x2d7c
  958. #define R200_PP_CUBIC_OFFSET_F2_5 0x2d80
  959. #define R200_PP_CUBIC_OFFSET_F3_5 0x2d84
  960. #define R200_PP_CUBIC_OFFSET_F4_5 0x2d88
  961. #define R200_PP_CUBIC_OFFSET_F5_5 0x2d8c
  962. #define R200_RE_AUX_SCISSOR_CNTL 0x26f0
  963. #define R200_SE_VTE_CNTL 0x20b0
  964. #define R200_SE_TCL_OUTPUT_VTX_COMP_SEL 0x2250
  965. #define R200_PP_TAM_DEBUG3 0x2d9c
  966. #define R200_PP_CNTL_X 0x2cc4
  967. #define R200_SE_VAP_CNTL_STATUS 0x2140
  968. #define R200_RE_SCISSOR_TL_0 0x1cd8
  969. #define R200_RE_SCISSOR_TL_1 0x1ce0
  970. #define R200_RE_SCISSOR_TL_2 0x1ce8
  971. #define R200_RB3D_DEPTHXY_OFFSET 0x1d60
  972. #define R200_RE_AUX_SCISSOR_CNTL 0x26f0
  973. #define R200_SE_VTX_STATE_CNTL 0x2180
  974. #define R200_RE_POINTSIZE 0x2648
  975. #define R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0 0x2254
  976. #define RADEON_PP_TEX_SIZE_0 0x1d04 /* NPOT */
  977. #define RADEON_PP_TEX_SIZE_1 0x1d0c
  978. #define RADEON_PP_TEX_SIZE_2 0x1d14
  979. #define RADEON_PP_CUBIC_FACES_0 0x1d24
  980. #define RADEON_PP_CUBIC_FACES_1 0x1d28
  981. #define RADEON_PP_CUBIC_FACES_2 0x1d2c
  982. #define RADEON_PP_CUBIC_OFFSET_T0_0 0x1dd0 /* bits [31:5] */
  983. #define RADEON_PP_CUBIC_OFFSET_T1_0 0x1e00
  984. #define RADEON_PP_CUBIC_OFFSET_T2_0 0x1e14
  985. #define RADEON_SE_TCL_STATE_FLUSH 0x2284
  986. #define SE_VAP_CNTL__TCL_ENA_MASK 0x00000001
  987. #define SE_VAP_CNTL__FORCE_W_TO_ONE_MASK 0x00010000
  988. #define SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT 0x00000012
  989. #define SE_VTE_CNTL__VTX_XY_FMT_MASK 0x00000100
  990. #define SE_VTE_CNTL__VTX_Z_FMT_MASK 0x00000200
  991. #define SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK 0x00000001
  992. #define SE_VTX_FMT_0__VTX_W0_PRESENT_MASK 0x00000002
  993. #define SE_VTX_FMT_0__VTX_COLOR_0_FMT__SHIFT 0x0000000b
  994. #define R200_3D_DRAW_IMMD_2 0xC0003500
  995. #define R200_SE_VTX_FMT_1 0x208c
  996. #define R200_RE_CNTL 0x1c50
  997. #define R200_RB3D_BLENDCOLOR 0x3218
  998. #define R200_SE_TCL_POINT_SPRITE_CNTL 0x22c4
  999. #define R200_PP_TRI_PERF 0x2cf8
  1000. #define R200_PP_AFS_0 0x2f80
  1001. #define R200_PP_AFS_1 0x2f00 /* same as txcblend_0 */
  1002. #define R200_VAP_PVS_CNTL_1 0x22D0
  1003. #define R500_D1CRTC_STATUS 0x609c
  1004. #define R500_D2CRTC_STATUS 0x689c
  1005. #define R500_CRTC_V_BLANK (1<<0)
  1006. #define R500_D1CRTC_FRAME_COUNT 0x60a4
  1007. #define R500_D2CRTC_FRAME_COUNT 0x68a4
  1008. #define R500_D1MODE_V_COUNTER 0x6530
  1009. #define R500_D2MODE_V_COUNTER 0x6d30
  1010. #define R500_D1MODE_VBLANK_STATUS 0x6534
  1011. #define R500_D2MODE_VBLANK_STATUS 0x6d34
  1012. #define R500_VBLANK_OCCURED (1<<0)
  1013. #define R500_VBLANK_ACK (1<<4)
  1014. #define R500_VBLANK_STAT (1<<12)
  1015. #define R500_VBLANK_INT (1<<16)
  1016. #define R500_DxMODE_INT_MASK 0x6540
  1017. #define R500_D1MODE_INT_MASK (1<<0)
  1018. #define R500_D2MODE_INT_MASK (1<<8)
  1019. #define R500_DISP_INTERRUPT_STATUS 0x7edc
  1020. #define R500_D1_VBLANK_INTERRUPT (1 << 4)
  1021. #define R500_D2_VBLANK_INTERRUPT (1 << 5)
  1022. /* Constants */
  1023. #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  1024. #define RADEON_LAST_FRAME_REG RADEON_SCRATCH_REG0
  1025. #define RADEON_LAST_DISPATCH_REG RADEON_SCRATCH_REG1
  1026. #define RADEON_LAST_CLEAR_REG RADEON_SCRATCH_REG2
  1027. #define RADEON_LAST_SWI_REG RADEON_SCRATCH_REG3
  1028. #define RADEON_LAST_DISPATCH 1
  1029. #define RADEON_MAX_VB_AGE 0x7fffffff
  1030. #define RADEON_MAX_VB_VERTS (0xffff)
  1031. #define RADEON_RING_HIGH_MARK 128
  1032. #define RADEON_PCIGART_TABLE_SIZE (32*1024)
  1033. #define RADEON_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
  1034. #define RADEON_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, (reg), (val) )
  1035. #define RADEON_READ8(reg) DRM_READ8( dev_priv->mmio, (reg) )
  1036. #define RADEON_WRITE8(reg,val) DRM_WRITE8( dev_priv->mmio, (reg), (val) )
  1037. #define RADEON_WRITE_PLL(addr, val) \
  1038. do { \
  1039. RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX, \
  1040. ((addr) & 0x1f) | RADEON_PLL_WR_EN ); \
  1041. RADEON_WRITE(RADEON_CLOCK_CNTL_DATA, (val)); \
  1042. } while (0)
  1043. #define RADEON_WRITE_PCIE(addr, val) \
  1044. do { \
  1045. RADEON_WRITE8(RADEON_PCIE_INDEX, \
  1046. ((addr) & 0xff)); \
  1047. RADEON_WRITE(RADEON_PCIE_DATA, (val)); \
  1048. } while (0)
  1049. #define R500_WRITE_MCIND(addr, val) \
  1050. do { \
  1051. RADEON_WRITE(R520_MC_IND_INDEX, 0xff0000 | ((addr) & 0xff)); \
  1052. RADEON_WRITE(R520_MC_IND_DATA, (val)); \
  1053. RADEON_WRITE(R520_MC_IND_INDEX, 0); \
  1054. } while (0)
  1055. #define RS480_WRITE_MCIND(addr, val) \
  1056. do { \
  1057. RADEON_WRITE(RS480_NB_MC_INDEX, \
  1058. ((addr) & 0xff) | RS480_NB_MC_IND_WR_EN); \
  1059. RADEON_WRITE(RS480_NB_MC_DATA, (val)); \
  1060. RADEON_WRITE(RS480_NB_MC_INDEX, 0xff); \
  1061. } while (0)
  1062. #define RS690_WRITE_MCIND(addr, val) \
  1063. do { \
  1064. RADEON_WRITE(RS690_MC_INDEX, RS690_MC_INDEX_WR_EN | ((addr) & RS690_MC_INDEX_MASK)); \
  1065. RADEON_WRITE(RS690_MC_DATA, val); \
  1066. RADEON_WRITE(RS690_MC_INDEX, RS690_MC_INDEX_WR_ACK); \
  1067. } while (0)
  1068. #define IGP_WRITE_MCIND(addr, val) \
  1069. do { \
  1070. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) \
  1071. RS690_WRITE_MCIND(addr, val); \
  1072. else \
  1073. RS480_WRITE_MCIND(addr, val); \
  1074. } while (0)
  1075. #define CP_PACKET0( reg, n ) \
  1076. (RADEON_CP_PACKET0 | ((n) << 16) | ((reg) >> 2))
  1077. #define CP_PACKET0_TABLE( reg, n ) \
  1078. (RADEON_CP_PACKET0 | RADEON_ONE_REG_WR | ((n) << 16) | ((reg) >> 2))
  1079. #define CP_PACKET1( reg0, reg1 ) \
  1080. (RADEON_CP_PACKET1 | (((reg1) >> 2) << 15) | ((reg0) >> 2))
  1081. #define CP_PACKET2() \
  1082. (RADEON_CP_PACKET2)
  1083. #define CP_PACKET3( pkt, n ) \
  1084. (RADEON_CP_PACKET3 | (pkt) | ((n) << 16))
  1085. /* ================================================================
  1086. * Engine control helper macros
  1087. */
  1088. #define RADEON_WAIT_UNTIL_2D_IDLE() do { \
  1089. OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
  1090. OUT_RING( (RADEON_WAIT_2D_IDLECLEAN | \
  1091. RADEON_WAIT_HOST_IDLECLEAN) ); \
  1092. } while (0)
  1093. #define RADEON_WAIT_UNTIL_3D_IDLE() do { \
  1094. OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
  1095. OUT_RING( (RADEON_WAIT_3D_IDLECLEAN | \
  1096. RADEON_WAIT_HOST_IDLECLEAN) ); \
  1097. } while (0)
  1098. #define RADEON_WAIT_UNTIL_IDLE() do { \
  1099. OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
  1100. OUT_RING( (RADEON_WAIT_2D_IDLECLEAN | \
  1101. RADEON_WAIT_3D_IDLECLEAN | \
  1102. RADEON_WAIT_HOST_IDLECLEAN) ); \
  1103. } while (0)
  1104. #define RADEON_WAIT_UNTIL_PAGE_FLIPPED() do { \
  1105. OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
  1106. OUT_RING( RADEON_WAIT_CRTC_PFLIP ); \
  1107. } while (0)
  1108. #define RADEON_FLUSH_CACHE() do { \
  1109. if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) { \
  1110. OUT_RING(CP_PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0)); \
  1111. OUT_RING(RADEON_RB3D_DC_FLUSH); \
  1112. } else { \
  1113. OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0)); \
  1114. OUT_RING(R300_RB3D_DC_FLUSH); \
  1115. } \
  1116. } while (0)
  1117. #define RADEON_PURGE_CACHE() do { \
  1118. if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) { \
  1119. OUT_RING(CP_PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0)); \
  1120. OUT_RING(RADEON_RB3D_DC_FLUSH | RADEON_RB3D_DC_FREE); \
  1121. } else { \
  1122. OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0)); \
  1123. OUT_RING(R300_RB3D_DC_FLUSH | R300_RB3D_DC_FREE); \
  1124. } \
  1125. } while (0)
  1126. #define RADEON_FLUSH_ZCACHE() do { \
  1127. if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) { \
  1128. OUT_RING(CP_PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0)); \
  1129. OUT_RING(RADEON_RB3D_ZC_FLUSH); \
  1130. } else { \
  1131. OUT_RING(CP_PACKET0(R300_ZB_ZCACHE_CTLSTAT, 0)); \
  1132. OUT_RING(R300_ZC_FLUSH); \
  1133. } \
  1134. } while (0)
  1135. #define RADEON_PURGE_ZCACHE() do { \
  1136. if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) { \
  1137. OUT_RING(CP_PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0)); \
  1138. OUT_RING(RADEON_RB3D_ZC_FLUSH | RADEON_RB3D_ZC_FREE); \
  1139. } else { \
  1140. OUT_RING(CP_PACKET0(R300_ZB_ZCACHE_CTLSTAT, 0)); \
  1141. OUT_RING(R300_ZC_FLUSH | R300_ZC_FREE); \
  1142. } \
  1143. } while (0)
  1144. /* ================================================================
  1145. * Misc helper macros
  1146. */
  1147. /* Perfbox functionality only.
  1148. */
  1149. #define RING_SPACE_TEST_WITH_RETURN( dev_priv ) \
  1150. do { \
  1151. if (!(dev_priv->stats.boxes & RADEON_BOX_DMA_IDLE)) { \
  1152. u32 head = GET_RING_HEAD( dev_priv ); \
  1153. if (head == dev_priv->ring.tail) \
  1154. dev_priv->stats.boxes |= RADEON_BOX_DMA_IDLE; \
  1155. } \
  1156. } while (0)
  1157. #define VB_AGE_TEST_WITH_RETURN( dev_priv ) \
  1158. do { \
  1159. drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv; \
  1160. if ( sarea_priv->last_dispatch >= RADEON_MAX_VB_AGE ) { \
  1161. int __ret = radeon_do_cp_idle( dev_priv ); \
  1162. if ( __ret ) return __ret; \
  1163. sarea_priv->last_dispatch = 0; \
  1164. radeon_freelist_reset( dev ); \
  1165. } \
  1166. } while (0)
  1167. #define RADEON_DISPATCH_AGE( age ) do { \
  1168. OUT_RING( CP_PACKET0( RADEON_LAST_DISPATCH_REG, 0 ) ); \
  1169. OUT_RING( age ); \
  1170. } while (0)
  1171. #define RADEON_FRAME_AGE( age ) do { \
  1172. OUT_RING( CP_PACKET0( RADEON_LAST_FRAME_REG, 0 ) ); \
  1173. OUT_RING( age ); \
  1174. } while (0)
  1175. #define RADEON_CLEAR_AGE( age ) do { \
  1176. OUT_RING( CP_PACKET0( RADEON_LAST_CLEAR_REG, 0 ) ); \
  1177. OUT_RING( age ); \
  1178. } while (0)
  1179. /* ================================================================
  1180. * Ring control
  1181. */
  1182. #define RADEON_VERBOSE 0
  1183. #define RING_LOCALS int write, _nr; unsigned int mask; u32 *ring;
  1184. #define BEGIN_RING( n ) do { \
  1185. if ( RADEON_VERBOSE ) { \
  1186. DRM_INFO( "BEGIN_RING( %d )\n", (n)); \
  1187. } \
  1188. if ( dev_priv->ring.space <= (n) * sizeof(u32) ) { \
  1189. COMMIT_RING(); \
  1190. radeon_wait_ring( dev_priv, (n) * sizeof(u32) ); \
  1191. } \
  1192. _nr = n; dev_priv->ring.space -= (n) * sizeof(u32); \
  1193. ring = dev_priv->ring.start; \
  1194. write = dev_priv->ring.tail; \
  1195. mask = dev_priv->ring.tail_mask; \
  1196. } while (0)
  1197. #define ADVANCE_RING() do { \
  1198. if ( RADEON_VERBOSE ) { \
  1199. DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n", \
  1200. write, dev_priv->ring.tail ); \
  1201. } \
  1202. if (((dev_priv->ring.tail + _nr) & mask) != write) { \
  1203. DRM_ERROR( \
  1204. "ADVANCE_RING(): mismatch: nr: %x write: %x line: %d\n", \
  1205. ((dev_priv->ring.tail + _nr) & mask), \
  1206. write, __LINE__); \
  1207. } else \
  1208. dev_priv->ring.tail = write; \
  1209. } while (0)
  1210. #define COMMIT_RING() do { \
  1211. /* Flush writes to ring */ \
  1212. DRM_MEMORYBARRIER(); \
  1213. GET_RING_HEAD( dev_priv ); \
  1214. RADEON_WRITE( RADEON_CP_RB_WPTR, dev_priv->ring.tail ); \
  1215. /* read from PCI bus to ensure correct posting */ \
  1216. RADEON_READ( RADEON_CP_RB_RPTR ); \
  1217. } while (0)
  1218. #define OUT_RING( x ) do { \
  1219. if ( RADEON_VERBOSE ) { \
  1220. DRM_INFO( " OUT_RING( 0x%08x ) at 0x%x\n", \
  1221. (unsigned int)(x), write ); \
  1222. } \
  1223. ring[write++] = (x); \
  1224. write &= mask; \
  1225. } while (0)
  1226. #define OUT_RING_REG( reg, val ) do { \
  1227. OUT_RING( CP_PACKET0( reg, 0 ) ); \
  1228. OUT_RING( val ); \
  1229. } while (0)
  1230. #define OUT_RING_TABLE( tab, sz ) do { \
  1231. int _size = (sz); \
  1232. int *_tab = (int *)(tab); \
  1233. \
  1234. if (write + _size > mask) { \
  1235. int _i = (mask+1) - write; \
  1236. _size -= _i; \
  1237. while (_i > 0 ) { \
  1238. *(int *)(ring + write) = *_tab++; \
  1239. write++; \
  1240. _i--; \
  1241. } \
  1242. write = 0; \
  1243. _tab += _i; \
  1244. } \
  1245. while (_size > 0) { \
  1246. *(ring + write) = *_tab++; \
  1247. write++; \
  1248. _size--; \
  1249. } \
  1250. write &= mask; \
  1251. } while (0)
  1252. #endif /* __RADEON_DRV_H__ */