ffb_accel_common.c revision dda79b8e
1/* $NetBSD: ffb_accel_common.c,v 1.3 2016/08/22 08:28:32 mrg Exp $ */
2/*
3 * Copyright (C) 1998,1999,2000 Jakub Jelinek (jakub@redhat.com)
4 * Copyright (C) 1998 Michal Rehacek (majkl@iname.com)
5 * Copyright (C) 1999,2000 David S. Miller (davem@redhat.com)
6 * Copyright (C) 2015 Michael Lorenz (macallan@netbsd.org)
7  *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the 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 * JAKUB JELINEK, MICHAL REHACEK, OR DAVID MILLER BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29#include <sys/types.h>
30
31#ifdef HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include "ffb_fifo.h"
36#include "ffb_rcache.h"
37#include "ffb.h"
38#include "ffb_regs.h"
39
40/* all driver need this */
41#include "xf86.h"
42#include "xf86_OSproc.h"
43#include "compiler.h"
44#include "exa.h"
45
46void FFB_SetupTextureAttrs(FFBPtr pFfb)
47{
48       ffb_fbcPtr ffb = pFfb->regs;
49       unsigned int ppc = FFB_PPC_APE_DISABLE | FFB_PPC_CS_VAR | FFB_PPC_XS_VAR;
50       unsigned int ppc_mask = FFB_PPC_APE_MASK | FFB_PPC_CS_MASK | FFB_PPC_XS_MASK;
51       unsigned int rop = FFB_ROP_NEW | (FFB_ROP_NEW << 8);
52       unsigned int fbc = pFfb->fbc;
53       unsigned int wid = pFfb->wid;
54
55       ppc |= FFB_PPC_ABE_ENABLE;
56       ppc_mask |= FFB_PPC_ABE_MASK;
57
58       if ((pFfb->ppc_cache & ppc_mask) != ppc ||
59           pFfb->fbc_cache != fbc ||
60           pFfb->wid_cache != wid ||
61           pFfb->rop_cache != rop ||
62           pFfb->pmask_cache != 0xffffffff)
63               __FFB_Attr_SFB_VAR(pFfb, ppc, ppc_mask, fbc,
64                                  wid, rop, 0xffffffff);
65       FFBWait(pFfb, ffb);
66}
67
68void FFB_HardwareSetup(FFBPtr pFfb)
69{
70       ffb_fbcPtr ffb = pFfb->regs;
71
72	/* Determine the current screen resolution type.  This is
73	 * needed to figure out the fastfill/pagefill parameters.
74	 */
75	switch(ffb->fbcfg0 & FFB_FBCFG0_RES_MASK) {
76	default:
77	case FFB_FBCFG0_RES_STD:
78		pFfb->ffb_res = ffb_res_standard;
79		break;
80	case FFB_FBCFG0_RES_HIGH:
81		pFfb->ffb_res = ffb_res_high;
82		break;
83	case FFB_FBCFG0_RES_STEREO:
84		pFfb->ffb_res = ffb_res_stereo;
85		break;
86	case FFB_FBCFG0_RES_PRTRAIT:
87		pFfb->ffb_res = ffb_res_portrait;
88		break;
89	};
90	CreatorAlignTabInit(pFfb);
91
92	/* Next, determine the hwbug workarounds and feature enables
93	 * we should be using on this board.
94	 */
95	pFfb->disable_pagefill = 0;
96	pFfb->disable_vscroll = 0;
97	pFfb->has_brline_bug = 0;
98	pFfb->use_blkread_prefetch = 0;
99	if (pFfb->ffb_type == ffb1_prototype ||
100	    pFfb->ffb_type == ffb1_standard ||
101	    pFfb->ffb_type == ffb1_speedsort) {
102		pFfb->has_brline_bug = 1;
103		if (pFfb->ffb_res == ffb_res_high)
104			pFfb->disable_vscroll = 1;
105		if (pFfb->ffb_res == ffb_res_high ||
106		    pFfb->ffb_res == ffb_res_stereo)
107			pFfb->disable_pagefill = 1;
108
109	} else {
110		/* FFB2 has blkread prefetch.  AFB supposedly does too
111		 * but the chip locks up on me when I try to use it. -DaveM
112		 */
113#define AFB_PREFETCH_IS_BUGGY	1
114		if (!AFB_PREFETCH_IS_BUGGY ||
115		    (pFfb->ffb_type != afb_m3 &&
116		     pFfb->ffb_type != afb_m6)) {
117			pFfb->use_blkread_prefetch = 1;
118		}
119		/* XXX I still cannot get page/block fast fills
120		 * XXX to work reliably on any of my AFB boards. -DaveM
121		 */
122#define AFB_FASTFILL_IS_BUGGY	1
123		if (AFB_FASTFILL_IS_BUGGY &&
124		    (pFfb->ffb_type == afb_m3 ||
125		     pFfb->ffb_type == afb_m6))
126			pFfb->disable_pagefill = 1;
127	}
128	pFfb->disable_fastfill_ap = 0;
129	if (pFfb->ffb_res == ffb_res_stereo ||
130	    pFfb->ffb_res == ffb_res_high)
131		pFfb->disable_fastfill_ap = 1;
132}
133
134/* Multiplies and divides suck... */
135void CreatorAlignTabInit(FFBPtr pFfb)
136{
137	struct fastfill_parms *ffp = &FFB_FFPARMS(pFfb);
138	short *tab = pFfb->Pf_AlignTab;
139	int i;
140
141	for(i = 0; i < 0x800; i++) {
142		int alignval;
143
144		alignval = (i / ffp->pagefill_width) * ffp->pagefill_width;
145		*tab++ = alignval;
146	}
147}
148
149