Home | History | Annotate | Line # | Download | only in savage
      1  1.2  riastrad /*	$NetBSD: savage_drv.h,v 1.3 2021/12/18 23:45:43 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.1  riastrad /* savage_drv.h -- Private header for the savage driver */
      4  1.1  riastrad /*
      5  1.1  riastrad  * Copyright 2004  Felix Kuehling
      6  1.1  riastrad  * All Rights Reserved.
      7  1.1  riastrad  *
      8  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      9  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
     10  1.1  riastrad  * to deal in the Software without restriction, including without limitation
     11  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sub license,
     12  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     13  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     14  1.1  riastrad  *
     15  1.1  riastrad  * The above copyright notice and this permission notice (including the
     16  1.1  riastrad  * next paragraph) shall be included in all copies or substantial portions
     17  1.1  riastrad  * of the Software.
     18  1.1  riastrad  *
     19  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     20  1.1  riastrad  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     21  1.1  riastrad  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     22  1.1  riastrad  * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
     23  1.1  riastrad  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
     24  1.1  riastrad  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     25  1.1  riastrad  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     26  1.1  riastrad  */
     27  1.1  riastrad 
     28  1.1  riastrad #ifndef __SAVAGE_DRV_H__
     29  1.1  riastrad #define __SAVAGE_DRV_H__
     30  1.1  riastrad 
     31  1.3  riastrad #include <linux/io.h>
     32  1.3  riastrad 
     33  1.3  riastrad #include <drm/drm_ioctl.h>
     34  1.2  riastrad #include <drm/drm_legacy.h>
     35  1.3  riastrad #include <drm/savage_drm.h>
     36  1.2  riastrad 
     37  1.1  riastrad #define DRIVER_AUTHOR	"Felix Kuehling"
     38  1.1  riastrad 
     39  1.1  riastrad #define DRIVER_NAME	"savage"
     40  1.1  riastrad #define DRIVER_DESC	"Savage3D/MX/IX, Savage4, SuperSavage, Twister, ProSavage[DDR]"
     41  1.1  riastrad #define DRIVER_DATE	"20050313"
     42  1.1  riastrad 
     43  1.1  riastrad #define DRIVER_MAJOR		2
     44  1.1  riastrad #define DRIVER_MINOR		4
     45  1.1  riastrad #define DRIVER_PATCHLEVEL	1
     46  1.1  riastrad /* Interface history:
     47  1.1  riastrad  *
     48  1.1  riastrad  * 1.x   The DRM driver from the VIA/S3 code drop, basically a dummy
     49  1.1  riastrad  * 2.0   The first real DRM
     50  1.1  riastrad  * 2.1   Scissors registers managed by the DRM, 3D operations clipped by
     51  1.1  riastrad  *       cliprects of the cmdbuf ioctl
     52  1.1  riastrad  * 2.2   Implemented SAVAGE_CMD_DMA_IDX and SAVAGE_CMD_VB_IDX
     53  1.1  riastrad  * 2.3   Event counters used by BCI_EVENT_EMIT/WAIT ioctls are now 32 bits
     54  1.1  riastrad  *       wide and thus very long lived (unlikely to ever wrap). The size
     55  1.1  riastrad  *       in the struct was 32 bits before, but only 16 bits were used
     56  1.1  riastrad  * 2.4   Implemented command DMA. Now drm_savage_init_t.cmd_dma_offset is
     57  1.1  riastrad  *       actually used
     58  1.1  riastrad  */
     59  1.1  riastrad 
     60  1.1  riastrad typedef struct drm_savage_age {
     61  1.1  riastrad 	uint16_t event;
     62  1.1  riastrad 	unsigned int wrap;
     63  1.1  riastrad } drm_savage_age_t;
     64  1.1  riastrad 
     65  1.1  riastrad typedef struct drm_savage_buf_priv {
     66  1.1  riastrad 	struct drm_savage_buf_priv *next;
     67  1.1  riastrad 	struct drm_savage_buf_priv *prev;
     68  1.1  riastrad 	drm_savage_age_t age;
     69  1.1  riastrad 	struct drm_buf *buf;
     70  1.1  riastrad } drm_savage_buf_priv_t;
     71  1.1  riastrad 
     72  1.1  riastrad typedef struct drm_savage_dma_page {
     73  1.1  riastrad 	drm_savage_age_t age;
     74  1.1  riastrad 	unsigned int used, flushed;
     75  1.1  riastrad } drm_savage_dma_page_t;
     76  1.1  riastrad #define SAVAGE_DMA_PAGE_SIZE 1024	/* in dwords */
     77  1.1  riastrad /* Fake DMA buffer size in bytes. 4 pages. Allows a maximum command
     78  1.1  riastrad  * size of 16kbytes or 4k entries. Minimum requirement would be
     79  1.1  riastrad  * 10kbytes for 255 40-byte vertices in one drawing command. */
     80  1.1  riastrad #define SAVAGE_FAKE_DMA_SIZE (SAVAGE_DMA_PAGE_SIZE*4*4)
     81  1.1  riastrad 
     82  1.1  riastrad /* interesting bits of hardware state that are saved in dev_priv */
     83  1.1  riastrad typedef union {
     84  1.1  riastrad 	struct drm_savage_common_state {
     85  1.1  riastrad 		uint32_t vbaddr;
     86  1.1  riastrad 	} common;
     87  1.1  riastrad 	struct {
     88  1.1  riastrad 		unsigned char pad[sizeof(struct drm_savage_common_state)];
     89  1.1  riastrad 		uint32_t texctrl, texaddr;
     90  1.1  riastrad 		uint32_t scstart, new_scstart;
     91  1.1  riastrad 		uint32_t scend, new_scend;
     92  1.1  riastrad 	} s3d;
     93  1.1  riastrad 	struct {
     94  1.1  riastrad 		unsigned char pad[sizeof(struct drm_savage_common_state)];
     95  1.1  riastrad 		uint32_t texdescr, texaddr0, texaddr1;
     96  1.1  riastrad 		uint32_t drawctrl0, new_drawctrl0;
     97  1.1  riastrad 		uint32_t drawctrl1, new_drawctrl1;
     98  1.1  riastrad 	} s4;
     99  1.1  riastrad } drm_savage_state_t;
    100  1.1  riastrad 
    101  1.1  riastrad /* these chip tags should match the ones in the 2D driver in savage_regs.h. */
    102  1.1  riastrad enum savage_family {
    103  1.1  riastrad 	S3_UNKNOWN = 0,
    104  1.1  riastrad 	S3_SAVAGE3D,
    105  1.1  riastrad 	S3_SAVAGE_MX,
    106  1.1  riastrad 	S3_SAVAGE4,
    107  1.1  riastrad 	S3_PROSAVAGE,
    108  1.1  riastrad 	S3_TWISTER,
    109  1.1  riastrad 	S3_PROSAVAGEDDR,
    110  1.1  riastrad 	S3_SUPERSAVAGE,
    111  1.1  riastrad 	S3_SAVAGE2000,
    112  1.1  riastrad 	S3_LAST
    113  1.1  riastrad };
    114  1.1  riastrad 
    115  1.2  riastrad extern const struct drm_ioctl_desc savage_ioctls[];
    116  1.1  riastrad extern int savage_max_ioctl;
    117  1.1  riastrad 
    118  1.1  riastrad #define S3_SAVAGE3D_SERIES(chip)  ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))
    119  1.1  riastrad 
    120  1.1  riastrad #define S3_SAVAGE4_SERIES(chip)  ((chip==S3_SAVAGE4)            \
    121  1.1  riastrad                                   || (chip==S3_PROSAVAGE)       \
    122  1.1  riastrad                                   || (chip==S3_TWISTER)         \
    123  1.1  riastrad                                   || (chip==S3_PROSAVAGEDDR))
    124  1.1  riastrad 
    125  1.1  riastrad #define	S3_SAVAGE_MOBILE_SERIES(chip)	((chip==S3_SAVAGE_MX) || (chip==S3_SUPERSAVAGE))
    126  1.1  riastrad 
    127  1.1  riastrad #define S3_SAVAGE_SERIES(chip)    ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
    128  1.1  riastrad 
    129  1.1  riastrad #define S3_MOBILE_TWISTER_SERIES(chip)   ((chip==S3_TWISTER)    \
    130  1.1  riastrad                                           ||(chip==S3_PROSAVAGEDDR))
    131  1.1  riastrad 
    132  1.1  riastrad /* flags */
    133  1.1  riastrad #define SAVAGE_IS_AGP 1
    134  1.1  riastrad 
    135  1.1  riastrad typedef struct drm_savage_private {
    136  1.1  riastrad 	drm_savage_sarea_t *sarea_priv;
    137  1.1  riastrad 
    138  1.1  riastrad 	drm_savage_buf_priv_t head, tail;
    139  1.1  riastrad 
    140  1.1  riastrad 	/* who am I? */
    141  1.1  riastrad 	enum savage_family chipset;
    142  1.1  riastrad 
    143  1.1  riastrad 	unsigned int cob_size;
    144  1.1  riastrad 	unsigned int bci_threshold_lo, bci_threshold_hi;
    145  1.1  riastrad 	unsigned int dma_type;
    146  1.1  riastrad 
    147  1.1  riastrad 	/* frame buffer layout */
    148  1.1  riastrad 	unsigned int fb_bpp;
    149  1.1  riastrad 	unsigned int front_offset, front_pitch;
    150  1.1  riastrad 	unsigned int back_offset, back_pitch;
    151  1.1  riastrad 	unsigned int depth_bpp;
    152  1.1  riastrad 	unsigned int depth_offset, depth_pitch;
    153  1.1  riastrad 
    154  1.1  riastrad 	/* bitmap descriptors for swap and clear */
    155  1.1  riastrad 	unsigned int front_bd, back_bd, depth_bd;
    156  1.1  riastrad 
    157  1.1  riastrad 	/* local textures */
    158  1.1  riastrad 	unsigned int texture_offset;
    159  1.1  riastrad 	unsigned int texture_size;
    160  1.1  riastrad 
    161  1.1  riastrad 	/* memory regions in physical memory */
    162  1.1  riastrad 	drm_local_map_t *sarea;
    163  1.1  riastrad 	drm_local_map_t *mmio;
    164  1.1  riastrad 	drm_local_map_t *fb;
    165  1.1  riastrad 	drm_local_map_t *aperture;
    166  1.1  riastrad 	drm_local_map_t *status;
    167  1.1  riastrad 	drm_local_map_t *agp_textures;
    168  1.1  riastrad 	drm_local_map_t *cmd_dma;
    169  1.1  riastrad 	drm_local_map_t fake_dma;
    170  1.1  riastrad 
    171  1.2  riastrad 	int mtrr_handles[3];
    172  1.1  riastrad 
    173  1.1  riastrad 	/* BCI and status-related stuff */
    174  1.1  riastrad 	volatile uint32_t *status_ptr, *bci_ptr;
    175  1.1  riastrad 	uint32_t status_used_mask;
    176  1.1  riastrad 	uint16_t event_counter;
    177  1.1  riastrad 	unsigned int event_wrap;
    178  1.1  riastrad 
    179  1.1  riastrad 	/* Savage4 command DMA */
    180  1.1  riastrad 	drm_savage_dma_page_t *dma_pages;
    181  1.1  riastrad 	unsigned int nr_dma_pages, first_dma_page, current_dma_page;
    182  1.1  riastrad 	drm_savage_age_t last_dma_age;
    183  1.1  riastrad 
    184  1.1  riastrad 	/* saved hw state for global/local check on S3D */
    185  1.1  riastrad 	uint32_t hw_draw_ctrl, hw_zbuf_ctrl;
    186  1.1  riastrad 	/* and for scissors (global, so don't emit if not changed) */
    187  1.1  riastrad 	uint32_t hw_scissors_start, hw_scissors_end;
    188  1.1  riastrad 
    189  1.1  riastrad 	drm_savage_state_t state;
    190  1.1  riastrad 
    191  1.1  riastrad 	/* after emitting a wait cmd Savage3D needs 63 nops before next DMA */
    192  1.1  riastrad 	unsigned int waiting;
    193  1.1  riastrad 
    194  1.1  riastrad 	/* config/hardware-dependent function pointers */
    195  1.1  riastrad 	int (*wait_fifo) (struct drm_savage_private * dev_priv, unsigned int n);
    196  1.1  riastrad 	int (*wait_evnt) (struct drm_savage_private * dev_priv, uint16_t e);
    197  1.1  riastrad 	/* Err, there is a macro wait_event in include/linux/wait.h.
    198  1.1  riastrad 	 * Avoid unwanted macro expansion. */
    199  1.1  riastrad 	void (*emit_clip_rect) (struct drm_savage_private * dev_priv,
    200  1.1  riastrad 				const struct drm_clip_rect * pbox);
    201  1.1  riastrad 	void (*dma_flush) (struct drm_savage_private * dev_priv);
    202  1.1  riastrad } drm_savage_private_t;
    203  1.1  riastrad 
    204  1.1  riastrad /* ioctls */
    205  1.1  riastrad extern int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv);
    206  1.1  riastrad extern int savage_bci_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
    207  1.1  riastrad 
    208  1.1  riastrad /* BCI functions */
    209  1.1  riastrad extern uint16_t savage_bci_emit_event(drm_savage_private_t * dev_priv,
    210  1.1  riastrad 				      unsigned int flags);
    211  1.1  riastrad extern void savage_freelist_put(struct drm_device * dev, struct drm_buf * buf);
    212  1.1  riastrad extern void savage_dma_reset(drm_savage_private_t * dev_priv);
    213  1.1  riastrad extern void savage_dma_wait(drm_savage_private_t * dev_priv, unsigned int page);
    214  1.1  riastrad extern uint32_t *savage_dma_alloc(drm_savage_private_t * dev_priv,
    215  1.1  riastrad 				  unsigned int n);
    216  1.1  riastrad extern int savage_driver_load(struct drm_device *dev, unsigned long chipset);
    217  1.1  riastrad extern int savage_driver_firstopen(struct drm_device *dev);
    218  1.1  riastrad extern void savage_driver_lastclose(struct drm_device *dev);
    219  1.3  riastrad extern void savage_driver_unload(struct drm_device *dev);
    220  1.1  riastrad extern void savage_reclaim_buffers(struct drm_device *dev,
    221  1.1  riastrad 				   struct drm_file *file_priv);
    222  1.1  riastrad 
    223  1.1  riastrad /* state functions */
    224  1.1  riastrad extern void savage_emit_clip_rect_s3d(drm_savage_private_t * dev_priv,
    225  1.1  riastrad 				      const struct drm_clip_rect * pbox);
    226  1.1  riastrad extern void savage_emit_clip_rect_s4(drm_savage_private_t * dev_priv,
    227  1.1  riastrad 				     const struct drm_clip_rect * pbox);
    228  1.1  riastrad 
    229  1.1  riastrad #define SAVAGE_FB_SIZE_S3	0x01000000	/*  16MB */
    230  1.1  riastrad #define SAVAGE_FB_SIZE_S4	0x02000000	/*  32MB */
    231  1.1  riastrad #define SAVAGE_MMIO_SIZE        0x00080000	/* 512kB */
    232  1.1  riastrad #define SAVAGE_APERTURE_OFFSET  0x02000000	/*  32MB */
    233  1.1  riastrad #define SAVAGE_APERTURE_SIZE    0x05000000	/* 5 tiled surfaces, 16MB each */
    234  1.1  riastrad 
    235  1.1  riastrad #define SAVAGE_BCI_OFFSET       0x00010000	/* offset of the BCI region
    236  1.1  riastrad 						 * inside the MMIO region */
    237  1.1  riastrad #define SAVAGE_BCI_FIFO_SIZE	32	/* number of entries in on-chip
    238  1.1  riastrad 					 * BCI FIFO */
    239  1.1  riastrad 
    240  1.1  riastrad /*
    241  1.1  riastrad  * MMIO registers
    242  1.1  riastrad  */
    243  1.1  riastrad #define SAVAGE_STATUS_WORD0		0x48C00
    244  1.1  riastrad #define SAVAGE_STATUS_WORD1		0x48C04
    245  1.1  riastrad #define SAVAGE_ALT_STATUS_WORD0 	0x48C60
    246  1.1  riastrad 
    247  1.1  riastrad #define SAVAGE_FIFO_USED_MASK_S3D	0x0001ffff
    248  1.1  riastrad #define SAVAGE_FIFO_USED_MASK_S4	0x001fffff
    249  1.1  riastrad 
    250  1.1  riastrad /* Copied from savage_bci.h in the 2D driver with some renaming. */
    251  1.1  riastrad 
    252  1.1  riastrad /* Bitmap descriptors */
    253  1.1  riastrad #define SAVAGE_BD_STRIDE_SHIFT 0
    254  1.1  riastrad #define SAVAGE_BD_BPP_SHIFT   16
    255  1.1  riastrad #define SAVAGE_BD_TILE_SHIFT  24
    256  1.1  riastrad #define SAVAGE_BD_BW_DISABLE  (1<<28)
    257  1.1  riastrad /* common: */
    258  1.1  riastrad #define	SAVAGE_BD_TILE_LINEAR		0
    259  1.1  riastrad /* savage4, MX, IX, 3D */
    260  1.1  riastrad #define	SAVAGE_BD_TILE_16BPP		2
    261  1.1  riastrad #define	SAVAGE_BD_TILE_32BPP		3
    262  1.1  riastrad /* twister, prosavage, DDR, supersavage, 2000 */
    263  1.1  riastrad #define	SAVAGE_BD_TILE_DEST		1
    264  1.1  riastrad #define	SAVAGE_BD_TILE_TEXTURE		2
    265  1.1  riastrad /* GBD - BCI enable */
    266  1.1  riastrad /* savage4, MX, IX, 3D */
    267  1.1  riastrad #define SAVAGE_GBD_BCI_ENABLE                    8
    268  1.1  riastrad /* twister, prosavage, DDR, supersavage, 2000 */
    269  1.1  riastrad #define SAVAGE_GBD_BCI_ENABLE_TWISTER            0
    270  1.1  riastrad 
    271  1.1  riastrad #define SAVAGE_GBD_BIG_ENDIAN                    4
    272  1.1  riastrad #define SAVAGE_GBD_LITTLE_ENDIAN                 0
    273  1.1  riastrad #define SAVAGE_GBD_64                            1
    274  1.1  riastrad 
    275  1.1  riastrad /*  Global Bitmap Descriptor */
    276  1.1  riastrad #define SAVAGE_BCI_GLB_BD_LOW             0x8168
    277  1.1  riastrad #define SAVAGE_BCI_GLB_BD_HIGH            0x816C
    278  1.1  riastrad 
    279  1.1  riastrad /*
    280  1.1  riastrad  * BCI registers
    281  1.1  riastrad  */
    282  1.1  riastrad /* Savage4/Twister/ProSavage 3D registers */
    283  1.1  riastrad #define SAVAGE_DRAWLOCALCTRL_S4		0x1e
    284  1.1  riastrad #define SAVAGE_TEXPALADDR_S4		0x1f
    285  1.1  riastrad #define SAVAGE_TEXCTRL0_S4		0x20
    286  1.1  riastrad #define SAVAGE_TEXCTRL1_S4		0x21
    287  1.1  riastrad #define SAVAGE_TEXADDR0_S4		0x22
    288  1.1  riastrad #define SAVAGE_TEXADDR1_S4		0x23
    289  1.1  riastrad #define SAVAGE_TEXBLEND0_S4		0x24
    290  1.1  riastrad #define SAVAGE_TEXBLEND1_S4		0x25
    291  1.1  riastrad #define SAVAGE_TEXXPRCLR_S4		0x26	/* never used */
    292  1.1  riastrad #define SAVAGE_TEXDESCR_S4		0x27
    293  1.1  riastrad #define SAVAGE_FOGTABLE_S4		0x28
    294  1.1  riastrad #define SAVAGE_FOGCTRL_S4		0x30
    295  1.1  riastrad #define SAVAGE_STENCILCTRL_S4		0x31
    296  1.1  riastrad #define SAVAGE_ZBUFCTRL_S4		0x32
    297  1.1  riastrad #define SAVAGE_ZBUFOFF_S4		0x33
    298  1.1  riastrad #define SAVAGE_DESTCTRL_S4		0x34
    299  1.1  riastrad #define SAVAGE_DRAWCTRL0_S4		0x35
    300  1.1  riastrad #define SAVAGE_DRAWCTRL1_S4		0x36
    301  1.1  riastrad #define SAVAGE_ZWATERMARK_S4		0x37
    302  1.1  riastrad #define SAVAGE_DESTTEXRWWATERMARK_S4	0x38
    303  1.1  riastrad #define SAVAGE_TEXBLENDCOLOR_S4		0x39
    304  1.1  riastrad /* Savage3D/MX/IX 3D registers */
    305  1.1  riastrad #define SAVAGE_TEXPALADDR_S3D		0x18
    306  1.1  riastrad #define SAVAGE_TEXXPRCLR_S3D		0x19	/* never used */
    307  1.1  riastrad #define SAVAGE_TEXADDR_S3D		0x1A
    308  1.1  riastrad #define SAVAGE_TEXDESCR_S3D		0x1B
    309  1.1  riastrad #define SAVAGE_TEXCTRL_S3D		0x1C
    310  1.1  riastrad #define SAVAGE_FOGTABLE_S3D		0x20
    311  1.1  riastrad #define SAVAGE_FOGCTRL_S3D		0x30
    312  1.1  riastrad #define SAVAGE_DRAWCTRL_S3D		0x31
    313  1.1  riastrad #define SAVAGE_ZBUFCTRL_S3D		0x32
    314  1.1  riastrad #define SAVAGE_ZBUFOFF_S3D		0x33
    315  1.1  riastrad #define SAVAGE_DESTCTRL_S3D		0x34
    316  1.1  riastrad #define SAVAGE_SCSTART_S3D		0x35
    317  1.1  riastrad #define SAVAGE_SCEND_S3D		0x36
    318  1.1  riastrad #define SAVAGE_ZWATERMARK_S3D		0x37
    319  1.1  riastrad #define SAVAGE_DESTTEXRWWATERMARK_S3D	0x38
    320  1.1  riastrad /* common stuff */
    321  1.1  riastrad #define SAVAGE_VERTBUFADDR		0x3e
    322  1.1  riastrad #define SAVAGE_BITPLANEWTMASK		0xd7
    323  1.1  riastrad #define SAVAGE_DMABUFADDR		0x51
    324  1.1  riastrad 
    325  1.1  riastrad /* texture enable bits (needed for tex addr checking) */
    326  1.1  riastrad #define SAVAGE_TEXCTRL_TEXEN_MASK	0x00010000	/* S3D */
    327  1.1  riastrad #define SAVAGE_TEXDESCR_TEX0EN_MASK	0x02000000	/* S4 */
    328  1.1  riastrad #define SAVAGE_TEXDESCR_TEX1EN_MASK	0x04000000	/* S4 */
    329  1.1  riastrad 
    330  1.1  riastrad /* Global fields in Savage4/Twister/ProSavage 3D registers:
    331  1.1  riastrad  *
    332  1.1  riastrad  * All texture registers and DrawLocalCtrl are local. All other
    333  1.1  riastrad  * registers are global. */
    334  1.1  riastrad 
    335  1.1  riastrad /* Global fields in Savage3D/MX/IX 3D registers:
    336  1.1  riastrad  *
    337  1.1  riastrad  * All texture registers are local. DrawCtrl and ZBufCtrl are
    338  1.1  riastrad  * partially local. All other registers are global.
    339  1.1  riastrad  *
    340  1.1  riastrad  * DrawCtrl global fields: cullMode, alphaTestCmpFunc, alphaTestEn, alphaRefVal
    341  1.1  riastrad  * ZBufCtrl global fields: zCmpFunc, zBufEn
    342  1.1  riastrad  */
    343  1.1  riastrad #define SAVAGE_DRAWCTRL_S3D_GLOBAL	0x03f3c00c
    344  1.1  riastrad #define SAVAGE_ZBUFCTRL_S3D_GLOBAL	0x00000027
    345  1.1  riastrad 
    346  1.1  riastrad /* Masks for scissor bits (drawCtrl[01] on s4, scissorStart/End on s3d)
    347  1.1  riastrad  */
    348  1.1  riastrad #define SAVAGE_SCISSOR_MASK_S4		0x00fff7ff
    349  1.1  riastrad #define SAVAGE_SCISSOR_MASK_S3D		0x07ff07ff
    350  1.1  riastrad 
    351  1.1  riastrad /*
    352  1.1  riastrad  * BCI commands
    353  1.1  riastrad  */
    354  1.1  riastrad #define BCI_CMD_NOP                  0x40000000
    355  1.1  riastrad #define BCI_CMD_RECT                 0x48000000
    356  1.1  riastrad #define BCI_CMD_RECT_XP              0x01000000
    357  1.1  riastrad #define BCI_CMD_RECT_YP              0x02000000
    358  1.1  riastrad #define BCI_CMD_SCANLINE             0x50000000
    359  1.1  riastrad #define BCI_CMD_LINE                 0x5C000000
    360  1.1  riastrad #define BCI_CMD_LINE_LAST_PIXEL      0x58000000
    361  1.1  riastrad #define BCI_CMD_BYTE_TEXT            0x63000000
    362  1.1  riastrad #define BCI_CMD_NT_BYTE_TEXT         0x67000000
    363  1.1  riastrad #define BCI_CMD_BIT_TEXT             0x6C000000
    364  1.1  riastrad #define BCI_CMD_GET_ROP(cmd)         (((cmd) >> 16) & 0xFF)
    365  1.1  riastrad #define BCI_CMD_SET_ROP(cmd, rop)    ((cmd) |= ((rop & 0xFF) << 16))
    366  1.1  riastrad #define BCI_CMD_SEND_COLOR           0x00008000
    367  1.1  riastrad 
    368  1.1  riastrad #define BCI_CMD_CLIP_NONE            0x00000000
    369  1.1  riastrad #define BCI_CMD_CLIP_CURRENT         0x00002000
    370  1.1  riastrad #define BCI_CMD_CLIP_LR              0x00004000
    371  1.1  riastrad #define BCI_CMD_CLIP_NEW             0x00006000
    372  1.1  riastrad 
    373  1.1  riastrad #define BCI_CMD_DEST_GBD             0x00000000
    374  1.1  riastrad #define BCI_CMD_DEST_PBD             0x00000800
    375  1.1  riastrad #define BCI_CMD_DEST_PBD_NEW         0x00000C00
    376  1.1  riastrad #define BCI_CMD_DEST_SBD             0x00001000
    377  1.1  riastrad #define BCI_CMD_DEST_SBD_NEW         0x00001400
    378  1.1  riastrad 
    379  1.1  riastrad #define BCI_CMD_SRC_TRANSPARENT      0x00000200
    380  1.1  riastrad #define BCI_CMD_SRC_SOLID            0x00000000
    381  1.1  riastrad #define BCI_CMD_SRC_GBD              0x00000020
    382  1.1  riastrad #define BCI_CMD_SRC_COLOR            0x00000040
    383  1.1  riastrad #define BCI_CMD_SRC_MONO             0x00000060
    384  1.1  riastrad #define BCI_CMD_SRC_PBD_COLOR        0x00000080
    385  1.1  riastrad #define BCI_CMD_SRC_PBD_MONO         0x000000A0
    386  1.1  riastrad #define BCI_CMD_SRC_PBD_COLOR_NEW    0x000000C0
    387  1.1  riastrad #define BCI_CMD_SRC_PBD_MONO_NEW     0x000000E0
    388  1.1  riastrad #define BCI_CMD_SRC_SBD_COLOR        0x00000100
    389  1.1  riastrad #define BCI_CMD_SRC_SBD_MONO         0x00000120
    390  1.1  riastrad #define BCI_CMD_SRC_SBD_COLOR_NEW    0x00000140
    391  1.1  riastrad #define BCI_CMD_SRC_SBD_MONO_NEW     0x00000160
    392  1.1  riastrad 
    393  1.1  riastrad #define BCI_CMD_PAT_TRANSPARENT      0x00000010
    394  1.1  riastrad #define BCI_CMD_PAT_NONE             0x00000000
    395  1.1  riastrad #define BCI_CMD_PAT_COLOR            0x00000002
    396  1.1  riastrad #define BCI_CMD_PAT_MONO             0x00000003
    397  1.1  riastrad #define BCI_CMD_PAT_PBD_COLOR        0x00000004
    398  1.1  riastrad #define BCI_CMD_PAT_PBD_MONO         0x00000005
    399  1.1  riastrad #define BCI_CMD_PAT_PBD_COLOR_NEW    0x00000006
    400  1.1  riastrad #define BCI_CMD_PAT_PBD_MONO_NEW     0x00000007
    401  1.1  riastrad #define BCI_CMD_PAT_SBD_COLOR        0x00000008
    402  1.1  riastrad #define BCI_CMD_PAT_SBD_MONO         0x00000009
    403  1.1  riastrad #define BCI_CMD_PAT_SBD_COLOR_NEW    0x0000000A
    404  1.1  riastrad #define BCI_CMD_PAT_SBD_MONO_NEW     0x0000000B
    405  1.1  riastrad 
    406  1.1  riastrad #define BCI_BD_BW_DISABLE            0x10000000
    407  1.1  riastrad #define BCI_BD_TILE_MASK             0x03000000
    408  1.1  riastrad #define BCI_BD_TILE_NONE             0x00000000
    409  1.1  riastrad #define BCI_BD_TILE_16               0x02000000
    410  1.1  riastrad #define BCI_BD_TILE_32               0x03000000
    411  1.1  riastrad #define BCI_BD_GET_BPP(bd)           (((bd) >> 16) & 0xFF)
    412  1.1  riastrad #define BCI_BD_SET_BPP(bd, bpp)      ((bd) |= (((bpp) & 0xFF) << 16))
    413  1.1  riastrad #define BCI_BD_GET_STRIDE(bd)        ((bd) & 0xFFFF)
    414  1.1  riastrad #define BCI_BD_SET_STRIDE(bd, st)    ((bd) |= ((st) & 0xFFFF))
    415  1.1  riastrad 
    416  1.1  riastrad #define BCI_CMD_SET_REGISTER            0x96000000
    417  1.1  riastrad 
    418  1.1  riastrad #define BCI_CMD_WAIT                    0xC0000000
    419  1.1  riastrad #define BCI_CMD_WAIT_3D                 0x00010000
    420  1.1  riastrad #define BCI_CMD_WAIT_2D                 0x00020000
    421  1.1  riastrad 
    422  1.1  riastrad #define BCI_CMD_UPDATE_EVENT_TAG        0x98000000
    423  1.1  riastrad 
    424  1.1  riastrad #define BCI_CMD_DRAW_PRIM               0x80000000
    425  1.1  riastrad #define BCI_CMD_DRAW_INDEXED_PRIM       0x88000000
    426  1.1  riastrad #define BCI_CMD_DRAW_CONT               0x01000000
    427  1.1  riastrad #define BCI_CMD_DRAW_TRILIST            0x00000000
    428  1.1  riastrad #define BCI_CMD_DRAW_TRISTRIP           0x02000000
    429  1.1  riastrad #define BCI_CMD_DRAW_TRIFAN             0x04000000
    430  1.1  riastrad #define BCI_CMD_DRAW_SKIPFLAGS          0x000000ff
    431  1.1  riastrad #define BCI_CMD_DRAW_NO_Z		0x00000001
    432  1.1  riastrad #define BCI_CMD_DRAW_NO_W		0x00000002
    433  1.1  riastrad #define BCI_CMD_DRAW_NO_CD		0x00000004
    434  1.1  riastrad #define BCI_CMD_DRAW_NO_CS		0x00000008
    435  1.1  riastrad #define BCI_CMD_DRAW_NO_U0		0x00000010
    436  1.1  riastrad #define BCI_CMD_DRAW_NO_V0		0x00000020
    437  1.1  riastrad #define BCI_CMD_DRAW_NO_UV0		0x00000030
    438  1.1  riastrad #define BCI_CMD_DRAW_NO_U1		0x00000040
    439  1.1  riastrad #define BCI_CMD_DRAW_NO_V1		0x00000080
    440  1.1  riastrad #define BCI_CMD_DRAW_NO_UV1		0x000000c0
    441  1.1  riastrad 
    442  1.1  riastrad #define BCI_CMD_DMA			0xa8000000
    443  1.1  riastrad 
    444  1.1  riastrad #define BCI_W_H(w, h)                ((((h) << 16) | (w)) & 0x0FFF0FFF)
    445  1.1  riastrad #define BCI_X_Y(x, y)                ((((y) << 16) | (x)) & 0x0FFF0FFF)
    446  1.1  riastrad #define BCI_X_W(x, y)                ((((w) << 16) | (x)) & 0x0FFF0FFF)
    447  1.1  riastrad #define BCI_CLIP_LR(l, r)            ((((r) << 16) | (l)) & 0x0FFF0FFF)
    448  1.1  riastrad #define BCI_CLIP_TL(t, l)            ((((t) << 16) | (l)) & 0x0FFF0FFF)
    449  1.1  riastrad #define BCI_CLIP_BR(b, r)            ((((b) << 16) | (r)) & 0x0FFF0FFF)
    450  1.1  riastrad 
    451  1.1  riastrad #define BCI_LINE_X_Y(x, y)           (((y) << 16) | ((x) & 0xFFFF))
    452  1.1  riastrad #define BCI_LINE_STEPS(diag, axi)    (((axi) << 16) | ((diag) & 0xFFFF))
    453  1.1  riastrad #define BCI_LINE_MISC(maj, ym, xp, yp, err) \
    454  1.1  riastrad 	(((maj) & 0x1FFF) | \
    455  1.1  riastrad 	((ym) ? 1<<13 : 0) | \
    456  1.1  riastrad 	((xp) ? 1<<14 : 0) | \
    457  1.1  riastrad 	((yp) ? 1<<15 : 0) | \
    458  1.1  riastrad 	((err) << 16))
    459  1.1  riastrad 
    460  1.1  riastrad /*
    461  1.1  riastrad  * common commands
    462  1.1  riastrad  */
    463  1.1  riastrad #define BCI_SET_REGISTERS( first, n )			\
    464  1.1  riastrad 	BCI_WRITE(BCI_CMD_SET_REGISTER |		\
    465  1.1  riastrad 		  ((uint32_t)(n) & 0xff) << 16 |	\
    466  1.1  riastrad 		  ((uint32_t)(first) & 0xffff))
    467  1.1  riastrad #define DMA_SET_REGISTERS( first, n )			\
    468  1.1  riastrad 	DMA_WRITE(BCI_CMD_SET_REGISTER |		\
    469  1.1  riastrad 		  ((uint32_t)(n) & 0xff) << 16 |	\
    470  1.1  riastrad 		  ((uint32_t)(first) & 0xffff))
    471  1.1  riastrad 
    472  1.1  riastrad #define BCI_DRAW_PRIMITIVE(n, type, skip)         \
    473  1.1  riastrad         BCI_WRITE(BCI_CMD_DRAW_PRIM | (type) | (skip) | \
    474  1.1  riastrad 		  ((n) << 16))
    475  1.1  riastrad #define DMA_DRAW_PRIMITIVE(n, type, skip)         \
    476  1.1  riastrad         DMA_WRITE(BCI_CMD_DRAW_PRIM | (type) | (skip) | \
    477  1.1  riastrad 		  ((n) << 16))
    478  1.1  riastrad 
    479  1.1  riastrad #define BCI_DRAW_INDICES_S3D(n, type, i0)         \
    480  1.1  riastrad         BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) |  \
    481  1.1  riastrad 		  ((n) << 16) | (i0))
    482  1.1  riastrad 
    483  1.1  riastrad #define BCI_DRAW_INDICES_S4(n, type, skip)        \
    484  1.1  riastrad         BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) |  \
    485  1.1  riastrad                   (skip) | ((n) << 16))
    486  1.1  riastrad 
    487  1.1  riastrad #define BCI_DMA(n)	\
    488  1.1  riastrad 	BCI_WRITE(BCI_CMD_DMA | (((n) >> 1) - 1))
    489  1.1  riastrad 
    490  1.1  riastrad /*
    491  1.1  riastrad  * access to MMIO
    492  1.1  riastrad  */
    493  1.3  riastrad #define SAVAGE_READ(reg) \
    494  1.3  riastrad        readl(((void __iomem *)dev_priv->mmio->handle) + (reg))
    495  1.3  riastrad #define SAVAGE_WRITE(reg) \
    496  1.3  riastrad 	writel(val, ((void __iomem *)dev_priv->mmio->handle) + (reg))
    497  1.1  riastrad 
    498  1.1  riastrad /*
    499  1.1  riastrad  * access to the burst command interface (BCI)
    500  1.1  riastrad  */
    501  1.1  riastrad #define SAVAGE_BCI_DEBUG 1
    502  1.1  riastrad 
    503  1.1  riastrad #define BCI_LOCALS    volatile uint32_t *bci_ptr;
    504  1.1  riastrad 
    505  1.1  riastrad #define BEGIN_BCI( n ) do {			\
    506  1.1  riastrad 	dev_priv->wait_fifo(dev_priv, (n));	\
    507  1.1  riastrad 	bci_ptr = dev_priv->bci_ptr;		\
    508  1.1  riastrad } while(0)
    509  1.1  riastrad 
    510  1.1  riastrad #define BCI_WRITE( val ) *bci_ptr++ = (uint32_t)(val)
    511  1.1  riastrad 
    512  1.1  riastrad /*
    513  1.1  riastrad  * command DMA support
    514  1.1  riastrad  */
    515  1.1  riastrad #define SAVAGE_DMA_DEBUG 1
    516  1.1  riastrad 
    517  1.1  riastrad #define DMA_LOCALS   uint32_t *dma_ptr;
    518  1.1  riastrad 
    519  1.1  riastrad #define BEGIN_DMA( n ) do {						\
    520  1.1  riastrad 	unsigned int cur = dev_priv->current_dma_page;			\
    521  1.1  riastrad 	unsigned int rest = SAVAGE_DMA_PAGE_SIZE -			\
    522  1.1  riastrad 		dev_priv->dma_pages[cur].used;				\
    523  1.1  riastrad 	if ((n) > rest) {						\
    524  1.1  riastrad 		dma_ptr = savage_dma_alloc(dev_priv, (n));		\
    525  1.1  riastrad 	} else { /* fast path for small allocations */			\
    526  1.1  riastrad 		dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle +	\
    527  1.1  riastrad 			cur * SAVAGE_DMA_PAGE_SIZE +			\
    528  1.1  riastrad 			dev_priv->dma_pages[cur].used;			\
    529  1.1  riastrad 		if (dev_priv->dma_pages[cur].used == 0)			\
    530  1.1  riastrad 			savage_dma_wait(dev_priv, cur);			\
    531  1.1  riastrad 		dev_priv->dma_pages[cur].used += (n);			\
    532  1.1  riastrad 	}								\
    533  1.1  riastrad } while(0)
    534  1.1  riastrad 
    535  1.1  riastrad #define DMA_WRITE( val ) *dma_ptr++ = (uint32_t)(val)
    536  1.1  riastrad 
    537  1.1  riastrad #define DMA_COPY(src, n) do {					\
    538  1.1  riastrad 	memcpy(dma_ptr, (src), (n)*4);				\
    539  1.1  riastrad 	dma_ptr += n;						\
    540  1.1  riastrad } while(0)
    541  1.1  riastrad 
    542  1.1  riastrad #if SAVAGE_DMA_DEBUG
    543  1.1  riastrad #define DMA_COMMIT() do {						\
    544  1.1  riastrad 	unsigned int cur = dev_priv->current_dma_page;			\
    545  1.1  riastrad 	uint32_t *expected = (uint32_t *)dev_priv->cmd_dma->handle +	\
    546  1.1  riastrad 			cur * SAVAGE_DMA_PAGE_SIZE +			\
    547  1.1  riastrad 			dev_priv->dma_pages[cur].used;			\
    548  1.1  riastrad 	if (dma_ptr != expected) {					\
    549  1.1  riastrad 		DRM_ERROR("DMA allocation and use don't match: "	\
    550  1.1  riastrad 			  "%p != %p\n", expected, dma_ptr);		\
    551  1.1  riastrad 		savage_dma_reset(dev_priv);				\
    552  1.1  riastrad 	}								\
    553  1.1  riastrad } while(0)
    554  1.1  riastrad #else
    555  1.1  riastrad #define DMA_COMMIT() do {/* nothing */} while(0)
    556  1.1  riastrad #endif
    557  1.1  riastrad 
    558  1.1  riastrad #define DMA_FLUSH() dev_priv->dma_flush(dev_priv)
    559  1.1  riastrad 
    560  1.1  riastrad /* Buffer aging via event tag
    561  1.1  riastrad  */
    562  1.1  riastrad 
    563  1.1  riastrad #define UPDATE_EVENT_COUNTER( ) do {			\
    564  1.1  riastrad 	if (dev_priv->status_ptr) {			\
    565  1.1  riastrad 		uint16_t count;				\
    566  1.1  riastrad 		/* coordinate with Xserver */		\
    567  1.1  riastrad 		count = dev_priv->status_ptr[1023];	\
    568  1.1  riastrad 		if (count < dev_priv->event_counter)	\
    569  1.1  riastrad 			dev_priv->event_wrap++;		\
    570  1.1  riastrad 		dev_priv->event_counter = count;	\
    571  1.1  riastrad 	}						\
    572  1.1  riastrad } while(0)
    573  1.1  riastrad 
    574  1.1  riastrad #define SET_AGE( age, e, w ) do {	\
    575  1.1  riastrad 	(age)->event = e;		\
    576  1.1  riastrad 	(age)->wrap = w;		\
    577  1.1  riastrad } while(0)
    578  1.1  riastrad 
    579  1.1  riastrad #define TEST_AGE( age, e, w )				\
    580  1.1  riastrad 	( (age)->wrap < (w) || ( (age)->wrap == (w) && (age)->event <= (e) ) )
    581  1.1  riastrad 
    582  1.1  riastrad #endif				/* __SAVAGE_DRV_H__ */
    583