2 * \file server/radeon_macros.h
3 * \brief Macros for Radeon MMIO operation.
5 * \authors Kevin E. Martin <martin@xfree86.org>
6 * \authors Rickard E. Faith <faith@valinux.com>
7 * \authors Alan Hourihane <alanh@fairlite.demon.co.uk>
11 * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
12 * VA Linux Systems Inc., Fremont, California.
14 * All Rights Reserved.
16 * Permission is hereby granted, free of charge, to any person obtaining
17 * a copy of this software and associated documentation files (the
18 * "Software"), to deal in the Software without restriction, including
19 * without limitation on the rights to use, copy, modify, merge,
20 * publish, distribute, sublicense, and/or sell copies of the Software,
21 * and to permit persons to whom the Software is furnished to do so,
22 * subject to the following conditions:
24 * The above copyright notice and this permission notice (including the
25 * next paragraph) shall be included in all copies or substantial
26 * portions of the Software.
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NON-INFRINGEMENT. IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR
32 * THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 * DEALINGS IN THE SOFTWARE.
38 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ati/radeon_reg.h,v 1.20 2002/10/12 01:38:07 martin Exp $ */
40 #ifndef _RADEON_MACROS_H_
41 #define _RADEON_MACROS_H_
45 # define MMIO_IN8(base, offset) \
46 *(volatile unsigned char *)(((unsigned char*)(base)) + (offset))
47 # define MMIO_IN16(base, offset) \
48 *(volatile unsigned short *)(void *)(((unsigned char*)(base)) + (offset))
49 # define MMIO_IN32(base, offset) \
50 *(volatile unsigned int *)(void *)(((unsigned char*)(base)) + (offset))
51 # define MMIO_OUT8(base, offset, val) \
52 *(volatile unsigned char *)(((unsigned char*)(base)) + (offset)) = (val)
53 # define MMIO_OUT16(base, offset, val) \
54 *(volatile unsigned short *)(void *)(((unsigned char*)(base)) + (offset)) = (val)
55 # define MMIO_OUT32(base, offset, val) \
56 *(volatile unsigned int *)(void *)(((unsigned char*)(base)) + (offset)) = (val)
59 /* Memory mapped register access macros */
60 #define INREG8(addr) MMIO_IN8(RADEONMMIO, addr)
61 #define INREG16(addr) MMIO_IN16(RADEONMMIO, addr)
62 #define INREG(addr) MMIO_IN32(RADEONMMIO, addr)
63 #define OUTREG8(addr, val) MMIO_OUT8(RADEONMMIO, addr, val)
64 #define OUTREG16(addr, val) MMIO_OUT16(RADEONMMIO, addr, val)
65 #define OUTREG(addr, val) MMIO_OUT32(RADEONMMIO, addr, val)
67 #define ADDRREG(addr) ((volatile GLuint *)(pointer)(RADEONMMIO + (addr)))
70 #define OUTREGP(addr, val, mask) \
72 GLuint tmp = INREG(addr); \
78 #define INPLL(dpy, addr) RADEONINPLL(dpy, addr)
80 #define OUTPLL(addr, val) \
82 OUTREG8(RADEON_CLOCK_CNTL_INDEX, (((addr) & 0x3f) | \
84 OUTREG(RADEON_CLOCK_CNTL_DATA, val); \
87 #define OUTPLLP(dpy, addr, val, mask) \
89 GLuint tmp = INPLL(dpy, addr); \
95 #define OUTPAL_START(idx) \
97 OUTREG8(RADEON_PALETTE_INDEX, (idx)); \
100 #define OUTPAL_NEXT(r, g, b) \
102 OUTREG(RADEON_PALETTE_DATA, ((r) << 16) | ((g) << 8) | (b)); \
105 #define OUTPAL_NEXT_CARD32(v) \
107 OUTREG(RADEON_PALETTE_DATA, (v & 0x00ffffff)); \
110 #define OUTPAL(idx, r, g, b) \
112 OUTPAL_START((idx)); \
113 OUTPAL_NEXT((r), (g), (b)); \
116 #define INPAL_START(idx) \
118 OUTREG(RADEON_PALETTE_INDEX, (idx) << 16); \
121 #define INPAL_NEXT() INREG(RADEON_PALETTE_DATA)
123 #define PAL_SELECT(idx) \
126 OUTREG(RADEON_DAC_CNTL2, INREG(RADEON_DAC_CNTL2) & \
127 (GLuint)~RADEON_DAC2_PALETTE_ACC_CTL); \
129 OUTREG(RADEON_DAC_CNTL2, INREG(RADEON_DAC_CNTL2) | \
130 RADEON_DAC2_PALETTE_ACC_CTL); \