ffb_accel_common.c revision 504f16bc
1/* $NetBSD: ffb_accel_common.c,v 1.1 2015/08/16 17:47:39 macallan 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/* all driver need this */
32#include "xf86.h"
33#include "xf86_OSproc.h"
34#include "compiler.h"
35#include "exa.h"
36
37#include "ffb_fifo.h"
38#include "ffb_rcache.h"
39#include "ffb.h"
40#include "ffb_regs.h"
41
42void FFB_SetupTextureAttrs(FFBPtr pFfb)
43{
44       ffb_fbcPtr ffb = pFfb->regs;
45       unsigned int ppc = FFB_PPC_APE_DISABLE | FFB_PPC_CS_VAR | FFB_PPC_XS_VAR;
46       unsigned int ppc_mask = FFB_PPC_APE_MASK | FFB_PPC_CS_MASK | FFB_PPC_XS_MASK;
47       unsigned int rop = FFB_ROP_NEW | (FFB_ROP_NEW << 8);
48       unsigned int fbc = pFfb->fbc;
49       unsigned int wid = pFfb->wid;
50
51       ppc |= FFB_PPC_ABE_ENABLE;
52       ppc_mask |= FFB_PPC_ABE_MASK;
53
54       if ((pFfb->ppc_cache & ppc_mask) != ppc ||
55           pFfb->fbc_cache != fbc ||
56           pFfb->wid_cache != wid ||
57           pFfb->rop_cache != rop ||
58           pFfb->pmask_cache != 0xffffffff)
59               __FFB_Attr_SFB_VAR(pFfb, ppc, ppc_mask, fbc,
60                                  wid, rop, 0xffffffff);
61       FFBWait(pFfb, ffb);
62}
63
64void FFB_HardwareSetup(FFBPtr pFfb)
65{
66       ffb_fbcPtr ffb = pFfb->regs;
67
68	/* Determine the current screen resolution type.  This is
69	 * needed to figure out the fastfill/pagefill parameters.
70	 */
71	switch(ffb->fbcfg0 & FFB_FBCFG0_RES_MASK) {
72	default:
73	case FFB_FBCFG0_RES_STD:
74		pFfb->ffb_res = ffb_res_standard;
75		break;
76	case FFB_FBCFG0_RES_HIGH:
77		pFfb->ffb_res = ffb_res_high;
78		break;
79	case FFB_FBCFG0_RES_STEREO:
80		pFfb->ffb_res = ffb_res_stereo;
81		break;
82	case FFB_FBCFG0_RES_PRTRAIT:
83		pFfb->ffb_res = ffb_res_portrait;
84		break;
85	};
86	CreatorAlignTabInit(pFfb);
87
88	/* Next, determine the hwbug workarounds and feature enables
89	 * we should be using on this board.
90	 */
91	pFfb->disable_pagefill = 0;
92	pFfb->disable_vscroll = 0;
93	pFfb->has_brline_bug = 0;
94	pFfb->use_blkread_prefetch = 0;
95	if (pFfb->ffb_type == ffb1_prototype ||
96	    pFfb->ffb_type == ffb1_standard ||
97	    pFfb->ffb_type == ffb1_speedsort) {
98		pFfb->has_brline_bug = 1;
99		if (pFfb->ffb_res == ffb_res_high)
100			pFfb->disable_vscroll = 1;
101		if (pFfb->ffb_res == ffb_res_high ||
102		    pFfb->ffb_res == ffb_res_stereo)
103			pFfb->disable_pagefill = 1;
104
105	} else {
106		/* FFB2 has blkread prefetch.  AFB supposedly does too
107		 * but the chip locks up on me when I try to use it. -DaveM
108		 */
109#define AFB_PREFETCH_IS_BUGGY	1
110		if (!AFB_PREFETCH_IS_BUGGY ||
111		    (pFfb->ffb_type != afb_m3 &&
112		     pFfb->ffb_type != afb_m6)) {
113			pFfb->use_blkread_prefetch = 1;
114		}
115		/* XXX I still cannot get page/block fast fills
116		 * XXX to work reliably on any of my AFB boards. -DaveM
117		 */
118#define AFB_FASTFILL_IS_BUGGY	1
119		if (AFB_FASTFILL_IS_BUGGY &&
120		    (pFfb->ffb_type == afb_m3 ||
121		     pFfb->ffb_type == afb_m6))
122			pFfb->disable_pagefill = 1;
123	}
124	pFfb->disable_fastfill_ap = 0;
125	if (pFfb->ffb_res == ffb_res_stereo ||
126	    pFfb->ffb_res == ffb_res_high)
127		pFfb->disable_fastfill_ap = 1;
128}
129
130/* Multiplies and divides suck... */
131void CreatorAlignTabInit(FFBPtr pFfb)
132{
133	struct fastfill_parms *ffp = &FFB_FFPARMS(pFfb);
134	short *tab = pFfb->Pf_AlignTab;
135	int i;
136
137	for(i = 0; i < 0x800; i++) {
138		int alignval;
139
140		alignval = (i / ffp->pagefill_width) * ffp->pagefill_width;
141		*tab++ = alignval;
142	}
143}
144
145