1/* $NetBSD: ffb_accel_common.c,v 1.4 2016/09/02 21:24:49 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#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 46/* Indexed by ffb resolution enum. */ 47struct fastfill_parms ffb_fastfill_parms[] = { 48 /* fsmall, psmall, ffh, ffw, pfh, pfw */ 49 { 0x00c0, 0x1400, 0x04, 0x08, 0x10, 0x50 }, /* Standard: 1280 x 1024 */ 50 { 0x0140, 0x2800, 0x04, 0x10, 0x10, 0xa0 }, /* High: 1920 x 1360 */ 51 { 0x0080, 0x0a00, 0x02, 0x08, 0x08, 0x50 }, /* Stereo: 960 x 580 */ 52/*XXX*/ { 0x00c0, 0x0a00, 0x04, 0x08, 0x08, 0x50 }, /* Portrait: 1280 x 2048 XXX */ 53}; 54 55void FFB_SetupTextureAttrs(FFBPtr pFfb) 56{ 57 ffb_fbcPtr ffb = pFfb->regs; 58 unsigned int ppc = FFB_PPC_APE_DISABLE | FFB_PPC_CS_VAR | FFB_PPC_XS_VAR; 59 unsigned int ppc_mask = FFB_PPC_APE_MASK | FFB_PPC_CS_MASK | FFB_PPC_XS_MASK; 60 unsigned int rop = FFB_ROP_NEW | (FFB_ROP_NEW << 8); 61 unsigned int fbc = pFfb->fbc; 62 unsigned int wid = pFfb->wid; 63 64 ppc |= FFB_PPC_ABE_ENABLE; 65 ppc_mask |= FFB_PPC_ABE_MASK; 66 67 if ((pFfb->ppc_cache & ppc_mask) != ppc || 68 pFfb->fbc_cache != fbc || 69 pFfb->wid_cache != wid || 70 pFfb->rop_cache != rop || 71 pFfb->pmask_cache != 0xffffffff) 72 __FFB_Attr_SFB_VAR(pFfb, ppc, ppc_mask, fbc, 73 wid, rop, 0xffffffff); 74 FFBWait(pFfb, ffb); 75} 76 77void FFB_HardwareSetup(FFBPtr pFfb) 78{ 79 ffb_fbcPtr ffb = pFfb->regs; 80 81 /* Determine the current screen resolution type. This is 82 * needed to figure out the fastfill/pagefill parameters. 83 */ 84 switch(ffb->fbcfg0 & FFB_FBCFG0_RES_MASK) { 85 default: 86 case FFB_FBCFG0_RES_STD: 87 pFfb->ffb_res = ffb_res_standard; 88 break; 89 case FFB_FBCFG0_RES_HIGH: 90 pFfb->ffb_res = ffb_res_high; 91 break; 92 case FFB_FBCFG0_RES_STEREO: 93 pFfb->ffb_res = ffb_res_stereo; 94 break; 95 case FFB_FBCFG0_RES_PRTRAIT: 96 pFfb->ffb_res = ffb_res_portrait; 97 break; 98 }; 99 CreatorAlignTabInit(pFfb); 100 101 /* Next, determine the hwbug workarounds and feature enables 102 * we should be using on this board. 103 */ 104 pFfb->disable_pagefill = 0; 105 pFfb->disable_vscroll = 0; 106 pFfb->has_brline_bug = 0; 107 pFfb->use_blkread_prefetch = 0; 108 if (pFfb->ffb_type == ffb1_prototype || 109 pFfb->ffb_type == ffb1_standard || 110 pFfb->ffb_type == ffb1_speedsort) { 111 pFfb->has_brline_bug = 1; 112 if (pFfb->ffb_res == ffb_res_high) 113 pFfb->disable_vscroll = 1; 114 if (pFfb->ffb_res == ffb_res_high || 115 pFfb->ffb_res == ffb_res_stereo) 116 pFfb->disable_pagefill = 1; 117 118 } else { 119 /* FFB2 has blkread prefetch. AFB supposedly does too 120 * but the chip locks up on me when I try to use it. -DaveM 121 */ 122#define AFB_PREFETCH_IS_BUGGY 1 123 if (!AFB_PREFETCH_IS_BUGGY || 124 (pFfb->ffb_type != afb_m3 && 125 pFfb->ffb_type != afb_m6)) { 126 pFfb->use_blkread_prefetch = 1; 127 } 128 /* XXX I still cannot get page/block fast fills 129 * XXX to work reliably on any of my AFB boards. -DaveM 130 */ 131#define AFB_FASTFILL_IS_BUGGY 1 132 if (AFB_FASTFILL_IS_BUGGY && 133 (pFfb->ffb_type == afb_m3 || 134 pFfb->ffb_type == afb_m6)) 135 pFfb->disable_pagefill = 1; 136 } 137 pFfb->disable_fastfill_ap = 0; 138 if (pFfb->ffb_res == ffb_res_stereo || 139 pFfb->ffb_res == ffb_res_high) 140 pFfb->disable_fastfill_ap = 1; 141} 142 143/* Multiplies and divides suck... */ 144void CreatorAlignTabInit(FFBPtr pFfb) 145{ 146 struct fastfill_parms *ffp = &FFB_FFPARMS(pFfb); 147 short *tab = pFfb->Pf_AlignTab; 148 int i; 149 150 for(i = 0; i < 0x800; i++) { 151 int alignval; 152 153 alignval = (i / ffp->pagefill_width) * ffp->pagefill_width; 154 *tab++ = alignval; 155 } 156} 157 158