cg14.h revision 698f741c
1/*
2 * CG14 framebuffer - defines.
3 *
4 * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#ifndef CG14_H
25#define CG14_H
26
27#include "xf86.h"
28#include "xf86_OSproc.h"
29#include <X11/Xmd.h>
30#include "gcstruct.h"
31#include "xf86sbusBus.h"
32#include "xf86Cursor.h"
33#include "exa.h"
34#include <sparc/sxreg.h>
35
36/* Various offsets in virtual (ie. mmap()) spaces Linux and Solaris support. */
37#define CG14_REGS_VOFF		0x00000000	/* registers */
38#define CG14_XLUT_VOFF		0x00003000	/* X Look Up Table */
39#define CG14_CLUT1_VOFF		0x00004000	/* Color Look Up Table */
40#define CG14_CLUT2_VOFF		0x00005000	/* Color Look Up Table */
41#define CG14_CLUT3_VOFF		0x00006000	/* Color Look Up Table */
42#define CG14_DIRECT_VOFF	0x10000000
43#define CG14_CTLREG_VOFF	0x20000000
44#define CG14_CURSOR_VOFF	0x30000000
45#define CG14_SHDW_VRT_VOFF	0x40000000
46#define CG14_XBGR_VOFF		0x50000000
47#define CG14_BGR_VOFF		0x60000000
48#define CG14_X16_VOFF		0x70000000
49#define CG14_C16_VOFF		0x80000000
50#define CG14_X32_VOFF		0x90000000
51#define CG14_B32_VOFF		0xa0000000
52#define CG14_G32_VOFF		0xb0000000
53#define CG14_R32_VOFF		0xc0000000
54
55/* these two are NetBSD specific */
56#define CG14_SXREG_VOFF		0x00010000	/* SX userspace registers */
57#define CG14_SXIO_VOFF		0xd0000000
58
59
60/* Hardware cursor map */
61#define CG14_CURS_SIZE		32
62struct cg14curs {
63	volatile uint32_t	curs_plane0[CG14_CURS_SIZE];	/* plane 0 */
64	volatile uint32_t	curs_plane1[CG14_CURS_SIZE];
65	volatile uint8_t	curs_ctl;	/* control register */
66#define CG14_CURS_ENABLE	0x4
67#define CG14_CURS_DOUBLEBUFFER	0x2 		/* use X-channel for curs */
68	volatile uint8_t	pad0[3];
69	volatile uint16_t	curs_x;		/* x position */
70	volatile uint16_t	curs_y;		/* y position */
71	volatile uint32_t	curs_color1;	/* color register 1 */
72	volatile uint32_t	curs_color2;	/* color register 2 */
73	volatile uint32_t	pad[444];	/* pad to 2KB boundary */
74	volatile uint32_t	curs_plane0incr[CG14_CURS_SIZE]; /* autoincr */
75	volatile uint32_t	curs_plane1incr[CG14_CURS_SIZE]; /* autoincr */
76};
77
78typedef struct {
79	unsigned char	*fb;
80	unsigned char	*x32;
81	unsigned char	*xlut;
82	struct cg14curs	*curs;
83	int		width;
84	int		height;
85	int		use_shadow;
86	int		memsize;
87	int		HWCursor;
88	void *		shadow;
89	sbusDevicePtr	psdp;
90	CloseScreenProcPtr CloseScreen;
91	CreateScreenResourcesProcPtr CreateScreenResources;
92	OptionInfoPtr	Options;
93	xf86CursorInfoPtr	CursorInfoRec;
94	/* SX accel stuff */
95	void		*sxreg, *sxio;
96	int		use_accel, use_xrender;
97	uint32_t	last_mask;
98	uint32_t	last_rop;
99	uint32_t	srcoff, srcpitch, mskoff, mskpitch;
100	uint32_t	srcformat, dstformat, mskformat;
101	uint32_t	fillcolour;
102	int		op;
103	Bool		source_is_solid, no_source_pixmap;
104	int		xdir, ydir;
105	int		queuecount;
106	ExaDriverPtr 	pExa;
107} Cg14Rec, *Cg14Ptr;
108
109/* SX stuff */
110/* write an SX register */
111static inline void
112write_sx_reg(Cg14Ptr p, int reg, uint32_t val)
113{
114	*(volatile uint32_t *)(p->sxreg + reg) = val;
115}
116
117/* read an SX register */
118static inline uint32_t
119read_sx_reg(Cg14Ptr p, int reg)
120{
121	return *(volatile uint32_t *)(p->sxreg + reg);
122}
123
124/* write a memory referencing instruction */
125static inline void
126write_sx_io(Cg14Ptr p, int reg, uint32_t val)
127{
128	if (p->queuecount > 6) {
129		/* let the queue drain to avoid stalling the CPU */
130		do { } while
131		    ((read_sx_reg(p, SX_CONTROL_STATUS) & SX_MT) == 0);
132		p->queuecount = 0;
133	}
134	*(volatile uint32_t *)(p->sxio + (reg & ~7)) = val;
135	p->queuecount++;
136}
137
138/* convenience macros to hide the complexity involved with talking to SX */
139
140/*
141 * issue ALU instruction:
142 * sxi(OPCODE, srcA, srcB, dest, count)
143 */
144#define sxi(inst, a, b, d, cnt) write_sx_reg(p, SX_INSTRUCTIONS, inst((a), (b), (d), (cnt)))
145
146/*
147 * issue memory referencing instruction:
148 * sxm(OPCODE, address, start register, count)
149 */
150#define sxm(inst, addr, reg, count) write_sx_io(p, (addr) & ~7, inst((reg), (count), (addr) & 7))
151
152/* hw setup stuff */
153Bool CG14SetupCursor(ScreenPtr);
154Bool CG14InitAccel(ScreenPtr);
155
156/* xrender ops */
157void CG14Comp_Over8Solid(Cg14Ptr, uint32_t, uint32_t, uint32_t, uint32_t,
158                   int, int);
159void CG14Comp_Over32Solid(Cg14Ptr, uint32_t, uint32_t, uint32_t, uint32_t,
160                   int, int);
161void CG14Comp_Over32(Cg14Ptr, uint32_t, uint32_t, uint32_t, uint32_t,
162                   int, int, int);
163void CG14Comp_Over32Mask(Cg14Ptr, uint32_t, uint32_t, uint32_t, uint32_t,
164                   uint32_t, uint32_t, int, int, int);
165void CG14Comp_Over32Mask_noalpha(Cg14Ptr, uint32_t, uint32_t, uint32_t,
166		   uint32_t, uint32_t, uint32_t, int, int, int);
167void CG14Comp_Over32Mask32_noalpha(Cg14Ptr, uint32_t, uint32_t, uint32_t,
168		   uint32_t, uint32_t, uint32_t, int, int, int);
169void CG14Comp_Add8(Cg14Ptr, uint32_t, uint32_t, uint32_t, uint32_t,
170                   int, int);
171void CG14Comp_Add8_32(Cg14Ptr, uint32_t, uint32_t, uint32_t, uint32_t,
172                   int, int);
173void CG14Comp_Add32(Cg14Ptr, uint32_t, uint32_t, uint32_t, uint32_t,
174                   int, int);
175
176#define GET_CG14_FROM_SCRN(p)    ((Cg14Ptr)((p)->driverPrivate))
177
178/*
179 * This should match corresponding definition in Solaris's
180 * '/usr/include/sys/cg14io.h'.
181 */
182#ifdef __NetBSD__
183#include <dev/sun/fbio.h>
184#include <sys/ioccom.h>
185#define CG14_SET_PIXELMODE	_IOW('M', 3, int)
186#else
187#define CG14_SET_PIXELMODE	(('M' << 8) | 3)
188#endif
189
190#endif /* CG14_H */
191