1/* Copyright (c) 2003-2006 Advanced Micro Devices, Inc. 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a copy 4 * of this software and associated documentation files (the "Software"), to 5 * deal in the Software without restriction, including without limitation the 6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 * sell copies of the Software, and to permit persons to whom the Software is 8 * furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 * IN THE SOFTWARE. 20 * 21 * Neither the name of the Advanced Micro Devices, Inc. nor the names of its 22 * contributors may be used to endorse or promote products derived from this 23 * software without specific prior written permission. 24 * */ 25 26/* The previous version of this file was way more complex then it should have 27 been - remove the unnecessary #defines and routines, and concentrate on 28 Linux for now. 29*/ 30 31#ifdef HAVE_CONFIG_H 32#include "config.h" 33#endif 34 35#include <unistd.h> 36#include <errno.h> 37#include <compiler.h> 38#include <os.h> /* ErrorF() */ 39 40/* Compiler options */ 41 42#define GFX_DISPLAY_GU1 0 /* 1st generation display controller */ 43#define GFX_DISPLAY_GU2 1 /* 2nd generation display controller */ 44 45#define GFX_INIT_DYNAMIC 0 /* runtime selection */ 46#define GFX_INIT_GU1 0 /* SC1200/GX1 */ 47#define GFX_INIT_GU2 1 /* GX */ 48 49#define GFX_MSR_DYNAMIC 0 /* runtime selection */ 50#define GFX_MSR_REDCLOUD 1 /* GX */ 51 52#define GFX_2DACCEL_DYNAMIC 0 /* runtime selection */ 53#define GFX_2DACCEL_GU1 0 /* 1st generation 2D accelerator */ 54#define GFX_2DACCEL_GU2 1 /* 2nd generation 2D accelerator */ 55 56#define GFX_VIDEO_DYNAMIC 0 /* runtime selection */ 57#define GFX_VIDEO_CS5530 0 /* support for CS5530 */ 58#define GFX_VIDEO_SC1200 0 /* support for SC1200 */ 59#define GFX_VIDEO_REDCLOUD 1 /* support for GX */ 60 61#define GFX_VIP_DYNAMIC 0 /* runtime selection */ 62#define GFX_VIP_SC1200 0 /* support for SC1200 */ 63 64#define GFX_DECODER_DYNAMIC 0 /* runtime selection */ 65#define GFX_DECODER_SAA7114 0 /* Philips SAA7114 decoder */ 66 67#define GFX_TV_DYNAMIC 0 /* runtime selection */ 68#define GFX_TV_FS451 0 /* Focus Enhancements FS450 */ 69#define GFX_TV_SC1200 0 /* SC1200 integrated TV encoder */ 70 71#define GFX_I2C_DYNAMIC 0 /* runtime selection */ 72#define GFX_I2C_ACCESS 0 /* support for ACCESS.BUS */ 73#define GFX_I2C_GPIO 0 /* support for CS5530 GPIOs */ 74 75#define GFX_VGA_DYNAMIC 0 /* runtime selection */ 76#define GFX_VGA_GU1 0 /* 1st generation graphics unit */ 77 78#define FB4MB 1 /* Set to use 4Mb vid ram for Pyramid */ 79 80#define GFX_NO_IO_IN_WAIT_MACROS 1 /* Set to remove I/O accesses in GP */ 81#define GFX_READ_ROUTINES 1 82 83#include "gfx_rtns.h" 84#include "gfx_priv.h" 85#include "gfx_regs.h" 86#include "gfx_defs.h" 87 88unsigned char *gfx_virt_regptr = (unsigned char *) 0x40000000; 89unsigned char *gfx_virt_fbptr = (unsigned char *) 0x40800000; 90unsigned char *gfx_virt_vidptr = (unsigned char *) 0x40010000; 91unsigned char *gfx_virt_vipptr = (unsigned char *) 0x40015000; 92unsigned char *gfx_virt_spptr = (unsigned char *) 0x40000000; 93unsigned char *gfx_virt_gpptr = (unsigned char *) 0x40000000; 94 95unsigned char *gfx_phys_regptr = (unsigned char *) 0x40000000; 96unsigned char *gfx_phys_fbptr = (unsigned char *) 0x40800000; 97unsigned char *gfx_phys_vidptr = (unsigned char *) 0x40010000; 98unsigned char *gfx_phys_vipptr = (unsigned char *) 0x40015000; 99 100#define INB(port) inb(port) 101#define INW(port) inw(port) 102#define IND(port) inl(port) 103#define OUTB(port,data) outb(port, data) 104#define OUTW(port,data) outw(port, data) 105#define OUTD(port,data) outl(port, data) 106 107/* Squash warnings */ 108unsigned char gfx_inb(unsigned short); 109unsigned short gfx_inw(unsigned short); 110unsigned long gfx_ind(unsigned short); 111 112void gfx_outb(unsigned short, unsigned char); 113void gfx_outw(unsigned short, unsigned short); 114void gfx_outd(unsigned short, unsigned long); 115 116inline unsigned char 117gfx_inb(unsigned short port) 118{ 119 return inb(port); 120} 121 122inline unsigned short 123gfx_inw(unsigned short port) 124{ 125 return inw(port); 126} 127 128inline unsigned long 129gfx_ind(unsigned short port) 130{ 131 return inl(port); 132} 133 134inline void 135gfx_outb(unsigned short port, unsigned char data) 136{ 137 outb(port, data); 138} 139 140inline void 141gfx_outw(unsigned short port, unsigned short data) 142{ 143 outw(port, data); 144} 145 146inline void 147gfx_outd(unsigned short port, unsigned long data) 148{ 149 outl(port, data); 150} 151 152/* These routines use VSA to read the MSRs - these are a second resort to the Linux MSR method */ 153 154#define vsa_msr_read(msr,adr,high,low) \ 155 __asm__ __volatile__( \ 156 " mov $0x0AC1C, %%edx\n" \ 157 " mov $0xFC530007, %%eax\n" \ 158 " out %%eax,%%dx\n" \ 159 " add $2,%%dl\n" \ 160 " in %%dx, %%ax" \ 161 : "=a" (*(low)), "=d" (*(high)) \ 162 : "c" (msr | adr)) 163 164#define vsa_msr_write(msr,adr,high,low) \ 165 { int d0, d1, d2, d3, d4; \ 166 __asm__ __volatile__( \ 167 " push %%ebx\n" \ 168 " mov $0x0AC1C, %%edx\n" \ 169 " mov $0xFC530007, %%eax\n" \ 170 " out %%eax,%%dx\n" \ 171 " add $2,%%dl\n" \ 172 " mov %6, %%ebx\n" \ 173 " mov %7, %0\n" \ 174 " mov %5, %3\n" \ 175 " xor %2, %2\n" \ 176 " xor %1, %1\n" \ 177 " out %%ax, %%dx\n" \ 178 " pop %%ebx\n" \ 179 : "=a"(d0),"=&D"(d1),"=&S"(d2), \ 180 "=c"(d3),"=d"(d4) \ 181 : "1"(msr | adr),"2"(*(high)),"3"(*(low))); \ 182 } 183 184extern int GeodeWriteMSR(unsigned long, unsigned long, unsigned long); 185extern int GeodeReadMSR(unsigned long, unsigned long *, unsigned long *); 186 187void 188gfx_msr_asm_write(unsigned short reg, unsigned long addr, 189 unsigned long *hi, unsigned long *lo) 190{ 191 static int msr_method = 0; 192 193 if (msr_method == 0) { 194 if (!GeodeWriteMSR(addr | reg, *lo, *hi)) 195 return; 196 197 msr_method = 1; 198 } 199 200 /* This is the fallback VSA method - not preferred */ 201 vsa_msr_write(reg, addr, hi, lo); 202} 203 204void 205gfx_msr_asm_read(unsigned short reg, unsigned long addr, 206 unsigned long *hi, unsigned long *lo) 207{ 208 static int msr_method = 0; 209 210 if (msr_method == 0) { 211 if (!GeodeReadMSR(addr | reg, lo, hi)) 212 return; 213 214 ErrorF("Unable to read the MSR - reverting to the VSA method.\n"); 215 msr_method = 1; 216 } 217 218 /* This is the fallback VSA method - not preferred */ 219 vsa_msr_read(reg, addr, hi, lo); 220} 221 222#include "gfx_init.c" 223#include "gfx_msr.c" 224#include "gfx_rndr.c" 225#include "gfx_mode.h" 226#include "gfx_disp.c" 227#include "gfx_vid.c" 228#include "gfx_vip.c" 229#include "gfx_dcdr.c" 230#include "gfx_i2c.c" 231#include "gfx_tv.c" 232#include "gfx_vga.c" 233