18c2ecf20Sopenharmony_ci/* i810_drv.h -- Private header for the Matrox g200/g400 driver -*- linux-c -*-
28c2ecf20Sopenharmony_ci * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
58c2ecf20Sopenharmony_ci * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
68c2ecf20Sopenharmony_ci * All rights reserved.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
98c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
108c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
118c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
128c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
138c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next
168c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
178c2ecf20Sopenharmony_ci * Software.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
208c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
218c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
228c2ecf20Sopenharmony_ci * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
238c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
248c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
258c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
288c2ecf20Sopenharmony_ci *	    Jeff Hartmann <jhartmann@valinux.com>
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#ifndef _I810_DRV_H_
338c2ecf20Sopenharmony_ci#define _I810_DRV_H_
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include <drm/drm_ioctl.h>
368c2ecf20Sopenharmony_ci#include <drm/drm_legacy.h>
378c2ecf20Sopenharmony_ci#include <drm/i810_drm.h>
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* General customization:
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define DRIVER_AUTHOR		"VA Linux Systems Inc."
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define DRIVER_NAME		"i810"
458c2ecf20Sopenharmony_ci#define DRIVER_DESC		"Intel i810"
468c2ecf20Sopenharmony_ci#define DRIVER_DATE		"20030605"
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* Interface history
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * 1.1   - XFree86 4.1
518c2ecf20Sopenharmony_ci * 1.2   - XvMC interfaces
528c2ecf20Sopenharmony_ci *       - XFree86 4.2
538c2ecf20Sopenharmony_ci * 1.2.1 - Disable copying code (leave stub ioctls for backwards compatibility)
548c2ecf20Sopenharmony_ci *       - Remove requirement for interrupt (leave stubs again)
558c2ecf20Sopenharmony_ci * 1.3   - Add page flipping.
568c2ecf20Sopenharmony_ci * 1.4   - fix DRM interface
578c2ecf20Sopenharmony_ci */
588c2ecf20Sopenharmony_ci#define DRIVER_MAJOR		1
598c2ecf20Sopenharmony_ci#define DRIVER_MINOR		4
608c2ecf20Sopenharmony_ci#define DRIVER_PATCHLEVEL	0
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_citypedef struct drm_i810_buf_priv {
638c2ecf20Sopenharmony_ci	u32 *in_use;
648c2ecf20Sopenharmony_ci	int my_use_idx;
658c2ecf20Sopenharmony_ci	int currently_mapped;
668c2ecf20Sopenharmony_ci	void *virtual;
678c2ecf20Sopenharmony_ci	void *kernel_virtual;
688c2ecf20Sopenharmony_ci	drm_local_map_t map;
698c2ecf20Sopenharmony_ci} drm_i810_buf_priv_t;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_citypedef struct _drm_i810_ring_buffer {
728c2ecf20Sopenharmony_ci	int tail_mask;
738c2ecf20Sopenharmony_ci	unsigned long Start;
748c2ecf20Sopenharmony_ci	unsigned long End;
758c2ecf20Sopenharmony_ci	unsigned long Size;
768c2ecf20Sopenharmony_ci	u8 *virtual_start;
778c2ecf20Sopenharmony_ci	int head;
788c2ecf20Sopenharmony_ci	int tail;
798c2ecf20Sopenharmony_ci	int space;
808c2ecf20Sopenharmony_ci	drm_local_map_t map;
818c2ecf20Sopenharmony_ci} drm_i810_ring_buffer_t;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_citypedef struct drm_i810_private {
848c2ecf20Sopenharmony_ci	struct drm_local_map *sarea_map;
858c2ecf20Sopenharmony_ci	struct drm_local_map *mmio_map;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	drm_i810_sarea_t *sarea_priv;
888c2ecf20Sopenharmony_ci	drm_i810_ring_buffer_t ring;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	void *hw_status_page;
918c2ecf20Sopenharmony_ci	unsigned long counter;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	dma_addr_t dma_status_page;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	struct drm_buf *mmap_buffer;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	u32 front_di1, back_di1, zi1;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	int back_offset;
1008c2ecf20Sopenharmony_ci	int depth_offset;
1018c2ecf20Sopenharmony_ci	int overlay_offset;
1028c2ecf20Sopenharmony_ci	int overlay_physical;
1038c2ecf20Sopenharmony_ci	int w, h;
1048c2ecf20Sopenharmony_ci	int pitch;
1058c2ecf20Sopenharmony_ci	int back_pitch;
1068c2ecf20Sopenharmony_ci	int depth_pitch;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	int do_boxes;
1098c2ecf20Sopenharmony_ci	int dma_used;
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	int current_page;
1128c2ecf20Sopenharmony_ci	int page_flipping;
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	wait_queue_head_t irq_queue;
1158c2ecf20Sopenharmony_ci	atomic_t irq_received;
1168c2ecf20Sopenharmony_ci	atomic_t irq_emitted;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	int front_offset;
1198c2ecf20Sopenharmony_ci} drm_i810_private_t;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci				/* i810_dma.c */
1228c2ecf20Sopenharmony_ciextern int i810_driver_dma_quiescent(struct drm_device *dev);
1238c2ecf20Sopenharmony_civoid i810_driver_reclaim_buffers(struct drm_device *dev,
1248c2ecf20Sopenharmony_ci			         struct drm_file *file_priv);
1258c2ecf20Sopenharmony_ciextern int i810_driver_load(struct drm_device *, unsigned long flags);
1268c2ecf20Sopenharmony_ciextern void i810_driver_lastclose(struct drm_device *dev);
1278c2ecf20Sopenharmony_ciextern void i810_driver_preclose(struct drm_device *dev,
1288c2ecf20Sopenharmony_ci				 struct drm_file *file_priv);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ciextern long i810_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1318c2ecf20Sopenharmony_ciextern const struct drm_ioctl_desc i810_ioctls[];
1328c2ecf20Sopenharmony_ciextern int i810_max_ioctl;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#define I810_BASE(reg)		((unsigned long) \
1358c2ecf20Sopenharmony_ci				dev_priv->mmio_map->handle)
1368c2ecf20Sopenharmony_ci#define I810_ADDR(reg)		(I810_BASE(reg) + reg)
1378c2ecf20Sopenharmony_ci#define I810_DEREF(reg)		(*(__volatile__ int *)I810_ADDR(reg))
1388c2ecf20Sopenharmony_ci#define I810_READ(reg)		I810_DEREF(reg)
1398c2ecf20Sopenharmony_ci#define I810_WRITE(reg, val)	do { I810_DEREF(reg) = val; } while (0)
1408c2ecf20Sopenharmony_ci#define I810_DEREF16(reg)	(*(__volatile__ u16 *)I810_ADDR(reg))
1418c2ecf20Sopenharmony_ci#define I810_READ16(reg)	I810_DEREF16(reg)
1428c2ecf20Sopenharmony_ci#define I810_WRITE16(reg, val)	do { I810_DEREF16(reg) = val; } while (0)
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#define I810_VERBOSE 0
1458c2ecf20Sopenharmony_ci#define RING_LOCALS	unsigned int outring, ringmask; \
1468c2ecf20Sopenharmony_ci			volatile char *virt;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#define BEGIN_LP_RING(n) do {					\
1498c2ecf20Sopenharmony_ci	if (I810_VERBOSE)					\
1508c2ecf20Sopenharmony_ci		DRM_DEBUG("BEGIN_LP_RING(%d)\n", n);		\
1518c2ecf20Sopenharmony_ci	if (dev_priv->ring.space < n*4)				\
1528c2ecf20Sopenharmony_ci		i810_wait_ring(dev, n*4);			\
1538c2ecf20Sopenharmony_ci	dev_priv->ring.space -= n*4;				\
1548c2ecf20Sopenharmony_ci	outring = dev_priv->ring.tail;				\
1558c2ecf20Sopenharmony_ci	ringmask = dev_priv->ring.tail_mask;			\
1568c2ecf20Sopenharmony_ci	virt = dev_priv->ring.virtual_start;			\
1578c2ecf20Sopenharmony_ci} while (0)
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci#define ADVANCE_LP_RING() do {					\
1608c2ecf20Sopenharmony_ci	if (I810_VERBOSE)					\
1618c2ecf20Sopenharmony_ci		DRM_DEBUG("ADVANCE_LP_RING\n");			\
1628c2ecf20Sopenharmony_ci	dev_priv->ring.tail = outring;				\
1638c2ecf20Sopenharmony_ci	I810_WRITE(LP_RING + RING_TAIL, outring);		\
1648c2ecf20Sopenharmony_ci} while (0)
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#define OUT_RING(n) do {					\
1678c2ecf20Sopenharmony_ci	if (I810_VERBOSE)					\
1688c2ecf20Sopenharmony_ci		DRM_DEBUG("   OUT_RING %x\n", (int)(n));	\
1698c2ecf20Sopenharmony_ci	*(volatile unsigned int *)(virt + outring) = n;		\
1708c2ecf20Sopenharmony_ci	outring += 4;						\
1718c2ecf20Sopenharmony_ci	outring &= ringmask;					\
1728c2ecf20Sopenharmony_ci} while (0)
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci#define GFX_OP_USER_INTERRUPT		((0<<29)|(2<<23))
1758c2ecf20Sopenharmony_ci#define GFX_OP_BREAKPOINT_INTERRUPT	((0<<29)|(1<<23))
1768c2ecf20Sopenharmony_ci#define CMD_REPORT_HEAD			(7<<23)
1778c2ecf20Sopenharmony_ci#define CMD_STORE_DWORD_IDX		((0x21<<23) | 0x1)
1788c2ecf20Sopenharmony_ci#define CMD_OP_BATCH_BUFFER  ((0x0<<29)|(0x30<<23)|0x1)
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci#define INST_PARSER_CLIENT   0x00000000
1818c2ecf20Sopenharmony_ci#define INST_OP_FLUSH        0x02000000
1828c2ecf20Sopenharmony_ci#define INST_FLUSH_MAP_CACHE 0x00000001
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#define BB1_START_ADDR_MASK   (~0x7)
1858c2ecf20Sopenharmony_ci#define BB1_PROTECTED         (1<<0)
1868c2ecf20Sopenharmony_ci#define BB1_UNPROTECTED       (0<<0)
1878c2ecf20Sopenharmony_ci#define BB2_END_ADDR_MASK     (~0x7)
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci#define I810REG_HWSTAM		0x02098
1908c2ecf20Sopenharmony_ci#define I810REG_INT_IDENTITY_R	0x020a4
1918c2ecf20Sopenharmony_ci#define I810REG_INT_MASK_R	0x020a8
1928c2ecf20Sopenharmony_ci#define I810REG_INT_ENABLE_R	0x020a0
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci#define LP_RING			0x2030
1958c2ecf20Sopenharmony_ci#define HP_RING			0x2040
1968c2ecf20Sopenharmony_ci#define RING_TAIL		0x00
1978c2ecf20Sopenharmony_ci#define TAIL_ADDR		0x000FFFF8
1988c2ecf20Sopenharmony_ci#define RING_HEAD		0x04
1998c2ecf20Sopenharmony_ci#define HEAD_WRAP_COUNT		0xFFE00000
2008c2ecf20Sopenharmony_ci#define HEAD_WRAP_ONE		0x00200000
2018c2ecf20Sopenharmony_ci#define HEAD_ADDR		0x001FFFFC
2028c2ecf20Sopenharmony_ci#define RING_START		0x08
2038c2ecf20Sopenharmony_ci#define START_ADDR		0x00FFFFF8
2048c2ecf20Sopenharmony_ci#define RING_LEN		0x0C
2058c2ecf20Sopenharmony_ci#define RING_NR_PAGES		0x000FF000
2068c2ecf20Sopenharmony_ci#define RING_REPORT_MASK	0x00000006
2078c2ecf20Sopenharmony_ci#define RING_REPORT_64K		0x00000002
2088c2ecf20Sopenharmony_ci#define RING_REPORT_128K	0x00000004
2098c2ecf20Sopenharmony_ci#define RING_NO_REPORT		0x00000000
2108c2ecf20Sopenharmony_ci#define RING_VALID_MASK		0x00000001
2118c2ecf20Sopenharmony_ci#define RING_VALID		0x00000001
2128c2ecf20Sopenharmony_ci#define RING_INVALID		0x00000000
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci#define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
2158c2ecf20Sopenharmony_ci#define SC_UPDATE_SCISSOR       (0x1<<1)
2168c2ecf20Sopenharmony_ci#define SC_ENABLE_MASK          (0x1<<0)
2178c2ecf20Sopenharmony_ci#define SC_ENABLE               (0x1<<0)
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci#define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
2208c2ecf20Sopenharmony_ci#define SCI_YMIN_MASK      (0xffff<<16)
2218c2ecf20Sopenharmony_ci#define SCI_XMIN_MASK      (0xffff<<0)
2228c2ecf20Sopenharmony_ci#define SCI_YMAX_MASK      (0xffff<<16)
2238c2ecf20Sopenharmony_ci#define SCI_XMAX_MASK      (0xffff<<0)
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci#define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
2268c2ecf20Sopenharmony_ci#define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
2278c2ecf20Sopenharmony_ci#define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x2)
2288c2ecf20Sopenharmony_ci#define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
2298c2ecf20Sopenharmony_ci#define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
2308c2ecf20Sopenharmony_ci#define GFX_OP_PRIMITIVE         ((0x3<<29)|(0x1f<<24))
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci#define CMD_OP_Z_BUFFER_INFO     ((0x0<<29)|(0x16<<23))
2338c2ecf20Sopenharmony_ci#define CMD_OP_DESTBUFFER_INFO   ((0x0<<29)|(0x15<<23))
2348c2ecf20Sopenharmony_ci#define CMD_OP_FRONTBUFFER_INFO  ((0x0<<29)|(0x14<<23))
2358c2ecf20Sopenharmony_ci#define CMD_OP_WAIT_FOR_EVENT    ((0x0<<29)|(0x03<<23))
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci#define BR00_BITBLT_CLIENT   0x40000000
2388c2ecf20Sopenharmony_ci#define BR00_OP_COLOR_BLT    0x10000000
2398c2ecf20Sopenharmony_ci#define BR00_OP_SRC_COPY_BLT 0x10C00000
2408c2ecf20Sopenharmony_ci#define BR13_SOLID_PATTERN   0x80000000
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci#define WAIT_FOR_PLANE_A_SCANLINES (1<<1)
2438c2ecf20Sopenharmony_ci#define WAIT_FOR_PLANE_A_FLIP      (1<<2)
2448c2ecf20Sopenharmony_ci#define WAIT_FOR_VBLANK (1<<3)
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci#endif
247