atimach64io.c revision 32b578d3
1848b8605Smrg/* 2848b8605Smrg * Copyright 2000 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org 3848b8605Smrg * 4848b8605Smrg * Permission to use, copy, modify, distribute, and sell this software and its 5848b8605Smrg * documentation for any purpose is hereby granted without fee, provided that 6848b8605Smrg * the above copyright notice appear in all copies and that both that copyright 7848b8605Smrg * notice and this permission notice appear in supporting documentation, and 8848b8605Smrg * that the name of Marc Aurele La France not be used in advertising or 9848b8605Smrg * publicity pertaining to distribution of the software without specific, 10848b8605Smrg * written prior permission. Marc Aurele La France makes no representations 11848b8605Smrg * about the suitability of this software for any purpose. It is provided 12848b8605Smrg * "as-is" without express or implied warranty. 13848b8605Smrg * 14848b8605Smrg * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15848b8605Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO 16848b8605Smrg * EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17848b8605Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18848b8605Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19848b8605Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 20848b8605Smrg * PERFORMANCE OF THIS SOFTWARE. 21848b8605Smrg */ 22848b8605Smrg 23848b8605Smrg#ifdef HAVE_CONFIG_H 24848b8605Smrg#include "config.h" 25848b8605Smrg#endif 26848b8605Smrg 27848b8605Smrg#include "ati.h" 28848b8605Smrg#include "atichip.h" 29848b8605Smrg#include "atimach64io.h" 30848b8605Smrg 31848b8605Smrg/* 32848b8605Smrg * ATIMach64AccessPLLReg -- 33848b8605Smrg * 34848b8605Smrg * This function sets up the addressing required to access, for read or write, 35848b8605Smrg * a 264xT's PLL registers. 36848b8605Smrg */ 37848b8605Smrgvoid 38848b8605SmrgATIMach64AccessPLLReg 39848b8605Smrg( 40848b8605Smrg ATIPtr pATI, 41848b8605Smrg const CARD8 Index, 42848b8605Smrg const Bool Write 43848b8605Smrg) 44848b8605Smrg{ 45848b8605Smrg CARD8 clock_cntl1 = in8(CLOCK_CNTL + 1) & 46848b8605Smrg ~GetByte(PLL_WR_EN | PLL_ADDR, 1); 47848b8605Smrg 48848b8605Smrg /* Set PLL register to be read or written */ 49848b8605Smrg out8(CLOCK_CNTL + 1, clock_cntl1 | 50848b8605Smrg GetByte(SetBits(Index, PLL_ADDR) | SetBits(Write, PLL_WR_EN), 1)); 51848b8605Smrg} 52848b8605Smrg 53848b8605Smrg/* 54848b8605Smrg * ATIMach64PollEngineStatus -- 55848b8605Smrg * 56848b8605Smrg * This function refreshes the driver's view of the draw engine's status. This 57848b8605Smrg * has been moved into a separate compilation unit to prevent inlining. 58848b8605Smrg */ 59848b8605Smrgvoid 60848b8605SmrgATIMach64PollEngineStatus 61848b8605Smrg( 62848b8605Smrg ATIPtr pATI 63848b8605Smrg) 64848b8605Smrg{ 65848b8605Smrg CARD32 IOValue; 66848b8605Smrg int Count; 67848b8605Smrg 68848b8605Smrg if (pATI->Chip < ATI_CHIP_264VTB) 69848b8605Smrg { 70848b8605Smrg /* 71848b8605Smrg * TODO: Deal with locked engines. 72848b8605Smrg */ 73848b8605Smrg IOValue = inm(FIFO_STAT); 74848b8605Smrg pATI->EngineIsLocked = GetBits(IOValue, FIFO_ERR); 75848b8605Smrg 76848b8605Smrg /* 77848b8605Smrg * The following counts the number of bits in FIFO_STAT_BITS, and is 78848b8605Smrg * derived from miSetVisualTypes(). 79848b8605Smrg */ 80848b8605Smrg IOValue = GetBits(IOValue, FIFO_STAT_BITS); 81848b8605Smrg Count = (IOValue >> 1) & 0x36DBU; 82848b8605Smrg Count = IOValue - Count - ((Count >> 1) & 0x36DBU); 83848b8605Smrg Count = ((Count + (Count >> 3)) & 0x71C7U) % 0x3FU; 84848b8605Smrg Count = pATI->nFIFOEntries - Count; 85848b8605Smrg if (Count > pATI->nAvailableFIFOEntries) 86848b8605Smrg pATI->nAvailableFIFOEntries = Count; 87848b8605Smrg 88848b8605Smrg /* 89848b8605Smrg * If the command FIFO is non-empty, then the engine isn't idle. 90848b8605Smrg */ 91848b8605Smrg if (pATI->nAvailableFIFOEntries < pATI->nFIFOEntries) 92848b8605Smrg { 93848b8605Smrg pATI->EngineIsBusy = TRUE; 94848b8605Smrg return; 95848b8605Smrg } 96848b8605Smrg } 97848b8605Smrg 98848b8605Smrg IOValue = inm(GUI_STAT); 99848b8605Smrg pATI->EngineIsBusy = GetBits(IOValue, GUI_ACTIVE); 100848b8605Smrg Count = GetBits(IOValue, GUI_FIFO); 101848b8605Smrg if (Count > pATI->nAvailableFIFOEntries) 102848b8605Smrg pATI->nAvailableFIFOEntries = Count; 103848b8605Smrg} 104848b8605Smrg