1209ff23fSmrg/* 2209ff23fSmrg * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and 3209ff23fSmrg * VA Linux Systems Inc., Fremont, California. 4209ff23fSmrg * 5209ff23fSmrg * All Rights Reserved. 6209ff23fSmrg * 7209ff23fSmrg * Permission is hereby granted, free of charge, to any person obtaining 8209ff23fSmrg * a copy of this software and associated documentation files (the 9209ff23fSmrg * "Software"), to deal in the Software without restriction, including 10209ff23fSmrg * without limitation on the rights to use, copy, modify, merge, 11209ff23fSmrg * publish, distribute, sublicense, and/or sell copies of the Software, 12209ff23fSmrg * and to permit persons to whom the Software is furnished to do so, 13209ff23fSmrg * subject to the following conditions: 14209ff23fSmrg * 15209ff23fSmrg * The above copyright notice and this permission notice (including the 16209ff23fSmrg * next paragraph) shall be included in all copies or substantial 17209ff23fSmrg * portions of the Software. 18209ff23fSmrg * 19209ff23fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20209ff23fSmrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21209ff23fSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22209ff23fSmrg * NON-INFRINGEMENT. IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR 23209ff23fSmrg * THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24209ff23fSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25209ff23fSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26209ff23fSmrg * DEALINGS IN THE SOFTWARE. 27209ff23fSmrg */ 28209ff23fSmrg 29209ff23fSmrg/* 30209ff23fSmrg * Authors: 31209ff23fSmrg * Kevin E. Martin <martin@xfree86.org> 32209ff23fSmrg * Rickard E. Faith <faith@valinux.com> 33209ff23fSmrg * Alan Hourihane <alanh@fairlite.demon.co.uk> 34209ff23fSmrg * 35209ff23fSmrg * References: 36209ff23fSmrg * 37209ff23fSmrg * !!!! FIXME !!!! 38209ff23fSmrg * RAGE 128 VR/ RAGE 128 GL Register Reference Manual (Technical 39209ff23fSmrg * Reference Manual P/N RRG-G04100-C Rev. 0.04), ATI Technologies: April 40209ff23fSmrg * 1999. 41209ff23fSmrg * 42209ff23fSmrg * !!!! FIXME !!!! 43209ff23fSmrg * RAGE 128 Software Development Manual (Technical Reference Manual P/N 44209ff23fSmrg * SDK-G04000 Rev. 0.01), ATI Technologies: June 1999. 45209ff23fSmrg * 46209ff23fSmrg */ 47209ff23fSmrg 48209ff23fSmrg 49209ff23fSmrg#ifndef _RADEON_MACROS_H_ 50209ff23fSmrg#define _RADEON_MACROS_H_ 51209ff23fSmrg 52209ff23fSmrg#include "compiler.h" 53209ff23fSmrg 54209ff23fSmrg#define RADEON_BIOS8(v) (info->VBIOS[v]) 55209ff23fSmrg#define RADEON_BIOS16(v) (info->VBIOS[v] | \ 56209ff23fSmrg (info->VBIOS[(v) + 1] << 8)) 57209ff23fSmrg#define RADEON_BIOS32(v) (info->VBIOS[v] | \ 58209ff23fSmrg (info->VBIOS[(v) + 1] << 8) | \ 59209ff23fSmrg (info->VBIOS[(v) + 2] << 16) | \ 60209ff23fSmrg (info->VBIOS[(v) + 3] << 24)) 61209ff23fSmrg 62209ff23fSmrg /* Memory mapped register access macros */ 63209ff23fSmrg#define INREG8(addr) MMIO_IN8(RADEONMMIO, addr) 64209ff23fSmrg#define INREG16(addr) MMIO_IN16(RADEONMMIO, addr) 65209ff23fSmrg#define INREG(addr) MMIO_IN32(RADEONMMIO, addr) 66209ff23fSmrg#define OUTREG8(addr, val) MMIO_OUT8(RADEONMMIO, addr, val) 67209ff23fSmrg#define OUTREG16(addr, val) MMIO_OUT16(RADEONMMIO, addr, val) 68209ff23fSmrg#define OUTREG(addr, val) MMIO_OUT32(RADEONMMIO, addr, val) 69209ff23fSmrg 70209ff23fSmrg#define ADDRREG(addr) ((volatile uint32_t *)(pointer)(RADEONMMIO + (addr))) 71209ff23fSmrg 72209ff23fSmrg 73209ff23fSmrg#define OUTREGP(addr, val, mask) \ 74209ff23fSmrgdo { \ 75209ff23fSmrg uint32_t tmp = INREG(addr); \ 76209ff23fSmrg tmp &= (mask); \ 77209ff23fSmrg tmp |= ((val) & ~(mask)); \ 78209ff23fSmrg OUTREG(addr, tmp); \ 79209ff23fSmrg} while (0) 80209ff23fSmrg 81209ff23fSmrg#define INPLL(pScrn, addr) RADEONINPLL(pScrn, addr) 82209ff23fSmrg 83209ff23fSmrg#define OUTPLL(pScrn, addr, val) RADEONOUTPLL(pScrn, addr, val) 84209ff23fSmrg 85209ff23fSmrg#define OUTPLLP(pScrn, addr, val, mask) \ 86209ff23fSmrgdo { \ 87209ff23fSmrg uint32_t tmp_ = INPLL(pScrn, addr); \ 88209ff23fSmrg tmp_ &= (mask); \ 89209ff23fSmrg tmp_ |= ((val) & ~(mask)); \ 90209ff23fSmrg OUTPLL(pScrn, addr, tmp_); \ 91209ff23fSmrg} while (0) 92209ff23fSmrg 93209ff23fSmrg#define OUTPAL_START(idx) \ 94209ff23fSmrgdo { \ 95209ff23fSmrg if (IS_AVIVO_VARIANT) { \ 96209ff23fSmrg OUTREG8(AVIVO_DC_LUT_RW_INDEX, (idx)); \ 97209ff23fSmrg } else { \ 98209ff23fSmrg OUTREG8(RADEON_PALETTE_INDEX, (idx)); \ 99209ff23fSmrg } \ 100209ff23fSmrg} while (0) 101209ff23fSmrg 102209ff23fSmrg#define OUTPAL_NEXT(r, g, b) \ 103209ff23fSmrgdo { \ 104209ff23fSmrg if (IS_AVIVO_VARIANT) { \ 105b7e1c893Smrg OUTREG(AVIVO_DC_LUT_30_COLOR, ((r) << 20) | ((g) << 10) | (b)); \ 106b7e1c893Smrg } else { \ 107b7e1c893Smrg OUTREG(RADEON_PALETTE_30_DATA, ((r) << 20) | ((g) << 10) | (b)); \ 108209ff23fSmrg } \ 109209ff23fSmrg} while (0) 110209ff23fSmrg 111209ff23fSmrg#define OUTPAL(idx, r, g, b) \ 112209ff23fSmrgdo { \ 113209ff23fSmrg OUTPAL_START((idx)); \ 114209ff23fSmrg OUTPAL_NEXT((r), (g), (b)); \ 115209ff23fSmrg} while (0) 116209ff23fSmrg 117209ff23fSmrg#define INPAL_START(idx) \ 118209ff23fSmrgdo { \ 119209ff23fSmrg if (IS_AVIVO_VARIANT) { \ 120209ff23fSmrg OUTREG8(AVIVO_DC_LUT_RW_INDEX, (idx)); \ 121209ff23fSmrg } else { \ 122209ff23fSmrg OUTREG(RADEON_PALETTE_INDEX, (idx) << 16); \ 123209ff23fSmrg } \ 124209ff23fSmrg} while (0) 125209ff23fSmrg 126209ff23fSmrg#define INPAL_NEXT() \ 127209ff23fSmrgdo { \ 128209ff23fSmrg if (IS_AVIVO_VARIANT) { \ 129209ff23fSmrg INREG(AVIVO_DC_LUT_30_COLOR); \ 130209ff23fSmrg } else { \ 131b7e1c893Smrg INREG(RADEON_PALETTE_30_DATA); \ 132209ff23fSmrg } \ 133209ff23fSmrg} while (0) 134209ff23fSmrg 135209ff23fSmrg#define PAL_SELECT(idx) \ 136209ff23fSmrgdo { \ 137209ff23fSmrg if (IS_AVIVO_VARIANT) { \ 138209ff23fSmrg if (!idx) { \ 139209ff23fSmrg OUTREG(AVIVO_DC_LUT_RW_SELECT, 0); \ 140209ff23fSmrg } else { \ 141209ff23fSmrg OUTREG(AVIVO_DC_LUT_RW_SELECT, 1); \ 142209ff23fSmrg } \ 143209ff23fSmrg } else { \ 144209ff23fSmrg if (!idx) { \ 145209ff23fSmrg OUTREG(RADEON_DAC_CNTL2, INREG(RADEON_DAC_CNTL2) & \ 146209ff23fSmrg (uint32_t)~RADEON_DAC2_PALETTE_ACC_CTL); \ 147209ff23fSmrg } else { \ 148209ff23fSmrg OUTREG(RADEON_DAC_CNTL2, INREG(RADEON_DAC_CNTL2) | \ 149209ff23fSmrg RADEON_DAC2_PALETTE_ACC_CTL); \ 150209ff23fSmrg } \ 151209ff23fSmrg } \ 152209ff23fSmrg} while (0) 153209ff23fSmrg 154209ff23fSmrg#define INMC(pScrn, addr) RADEONINMC(pScrn, addr) 155209ff23fSmrg#define OUTMC(pScrn, addr, val) RADEONOUTMC(pScrn, addr, val) 156209ff23fSmrg 157b7e1c893Smrg#define INPCIE(pScrn, addr) RADEONINPCIE(pScrn, addr) 158b7e1c893Smrg#define OUTPCIE(pScrn, addr, val) RADEONOUTPCIE(pScrn, addr, val) 159b7e1c893Smrg 160ad43ddacSmrg#define INPCIE_P(pScrn, addr) R600INPCIE_PORT(pScrn, addr) 161ad43ddacSmrg#define OUTPCIE_P(pScrn, addr, val) R600OUTPCIE_PORT(pScrn, addr, val) 162ad43ddacSmrg 163ad43ddacSmrg#define BEGIN_ACCEL_RELOC(n, r) do { \ 164ad43ddacSmrg int _nqw = (n) + (info->cs ? (r) : 0); \ 165ad43ddacSmrg BEGIN_ACCEL(_nqw); \ 166ad43ddacSmrg } while (0) 167ad43ddacSmrg 168ad43ddacSmrg#define CHECK_OFFSET(pPix, mask, type) do { \ 169ad43ddacSmrg if (!info->cs) { \ 170ad43ddacSmrg uint32_t _pix_offset = radeonGetPixmapOffset(pPix); \ 171ad43ddacSmrg if ((_pix_offset & mask) != 0) \ 172ad43ddacSmrg RADEON_FALLBACK(("Bad %s offset 0x%x\n", type, (int)_pix_offset)); \ 173ad43ddacSmrg } \ 174ad43ddacSmrg } while(0) 175ad43ddacSmrg 176ad43ddacSmrg#define EMIT_OFFSET(reg, value, pPix, rd, wd) do { \ 177ad43ddacSmrg if (info->cs) { \ 178ad43ddacSmrg driver_priv = exaGetPixmapDriverPrivate(pPix); \ 179ad43ddacSmrg OUT_ACCEL_REG((reg), (value)); \ 180ad43ddacSmrg OUT_RELOC(driver_priv->bo, (rd), (wd)); \ 181ad43ddacSmrg } else { \ 182ad43ddacSmrg uint32_t _pix_offset; \ 183ad43ddacSmrg _pix_offset = radeonGetPixmapOffset(pPix); \ 184ad43ddacSmrg OUT_ACCEL_REG((reg), _pix_offset | value); \ 185ad43ddacSmrg } \ 186ad43ddacSmrg } while(0) 187ad43ddacSmrg 188ad43ddacSmrg#define EMIT_READ_OFFSET(reg, value, pPix) EMIT_OFFSET(reg, value, pPix, (RADEON_GEM_DOMAIN_VRAM | RADEON_GEM_DOMAIN_GTT), 0) 189ad43ddacSmrg#define EMIT_WRITE_OFFSET(reg, value, pPix) EMIT_OFFSET(reg, value, pPix, 0, RADEON_GEM_DOMAIN_VRAM) 190ad43ddacSmrg 191ad43ddacSmrg#define OUT_TEXTURE_REG(reg, offset, bo) do { \ 192ad43ddacSmrg if (info->cs) { \ 193ad43ddacSmrg OUT_ACCEL_REG((reg), (offset)); \ 194ad43ddacSmrg OUT_RELOC((bo), RADEON_GEM_DOMAIN_VRAM | RADEON_GEM_DOMAIN_GTT, 0); \ 195ad43ddacSmrg } else { \ 196ad43ddacSmrg OUT_ACCEL_REG((reg), (offset) + info->fbLocation + pScrn->fbOffset);} \ 197ad43ddacSmrg } while(0) 198ad43ddacSmrg 199ad43ddacSmrg#define EMIT_COLORPITCH(reg, value, pPix) do { \ 200ad43ddacSmrg if (info->cs) { \ 201ad43ddacSmrg driver_priv = exaGetPixmapDriverPrivate(pPix); \ 202ad43ddacSmrg OUT_ACCEL_REG((reg), value); \ 203ad43ddacSmrg OUT_RELOC(driver_priv->bo, 0, RADEON_GEM_DOMAIN_VRAM); \ 204ad43ddacSmrg } else { \ 205ad43ddacSmrg OUT_ACCEL_REG((reg), value); \ 206ad43ddacSmrg } \ 207ad43ddacSmrg}while(0) 208ad43ddacSmrg 209209ff23fSmrg#endif 210