18c2ecf20Sopenharmony_ci/* r128_drv.h -- Private header for r128 driver -*- linux-c -*- 28c2ecf20Sopenharmony_ci * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com 38c2ecf20Sopenharmony_ci */ 48c2ecf20Sopenharmony_ci/* 58c2ecf20Sopenharmony_ci * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 68c2ecf20Sopenharmony_ci * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 78c2ecf20Sopenharmony_ci * All rights reserved. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 108c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 118c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 128c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 138c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 148c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 178c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 188c2ecf20Sopenharmony_ci * Software. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 218c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 228c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 238c2ecf20Sopenharmony_ci * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 248c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 258c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 268c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * Authors: 298c2ecf20Sopenharmony_ci * Rickard E. (Rik) Faith <faith@valinux.com> 308c2ecf20Sopenharmony_ci * Kevin E. Martin <martin@valinux.com> 318c2ecf20Sopenharmony_ci * Gareth Hughes <gareth@valinux.com> 328c2ecf20Sopenharmony_ci * Michel D�zer <daenzerm@student.ethz.ch> 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#ifndef __R128_DRV_H__ 368c2ecf20Sopenharmony_ci#define __R128_DRV_H__ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include <linux/delay.h> 398c2ecf20Sopenharmony_ci#include <linux/io.h> 408c2ecf20Sopenharmony_ci#include <linux/irqreturn.h> 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#include <drm/drm_ioctl.h> 438c2ecf20Sopenharmony_ci#include <drm/drm_legacy.h> 448c2ecf20Sopenharmony_ci#include <drm/r128_drm.h> 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#include "ati_pcigart.h" 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* General customization: 498c2ecf20Sopenharmony_ci */ 508c2ecf20Sopenharmony_ci#define DRIVER_AUTHOR "Gareth Hughes, VA Linux Systems Inc." 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define DRIVER_NAME "r128" 538c2ecf20Sopenharmony_ci#define DRIVER_DESC "ATI Rage 128" 548c2ecf20Sopenharmony_ci#define DRIVER_DATE "20030725" 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* Interface history: 578c2ecf20Sopenharmony_ci * 588c2ecf20Sopenharmony_ci * ?? - ?? 598c2ecf20Sopenharmony_ci * 2.4 - Add support for ycbcr textures (no new ioctls) 608c2ecf20Sopenharmony_ci * 2.5 - Add FLIP ioctl, disable FULLSCREEN. 618c2ecf20Sopenharmony_ci */ 628c2ecf20Sopenharmony_ci#define DRIVER_MAJOR 2 638c2ecf20Sopenharmony_ci#define DRIVER_MINOR 5 648c2ecf20Sopenharmony_ci#define DRIVER_PATCHLEVEL 0 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci#define GET_RING_HEAD(dev_priv) R128_READ(R128_PM4_BUFFER_DL_RPTR) 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_citypedef struct drm_r128_freelist { 698c2ecf20Sopenharmony_ci unsigned int age; 708c2ecf20Sopenharmony_ci struct drm_buf *buf; 718c2ecf20Sopenharmony_ci struct drm_r128_freelist *next; 728c2ecf20Sopenharmony_ci struct drm_r128_freelist *prev; 738c2ecf20Sopenharmony_ci} drm_r128_freelist_t; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_citypedef struct drm_r128_ring_buffer { 768c2ecf20Sopenharmony_ci u32 *start; 778c2ecf20Sopenharmony_ci u32 *end; 788c2ecf20Sopenharmony_ci int size; 798c2ecf20Sopenharmony_ci int size_l2qw; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci u32 tail; 828c2ecf20Sopenharmony_ci u32 tail_mask; 838c2ecf20Sopenharmony_ci int space; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci int high_mark; 868c2ecf20Sopenharmony_ci} drm_r128_ring_buffer_t; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_citypedef struct drm_r128_private { 898c2ecf20Sopenharmony_ci drm_r128_ring_buffer_t ring; 908c2ecf20Sopenharmony_ci drm_r128_sarea_t *sarea_priv; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci int cce_mode; 938c2ecf20Sopenharmony_ci int cce_fifo_size; 948c2ecf20Sopenharmony_ci int cce_running; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci drm_r128_freelist_t *head; 978c2ecf20Sopenharmony_ci drm_r128_freelist_t *tail; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci int usec_timeout; 1008c2ecf20Sopenharmony_ci int is_pci; 1018c2ecf20Sopenharmony_ci unsigned long cce_buffers_offset; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci atomic_t idle_count; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci int page_flipping; 1068c2ecf20Sopenharmony_ci int current_page; 1078c2ecf20Sopenharmony_ci u32 crtc_offset; 1088c2ecf20Sopenharmony_ci u32 crtc_offset_cntl; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci atomic_t vbl_received; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci u32 color_fmt; 1138c2ecf20Sopenharmony_ci unsigned int front_offset; 1148c2ecf20Sopenharmony_ci unsigned int front_pitch; 1158c2ecf20Sopenharmony_ci unsigned int back_offset; 1168c2ecf20Sopenharmony_ci unsigned int back_pitch; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci u32 depth_fmt; 1198c2ecf20Sopenharmony_ci unsigned int depth_offset; 1208c2ecf20Sopenharmony_ci unsigned int depth_pitch; 1218c2ecf20Sopenharmony_ci unsigned int span_offset; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci u32 front_pitch_offset_c; 1248c2ecf20Sopenharmony_ci u32 back_pitch_offset_c; 1258c2ecf20Sopenharmony_ci u32 depth_pitch_offset_c; 1268c2ecf20Sopenharmony_ci u32 span_pitch_offset_c; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci drm_local_map_t *sarea; 1298c2ecf20Sopenharmony_ci drm_local_map_t *mmio; 1308c2ecf20Sopenharmony_ci drm_local_map_t *cce_ring; 1318c2ecf20Sopenharmony_ci drm_local_map_t *ring_rptr; 1328c2ecf20Sopenharmony_ci drm_local_map_t *agp_textures; 1338c2ecf20Sopenharmony_ci struct drm_ati_pcigart_info gart_info; 1348c2ecf20Sopenharmony_ci} drm_r128_private_t; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_citypedef struct drm_r128_buf_priv { 1378c2ecf20Sopenharmony_ci u32 age; 1388c2ecf20Sopenharmony_ci int prim; 1398c2ecf20Sopenharmony_ci int discard; 1408c2ecf20Sopenharmony_ci int dispatched; 1418c2ecf20Sopenharmony_ci drm_r128_freelist_t *list_entry; 1428c2ecf20Sopenharmony_ci} drm_r128_buf_priv_t; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ciextern const struct drm_ioctl_desc r128_ioctls[]; 1458c2ecf20Sopenharmony_ciextern int r128_max_ioctl; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci /* r128_cce.c */ 1488c2ecf20Sopenharmony_ciextern int r128_cce_init(struct drm_device *dev, void *data, struct drm_file *file_priv); 1498c2ecf20Sopenharmony_ciextern int r128_cce_start(struct drm_device *dev, void *data, struct drm_file *file_priv); 1508c2ecf20Sopenharmony_ciextern int r128_cce_stop(struct drm_device *dev, void *data, struct drm_file *file_priv); 1518c2ecf20Sopenharmony_ciextern int r128_cce_reset(struct drm_device *dev, void *data, struct drm_file *file_priv); 1528c2ecf20Sopenharmony_ciextern int r128_cce_idle(struct drm_device *dev, void *data, struct drm_file *file_priv); 1538c2ecf20Sopenharmony_ciextern int r128_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv); 1548c2ecf20Sopenharmony_ciextern int r128_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv); 1558c2ecf20Sopenharmony_ciextern int r128_cce_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv); 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ciextern int r128_cce_stipple(struct drm_device *dev, void *data, struct drm_file *file_priv); 1588c2ecf20Sopenharmony_ciextern int r128_cce_depth(struct drm_device *dev, void *data, struct drm_file *file_priv); 1598c2ecf20Sopenharmony_ciextern int r128_getparam(struct drm_device *dev, void *data, struct drm_file *file_priv); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ciextern void r128_freelist_reset(struct drm_device *dev); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ciextern int r128_wait_ring(drm_r128_private_t *dev_priv, int n); 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ciextern int r128_do_cce_idle(drm_r128_private_t *dev_priv); 1668c2ecf20Sopenharmony_ciextern int r128_do_cleanup_cce(struct drm_device *dev); 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ciextern int r128_enable_vblank(struct drm_device *dev, unsigned int pipe); 1698c2ecf20Sopenharmony_ciextern void r128_disable_vblank(struct drm_device *dev, unsigned int pipe); 1708c2ecf20Sopenharmony_ciextern u32 r128_get_vblank_counter(struct drm_device *dev, unsigned int pipe); 1718c2ecf20Sopenharmony_ciextern irqreturn_t r128_driver_irq_handler(int irq, void *arg); 1728c2ecf20Sopenharmony_ciextern void r128_driver_irq_preinstall(struct drm_device *dev); 1738c2ecf20Sopenharmony_ciextern int r128_driver_irq_postinstall(struct drm_device *dev); 1748c2ecf20Sopenharmony_ciextern void r128_driver_irq_uninstall(struct drm_device *dev); 1758c2ecf20Sopenharmony_ciextern void r128_driver_lastclose(struct drm_device *dev); 1768c2ecf20Sopenharmony_ciextern int r128_driver_load(struct drm_device *dev, unsigned long flags); 1778c2ecf20Sopenharmony_ciextern void r128_driver_preclose(struct drm_device *dev, 1788c2ecf20Sopenharmony_ci struct drm_file *file_priv); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ciextern long r128_compat_ioctl(struct file *filp, unsigned int cmd, 1818c2ecf20Sopenharmony_ci unsigned long arg); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci/* Register definitions, register access macros and drmAddMap constants 1848c2ecf20Sopenharmony_ci * for Rage 128 kernel driver. 1858c2ecf20Sopenharmony_ci */ 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci#define R128_AUX_SC_CNTL 0x1660 1888c2ecf20Sopenharmony_ci# define R128_AUX1_SC_EN (1 << 0) 1898c2ecf20Sopenharmony_ci# define R128_AUX1_SC_MODE_OR (0 << 1) 1908c2ecf20Sopenharmony_ci# define R128_AUX1_SC_MODE_NAND (1 << 1) 1918c2ecf20Sopenharmony_ci# define R128_AUX2_SC_EN (1 << 2) 1928c2ecf20Sopenharmony_ci# define R128_AUX2_SC_MODE_OR (0 << 3) 1938c2ecf20Sopenharmony_ci# define R128_AUX2_SC_MODE_NAND (1 << 3) 1948c2ecf20Sopenharmony_ci# define R128_AUX3_SC_EN (1 << 4) 1958c2ecf20Sopenharmony_ci# define R128_AUX3_SC_MODE_OR (0 << 5) 1968c2ecf20Sopenharmony_ci# define R128_AUX3_SC_MODE_NAND (1 << 5) 1978c2ecf20Sopenharmony_ci#define R128_AUX1_SC_LEFT 0x1664 1988c2ecf20Sopenharmony_ci#define R128_AUX1_SC_RIGHT 0x1668 1998c2ecf20Sopenharmony_ci#define R128_AUX1_SC_TOP 0x166c 2008c2ecf20Sopenharmony_ci#define R128_AUX1_SC_BOTTOM 0x1670 2018c2ecf20Sopenharmony_ci#define R128_AUX2_SC_LEFT 0x1674 2028c2ecf20Sopenharmony_ci#define R128_AUX2_SC_RIGHT 0x1678 2038c2ecf20Sopenharmony_ci#define R128_AUX2_SC_TOP 0x167c 2048c2ecf20Sopenharmony_ci#define R128_AUX2_SC_BOTTOM 0x1680 2058c2ecf20Sopenharmony_ci#define R128_AUX3_SC_LEFT 0x1684 2068c2ecf20Sopenharmony_ci#define R128_AUX3_SC_RIGHT 0x1688 2078c2ecf20Sopenharmony_ci#define R128_AUX3_SC_TOP 0x168c 2088c2ecf20Sopenharmony_ci#define R128_AUX3_SC_BOTTOM 0x1690 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci#define R128_BRUSH_DATA0 0x1480 2118c2ecf20Sopenharmony_ci#define R128_BUS_CNTL 0x0030 2128c2ecf20Sopenharmony_ci# define R128_BUS_MASTER_DIS (1 << 6) 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci#define R128_CLOCK_CNTL_INDEX 0x0008 2158c2ecf20Sopenharmony_ci#define R128_CLOCK_CNTL_DATA 0x000c 2168c2ecf20Sopenharmony_ci# define R128_PLL_WR_EN (1 << 7) 2178c2ecf20Sopenharmony_ci#define R128_CONSTANT_COLOR_C 0x1d34 2188c2ecf20Sopenharmony_ci#define R128_CRTC_OFFSET 0x0224 2198c2ecf20Sopenharmony_ci#define R128_CRTC_OFFSET_CNTL 0x0228 2208c2ecf20Sopenharmony_ci# define R128_CRTC_OFFSET_FLIP_CNTL (1 << 16) 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci#define R128_DP_GUI_MASTER_CNTL 0x146c 2238c2ecf20Sopenharmony_ci# define R128_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0) 2248c2ecf20Sopenharmony_ci# define R128_GMC_DST_PITCH_OFFSET_CNTL (1 << 1) 2258c2ecf20Sopenharmony_ci# define R128_GMC_BRUSH_SOLID_COLOR (13 << 4) 2268c2ecf20Sopenharmony_ci# define R128_GMC_BRUSH_NONE (15 << 4) 2278c2ecf20Sopenharmony_ci# define R128_GMC_DST_16BPP (4 << 8) 2288c2ecf20Sopenharmony_ci# define R128_GMC_DST_24BPP (5 << 8) 2298c2ecf20Sopenharmony_ci# define R128_GMC_DST_32BPP (6 << 8) 2308c2ecf20Sopenharmony_ci# define R128_GMC_DST_DATATYPE_SHIFT 8 2318c2ecf20Sopenharmony_ci# define R128_GMC_SRC_DATATYPE_COLOR (3 << 12) 2328c2ecf20Sopenharmony_ci# define R128_DP_SRC_SOURCE_MEMORY (2 << 24) 2338c2ecf20Sopenharmony_ci# define R128_DP_SRC_SOURCE_HOST_DATA (3 << 24) 2348c2ecf20Sopenharmony_ci# define R128_GMC_CLR_CMP_CNTL_DIS (1 << 28) 2358c2ecf20Sopenharmony_ci# define R128_GMC_AUX_CLIP_DIS (1 << 29) 2368c2ecf20Sopenharmony_ci# define R128_GMC_WR_MSK_DIS (1 << 30) 2378c2ecf20Sopenharmony_ci# define R128_ROP3_S 0x00cc0000 2388c2ecf20Sopenharmony_ci# define R128_ROP3_P 0x00f00000 2398c2ecf20Sopenharmony_ci#define R128_DP_WRITE_MASK 0x16cc 2408c2ecf20Sopenharmony_ci#define R128_DST_PITCH_OFFSET_C 0x1c80 2418c2ecf20Sopenharmony_ci# define R128_DST_TILE (1 << 31) 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci#define R128_GEN_INT_CNTL 0x0040 2448c2ecf20Sopenharmony_ci# define R128_CRTC_VBLANK_INT_EN (1 << 0) 2458c2ecf20Sopenharmony_ci#define R128_GEN_INT_STATUS 0x0044 2468c2ecf20Sopenharmony_ci# define R128_CRTC_VBLANK_INT (1 << 0) 2478c2ecf20Sopenharmony_ci# define R128_CRTC_VBLANK_INT_AK (1 << 0) 2488c2ecf20Sopenharmony_ci#define R128_GEN_RESET_CNTL 0x00f0 2498c2ecf20Sopenharmony_ci# define R128_SOFT_RESET_GUI (1 << 0) 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci#define R128_GUI_SCRATCH_REG0 0x15e0 2528c2ecf20Sopenharmony_ci#define R128_GUI_SCRATCH_REG1 0x15e4 2538c2ecf20Sopenharmony_ci#define R128_GUI_SCRATCH_REG2 0x15e8 2548c2ecf20Sopenharmony_ci#define R128_GUI_SCRATCH_REG3 0x15ec 2558c2ecf20Sopenharmony_ci#define R128_GUI_SCRATCH_REG4 0x15f0 2568c2ecf20Sopenharmony_ci#define R128_GUI_SCRATCH_REG5 0x15f4 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci#define R128_GUI_STAT 0x1740 2598c2ecf20Sopenharmony_ci# define R128_GUI_FIFOCNT_MASK 0x0fff 2608c2ecf20Sopenharmony_ci# define R128_GUI_ACTIVE (1 << 31) 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci#define R128_MCLK_CNTL 0x000f 2638c2ecf20Sopenharmony_ci# define R128_FORCE_GCP (1 << 16) 2648c2ecf20Sopenharmony_ci# define R128_FORCE_PIPE3D_CP (1 << 17) 2658c2ecf20Sopenharmony_ci# define R128_FORCE_RCP (1 << 18) 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci#define R128_PC_GUI_CTLSTAT 0x1748 2688c2ecf20Sopenharmony_ci#define R128_PC_NGUI_CTLSTAT 0x0184 2698c2ecf20Sopenharmony_ci# define R128_PC_FLUSH_GUI (3 << 0) 2708c2ecf20Sopenharmony_ci# define R128_PC_RI_GUI (1 << 2) 2718c2ecf20Sopenharmony_ci# define R128_PC_FLUSH_ALL 0x00ff 2728c2ecf20Sopenharmony_ci# define R128_PC_BUSY (1 << 31) 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci#define R128_PCI_GART_PAGE 0x017c 2758c2ecf20Sopenharmony_ci#define R128_PRIM_TEX_CNTL_C 0x1cb0 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci#define R128_SCALE_3D_CNTL 0x1a00 2788c2ecf20Sopenharmony_ci#define R128_SEC_TEX_CNTL_C 0x1d00 2798c2ecf20Sopenharmony_ci#define R128_SEC_TEXTURE_BORDER_COLOR_C 0x1d3c 2808c2ecf20Sopenharmony_ci#define R128_SETUP_CNTL 0x1bc4 2818c2ecf20Sopenharmony_ci#define R128_STEN_REF_MASK_C 0x1d40 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci#define R128_TEX_CNTL_C 0x1c9c 2848c2ecf20Sopenharmony_ci# define R128_TEX_CACHE_FLUSH (1 << 23) 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci#define R128_WAIT_UNTIL 0x1720 2878c2ecf20Sopenharmony_ci# define R128_EVENT_CRTC_OFFSET (1 << 0) 2888c2ecf20Sopenharmony_ci#define R128_WINDOW_XY_OFFSET 0x1bcc 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci/* CCE registers 2918c2ecf20Sopenharmony_ci */ 2928c2ecf20Sopenharmony_ci#define R128_PM4_BUFFER_OFFSET 0x0700 2938c2ecf20Sopenharmony_ci#define R128_PM4_BUFFER_CNTL 0x0704 2948c2ecf20Sopenharmony_ci# define R128_PM4_MASK (15 << 28) 2958c2ecf20Sopenharmony_ci# define R128_PM4_NONPM4 (0 << 28) 2968c2ecf20Sopenharmony_ci# define R128_PM4_192PIO (1 << 28) 2978c2ecf20Sopenharmony_ci# define R128_PM4_192BM (2 << 28) 2988c2ecf20Sopenharmony_ci# define R128_PM4_128PIO_64INDBM (3 << 28) 2998c2ecf20Sopenharmony_ci# define R128_PM4_128BM_64INDBM (4 << 28) 3008c2ecf20Sopenharmony_ci# define R128_PM4_64PIO_128INDBM (5 << 28) 3018c2ecf20Sopenharmony_ci# define R128_PM4_64BM_128INDBM (6 << 28) 3028c2ecf20Sopenharmony_ci# define R128_PM4_64PIO_64VCBM_64INDBM (7 << 28) 3038c2ecf20Sopenharmony_ci# define R128_PM4_64BM_64VCBM_64INDBM (8 << 28) 3048c2ecf20Sopenharmony_ci# define R128_PM4_64PIO_64VCPIO_64INDPIO (15 << 28) 3058c2ecf20Sopenharmony_ci# define R128_PM4_BUFFER_CNTL_NOUPDATE (1 << 27) 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci#define R128_PM4_BUFFER_WM_CNTL 0x0708 3088c2ecf20Sopenharmony_ci# define R128_WMA_SHIFT 0 3098c2ecf20Sopenharmony_ci# define R128_WMB_SHIFT 8 3108c2ecf20Sopenharmony_ci# define R128_WMC_SHIFT 16 3118c2ecf20Sopenharmony_ci# define R128_WB_WM_SHIFT 24 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci#define R128_PM4_BUFFER_DL_RPTR_ADDR 0x070c 3148c2ecf20Sopenharmony_ci#define R128_PM4_BUFFER_DL_RPTR 0x0710 3158c2ecf20Sopenharmony_ci#define R128_PM4_BUFFER_DL_WPTR 0x0714 3168c2ecf20Sopenharmony_ci# define R128_PM4_BUFFER_DL_DONE (1 << 31) 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci#define R128_PM4_VC_FPU_SETUP 0x071c 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci#define R128_PM4_IW_INDOFF 0x0738 3218c2ecf20Sopenharmony_ci#define R128_PM4_IW_INDSIZE 0x073c 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci#define R128_PM4_STAT 0x07b8 3248c2ecf20Sopenharmony_ci# define R128_PM4_FIFOCNT_MASK 0x0fff 3258c2ecf20Sopenharmony_ci# define R128_PM4_BUSY (1 << 16) 3268c2ecf20Sopenharmony_ci# define R128_PM4_GUI_ACTIVE (1 << 31) 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci#define R128_PM4_MICROCODE_ADDR 0x07d4 3298c2ecf20Sopenharmony_ci#define R128_PM4_MICROCODE_RADDR 0x07d8 3308c2ecf20Sopenharmony_ci#define R128_PM4_MICROCODE_DATAH 0x07dc 3318c2ecf20Sopenharmony_ci#define R128_PM4_MICROCODE_DATAL 0x07e0 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci#define R128_PM4_BUFFER_ADDR 0x07f0 3348c2ecf20Sopenharmony_ci#define R128_PM4_MICRO_CNTL 0x07fc 3358c2ecf20Sopenharmony_ci# define R128_PM4_MICRO_FREERUN (1 << 30) 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci#define R128_PM4_FIFO_DATA_EVEN 0x1000 3388c2ecf20Sopenharmony_ci#define R128_PM4_FIFO_DATA_ODD 0x1004 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci/* CCE command packets 3418c2ecf20Sopenharmony_ci */ 3428c2ecf20Sopenharmony_ci#define R128_CCE_PACKET0 0x00000000 3438c2ecf20Sopenharmony_ci#define R128_CCE_PACKET1 0x40000000 3448c2ecf20Sopenharmony_ci#define R128_CCE_PACKET2 0x80000000 3458c2ecf20Sopenharmony_ci#define R128_CCE_PACKET3 0xC0000000 3468c2ecf20Sopenharmony_ci# define R128_CNTL_HOSTDATA_BLT 0x00009400 3478c2ecf20Sopenharmony_ci# define R128_CNTL_PAINT_MULTI 0x00009A00 3488c2ecf20Sopenharmony_ci# define R128_CNTL_BITBLT_MULTI 0x00009B00 3498c2ecf20Sopenharmony_ci# define R128_3D_RNDR_GEN_INDX_PRIM 0x00002300 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci#define R128_CCE_PACKET_MASK 0xC0000000 3528c2ecf20Sopenharmony_ci#define R128_CCE_PACKET_COUNT_MASK 0x3fff0000 3538c2ecf20Sopenharmony_ci#define R128_CCE_PACKET0_REG_MASK 0x000007ff 3548c2ecf20Sopenharmony_ci#define R128_CCE_PACKET1_REG0_MASK 0x000007ff 3558c2ecf20Sopenharmony_ci#define R128_CCE_PACKET1_REG1_MASK 0x003ff800 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_TYPE_NONE 0x00000000 3588c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_TYPE_POINT 0x00000001 3598c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_TYPE_LINE 0x00000002 3608c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_TYPE_POLY_LINE 0x00000003 3618c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST 0x00000004 3628c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_FAN 0x00000005 3638c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_STRIP 0x00000006 3648c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2 0x00000007 3658c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_WALK_IND 0x00000010 3668c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_WALK_LIST 0x00000020 3678c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_PRIM_WALK_RING 0x00000030 3688c2ecf20Sopenharmony_ci#define R128_CCE_VC_CNTL_NUM_SHIFT 16 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci#define R128_DATATYPE_VQ 0 3718c2ecf20Sopenharmony_ci#define R128_DATATYPE_CI4 1 3728c2ecf20Sopenharmony_ci#define R128_DATATYPE_CI8 2 3738c2ecf20Sopenharmony_ci#define R128_DATATYPE_ARGB1555 3 3748c2ecf20Sopenharmony_ci#define R128_DATATYPE_RGB565 4 3758c2ecf20Sopenharmony_ci#define R128_DATATYPE_RGB888 5 3768c2ecf20Sopenharmony_ci#define R128_DATATYPE_ARGB8888 6 3778c2ecf20Sopenharmony_ci#define R128_DATATYPE_RGB332 7 3788c2ecf20Sopenharmony_ci#define R128_DATATYPE_Y8 8 3798c2ecf20Sopenharmony_ci#define R128_DATATYPE_RGB8 9 3808c2ecf20Sopenharmony_ci#define R128_DATATYPE_CI16 10 3818c2ecf20Sopenharmony_ci#define R128_DATATYPE_YVYU422 11 3828c2ecf20Sopenharmony_ci#define R128_DATATYPE_VYUY422 12 3838c2ecf20Sopenharmony_ci#define R128_DATATYPE_AYUV444 14 3848c2ecf20Sopenharmony_ci#define R128_DATATYPE_ARGB4444 15 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci/* Constants */ 3878c2ecf20Sopenharmony_ci#define R128_AGP_OFFSET 0x02000000 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci#define R128_WATERMARK_L 16 3908c2ecf20Sopenharmony_ci#define R128_WATERMARK_M 8 3918c2ecf20Sopenharmony_ci#define R128_WATERMARK_N 8 3928c2ecf20Sopenharmony_ci#define R128_WATERMARK_K 128 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci#define R128_MAX_USEC_TIMEOUT 100000 /* 100 ms */ 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci#define R128_LAST_FRAME_REG R128_GUI_SCRATCH_REG0 3978c2ecf20Sopenharmony_ci#define R128_LAST_DISPATCH_REG R128_GUI_SCRATCH_REG1 3988c2ecf20Sopenharmony_ci#define R128_MAX_VB_AGE 0x7fffffff 3998c2ecf20Sopenharmony_ci#define R128_MAX_VB_VERTS (0xffff) 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci#define R128_RING_HIGH_MARK 128 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci#define R128_PERFORMANCE_BOXES 0 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci#define R128_PCIGART_TABLE_SIZE 32768 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci#define R128_READ(reg) readl(((void __iomem *)dev_priv->mmio->handle) + (reg)) 4088c2ecf20Sopenharmony_ci#define R128_WRITE(reg, val) writel(val, ((void __iomem *)dev_priv->mmio->handle) + (reg)) 4098c2ecf20Sopenharmony_ci#define R128_READ8(reg) readb(((void __iomem *)dev_priv->mmio->handle) + (reg)) 4108c2ecf20Sopenharmony_ci#define R128_WRITE8(reg, val) writeb(val, ((void __iomem *)dev_priv->mmio->handle) + (reg)) 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci#define R128_WRITE_PLL(addr, val) \ 4138c2ecf20Sopenharmony_cido { \ 4148c2ecf20Sopenharmony_ci R128_WRITE8(R128_CLOCK_CNTL_INDEX, \ 4158c2ecf20Sopenharmony_ci ((addr) & 0x1f) | R128_PLL_WR_EN); \ 4168c2ecf20Sopenharmony_ci R128_WRITE(R128_CLOCK_CNTL_DATA, (val)); \ 4178c2ecf20Sopenharmony_ci} while (0) 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci#define CCE_PACKET0(reg, n) (R128_CCE_PACKET0 | \ 4208c2ecf20Sopenharmony_ci ((n) << 16) | ((reg) >> 2)) 4218c2ecf20Sopenharmony_ci#define CCE_PACKET1(reg0, reg1) (R128_CCE_PACKET1 | \ 4228c2ecf20Sopenharmony_ci (((reg1) >> 2) << 11) | ((reg0) >> 2)) 4238c2ecf20Sopenharmony_ci#define CCE_PACKET2() (R128_CCE_PACKET2) 4248c2ecf20Sopenharmony_ci#define CCE_PACKET3(pkt, n) (R128_CCE_PACKET3 | \ 4258c2ecf20Sopenharmony_ci (pkt) | ((n) << 16)) 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_cistatic __inline__ void r128_update_ring_snapshot(drm_r128_private_t *dev_priv) 4288c2ecf20Sopenharmony_ci{ 4298c2ecf20Sopenharmony_ci drm_r128_ring_buffer_t *ring = &dev_priv->ring; 4308c2ecf20Sopenharmony_ci ring->space = (GET_RING_HEAD(dev_priv) - ring->tail) * sizeof(u32); 4318c2ecf20Sopenharmony_ci if (ring->space <= 0) 4328c2ecf20Sopenharmony_ci ring->space += ring->size; 4338c2ecf20Sopenharmony_ci} 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci/* ================================================================ 4368c2ecf20Sopenharmony_ci * Misc helper macros 4378c2ecf20Sopenharmony_ci */ 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci#define DEV_INIT_TEST_WITH_RETURN(_dev_priv) \ 4408c2ecf20Sopenharmony_cido { \ 4418c2ecf20Sopenharmony_ci if (!_dev_priv) { \ 4428c2ecf20Sopenharmony_ci DRM_ERROR("called with no initialization\n"); \ 4438c2ecf20Sopenharmony_ci return -EINVAL; \ 4448c2ecf20Sopenharmony_ci } \ 4458c2ecf20Sopenharmony_ci} while (0) 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci#define RING_SPACE_TEST_WITH_RETURN(dev_priv) \ 4488c2ecf20Sopenharmony_cido { \ 4498c2ecf20Sopenharmony_ci drm_r128_ring_buffer_t *ring = &dev_priv->ring; int i; \ 4508c2ecf20Sopenharmony_ci if (ring->space < ring->high_mark) { \ 4518c2ecf20Sopenharmony_ci for (i = 0 ; i < dev_priv->usec_timeout ; i++) { \ 4528c2ecf20Sopenharmony_ci r128_update_ring_snapshot(dev_priv); \ 4538c2ecf20Sopenharmony_ci if (ring->space >= ring->high_mark) \ 4548c2ecf20Sopenharmony_ci goto __ring_space_done; \ 4558c2ecf20Sopenharmony_ci udelay(1); \ 4568c2ecf20Sopenharmony_ci } \ 4578c2ecf20Sopenharmony_ci DRM_ERROR("ring space check failed!\n"); \ 4588c2ecf20Sopenharmony_ci return -EBUSY; \ 4598c2ecf20Sopenharmony_ci } \ 4608c2ecf20Sopenharmony_ci __ring_space_done: \ 4618c2ecf20Sopenharmony_ci ; \ 4628c2ecf20Sopenharmony_ci} while (0) 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci#define VB_AGE_TEST_WITH_RETURN(dev_priv) \ 4658c2ecf20Sopenharmony_cido { \ 4668c2ecf20Sopenharmony_ci drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; \ 4678c2ecf20Sopenharmony_ci if (sarea_priv->last_dispatch >= R128_MAX_VB_AGE) { \ 4688c2ecf20Sopenharmony_ci int __ret = r128_do_cce_idle(dev_priv); \ 4698c2ecf20Sopenharmony_ci if (__ret) \ 4708c2ecf20Sopenharmony_ci return __ret; \ 4718c2ecf20Sopenharmony_ci sarea_priv->last_dispatch = 0; \ 4728c2ecf20Sopenharmony_ci r128_freelist_reset(dev); \ 4738c2ecf20Sopenharmony_ci } \ 4748c2ecf20Sopenharmony_ci} while (0) 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci#define R128_WAIT_UNTIL_PAGE_FLIPPED() do { \ 4778c2ecf20Sopenharmony_ci OUT_RING(CCE_PACKET0(R128_WAIT_UNTIL, 0)); \ 4788c2ecf20Sopenharmony_ci OUT_RING(R128_EVENT_CRTC_OFFSET); \ 4798c2ecf20Sopenharmony_ci} while (0) 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci/* ================================================================ 4828c2ecf20Sopenharmony_ci * Ring control 4838c2ecf20Sopenharmony_ci */ 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci#define R128_VERBOSE 0 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci#define RING_LOCALS \ 4888c2ecf20Sopenharmony_ci int write, _nr; unsigned int tail_mask; volatile u32 *ring; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci#define BEGIN_RING(n) do { \ 4918c2ecf20Sopenharmony_ci if (R128_VERBOSE) \ 4928c2ecf20Sopenharmony_ci DRM_INFO("BEGIN_RING(%d)\n", (n)); \ 4938c2ecf20Sopenharmony_ci if (dev_priv->ring.space <= (n) * sizeof(u32)) { \ 4948c2ecf20Sopenharmony_ci COMMIT_RING(); \ 4958c2ecf20Sopenharmony_ci r128_wait_ring(dev_priv, (n) * sizeof(u32)); \ 4968c2ecf20Sopenharmony_ci } \ 4978c2ecf20Sopenharmony_ci _nr = n; dev_priv->ring.space -= (n) * sizeof(u32); \ 4988c2ecf20Sopenharmony_ci ring = dev_priv->ring.start; \ 4998c2ecf20Sopenharmony_ci write = dev_priv->ring.tail; \ 5008c2ecf20Sopenharmony_ci tail_mask = dev_priv->ring.tail_mask; \ 5018c2ecf20Sopenharmony_ci} while (0) 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci/* You can set this to zero if you want. If the card locks up, you'll 5048c2ecf20Sopenharmony_ci * need to keep this set. It works around a bug in early revs of the 5058c2ecf20Sopenharmony_ci * Rage 128 chipset, where the CCE would read 32 dwords past the end of 5068c2ecf20Sopenharmony_ci * the ring buffer before wrapping around. 5078c2ecf20Sopenharmony_ci */ 5088c2ecf20Sopenharmony_ci#define R128_BROKEN_CCE 1 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci#define ADVANCE_RING() do { \ 5118c2ecf20Sopenharmony_ci if (R128_VERBOSE) \ 5128c2ecf20Sopenharmony_ci DRM_INFO("ADVANCE_RING() wr=0x%06x tail=0x%06x\n", \ 5138c2ecf20Sopenharmony_ci write, dev_priv->ring.tail); \ 5148c2ecf20Sopenharmony_ci if (R128_BROKEN_CCE && write < 32) \ 5158c2ecf20Sopenharmony_ci memcpy(dev_priv->ring.end, \ 5168c2ecf20Sopenharmony_ci dev_priv->ring.start, \ 5178c2ecf20Sopenharmony_ci write * sizeof(u32)); \ 5188c2ecf20Sopenharmony_ci if (((dev_priv->ring.tail + _nr) & tail_mask) != write) \ 5198c2ecf20Sopenharmony_ci DRM_ERROR( \ 5208c2ecf20Sopenharmony_ci "ADVANCE_RING(): mismatch: nr: %x write: %x line: %d\n", \ 5218c2ecf20Sopenharmony_ci ((dev_priv->ring.tail + _nr) & tail_mask), \ 5228c2ecf20Sopenharmony_ci write, __LINE__); \ 5238c2ecf20Sopenharmony_ci else \ 5248c2ecf20Sopenharmony_ci dev_priv->ring.tail = write; \ 5258c2ecf20Sopenharmony_ci} while (0) 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci#define COMMIT_RING() do { \ 5288c2ecf20Sopenharmony_ci if (R128_VERBOSE) \ 5298c2ecf20Sopenharmony_ci DRM_INFO("COMMIT_RING() tail=0x%06x\n", \ 5308c2ecf20Sopenharmony_ci dev_priv->ring.tail); \ 5318c2ecf20Sopenharmony_ci mb(); \ 5328c2ecf20Sopenharmony_ci R128_WRITE(R128_PM4_BUFFER_DL_WPTR, dev_priv->ring.tail); \ 5338c2ecf20Sopenharmony_ci R128_READ(R128_PM4_BUFFER_DL_WPTR); \ 5348c2ecf20Sopenharmony_ci} while (0) 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci#define OUT_RING(x) do { \ 5378c2ecf20Sopenharmony_ci if (R128_VERBOSE) \ 5388c2ecf20Sopenharmony_ci DRM_INFO(" OUT_RING( 0x%08x ) at 0x%x\n", \ 5398c2ecf20Sopenharmony_ci (unsigned int)(x), write); \ 5408c2ecf20Sopenharmony_ci ring[write++] = cpu_to_le32(x); \ 5418c2ecf20Sopenharmony_ci write &= tail_mask; \ 5428c2ecf20Sopenharmony_ci} while (0) 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci#endif /* __R128_DRV_H__ */ 545