durango.c revision f29dbc25
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 unnessesary #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#define _LARGEFILE64_SOURCE 36 37#include <unistd.h> 38#include <errno.h> 39#include <compiler.h> 40#include <os.h> /* ErrorF() */ 41 42/* Compiler options */ 43 44#define GFX_DISPLAY_GU1 0 /* 1st generation display controller */ 45#define GFX_DISPLAY_GU2 1 /* 2nd generation display controller */ 46 47#define GFX_INIT_DYNAMIC 0 /* runtime selection */ 48#define GFX_INIT_GU1 0 /* SC1200/GX1 */ 49#define GFX_INIT_GU2 1 /* GX */ 50 51#define GFX_MSR_DYNAMIC 0 /* runtime selection */ 52#define GFX_MSR_REDCLOUD 1 /* GX */ 53 54#define GFX_2DACCEL_DYNAMIC 0 /* runtime selection */ 55#define GFX_2DACCEL_GU1 0 /* 1st generation 2D accelerator */ 56#define GFX_2DACCEL_GU2 1 /* 2nd generation 2D accelerator */ 57 58#define GFX_VIDEO_DYNAMIC 0 /* runtime selection */ 59#define GFX_VIDEO_CS5530 0 /* support for CS5530 */ 60#define GFX_VIDEO_SC1200 0 /* support for SC1200 */ 61#define GFX_VIDEO_REDCLOUD 1 /* support for GX */ 62 63#define GFX_VIP_DYNAMIC 0 /* runtime selection */ 64#define GFX_VIP_SC1200 0 /* support for SC1200 */ 65 66#define GFX_DECODER_DYNAMIC 0 /* runtime selection */ 67#define GFX_DECODER_SAA7114 0 /* Philips SAA7114 decoder */ 68 69#define GFX_TV_DYNAMIC 0 /* runtime selection */ 70#define GFX_TV_FS451 0 /* Focus Enhancements FS450 */ 71#define GFX_TV_SC1200 0 /* SC1200 integrated TV encoder */ 72 73#define GFX_I2C_DYNAMIC 0 /* runtime selection */ 74#define GFX_I2C_ACCESS 0 /* support for ACCESS.BUS */ 75#define GFX_I2C_GPIO 0 /* support for CS5530 GPIOs */ 76 77#define GFX_VGA_DYNAMIC 0 /* runtime selection */ 78#define GFX_VGA_GU1 0 /* 1st generation graphics unit */ 79 80#define FB4MB 1 /* Set to use 4Mb vid ram for Pyramid */ 81 82#define GFX_NO_IO_IN_WAIT_MACROS 1 /* Set to remove I/O accesses in GP */ 83#define GFX_READ_ROUTINES 1 84 85#include "gfx_rtns.h" 86#include "gfx_priv.h" 87#include "gfx_regs.h" 88#include "gfx_defs.h" 89 90unsigned char *gfx_virt_regptr = (unsigned char *)0x40000000; 91unsigned char *gfx_virt_fbptr = (unsigned char *)0x40800000; 92unsigned char *gfx_virt_vidptr = (unsigned char *)0x40010000; 93unsigned char *gfx_virt_vipptr = (unsigned char *)0x40015000; 94unsigned char *gfx_virt_spptr = (unsigned char *)0x40000000; 95unsigned char *gfx_virt_gpptr = (unsigned char *)0x40000000; 96 97unsigned char *gfx_phys_regptr = (unsigned char *)0x40000000; 98unsigned char *gfx_phys_fbptr = (unsigned char *)0x40800000; 99unsigned char *gfx_phys_vidptr = (unsigned char *)0x40010000; 100unsigned char *gfx_phys_vipptr = (unsigned char *)0x40015000; 101 102#define INB(port) inb(port) 103#define INW(port) inw(port) 104#define IND(port) inl(port) 105#define OUTB(port,data) outb(port, data) 106#define OUTW(port,data) outw(port, data) 107#define OUTD(port,data) outl(port, data) 108 109/* Squash warnings */ 110unsigned char gfx_inb(unsigned short); 111unsigned short gfx_inw(unsigned short); 112unsigned long gfx_ind(unsigned short); 113 114void gfx_outb(unsigned short, unsigned char); 115void gfx_outw(unsigned short, unsigned short); 116void gfx_outd(unsigned short, unsigned long); 117 118inline unsigned char 119gfx_inb(unsigned short port) 120{ 121 return inb(port); 122} 123 124inline unsigned short 125gfx_inw(unsigned short port) 126{ 127 return inw(port); 128} 129 130inline unsigned long 131gfx_ind(unsigned short port) 132{ 133 return inl(port); 134} 135 136inline void 137gfx_outb(unsigned short port, unsigned char data) 138{ 139 outb(port, data); 140} 141 142inline void 143gfx_outw(unsigned short port, unsigned short data) 144{ 145 outw(port, data); 146} 147 148inline void 149gfx_outd(unsigned short port, unsigned long data) 150{ 151 outl(port, data); 152} 153 154/* These routines use VSA to read the MSRs - these are a second resort to the Linux MSR method */ 155 156#define vsa_msr_read(msr,adr,high,low) \ 157 __asm__ __volatile__( \ 158 " mov $0x0AC1C, %%edx\n" \ 159 " mov $0xFC530007, %%eax\n" \ 160 " out %%eax,%%dx\n" \ 161 " add $2,%%dl\n" \ 162 " in %%dx, %%ax" \ 163 : "=a" (*(low)), "=d" (*(high)) \ 164 : "c" (msr | adr)) 165 166#define vsa_msr_write(msr,adr,high,low) \ 167 { int d0, d1, d2, d3, d4; \ 168 __asm__ __volatile__( \ 169 " push %%ebx\n" \ 170 " mov $0x0AC1C, %%edx\n" \ 171 " mov $0xFC530007, %%eax\n" \ 172 " out %%eax,%%dx\n" \ 173 " add $2,%%dl\n" \ 174 " mov %6, %%ebx\n" \ 175 " mov %7, %0\n" \ 176 " mov %5, %3\n" \ 177 " xor %2, %2\n" \ 178 " xor %1, %1\n" \ 179 " out %%ax, %%dx\n" \ 180 " pop %%ebx\n" \ 181 : "=a"(d0),"=&D"(d1),"=&S"(d2), \ 182 "=c"(d3),"=d"(d4) \ 183 : "1"(msr | adr),"2"(*(high)),"3"(*(low))); \ 184 } 185 186extern int GeodeWriteMSR(unsigned long, unsigned long, unsigned long); 187extern int GeodeReadMSR(unsigned long, unsigned long *, unsigned long *); 188 189void 190gfx_msr_asm_write(unsigned short reg, unsigned long addr, 191 unsigned long *hi, unsigned long *lo) 192{ 193 static int msr_method = 0; 194 195 if (msr_method == 0) { 196 if (!GeodeWriteMSR(addr | reg, *lo, *hi)) 197 return; 198 199 msr_method = 1; 200 } 201 202 /* This is the fallback VSA method - not preferred */ 203 vsa_msr_write(reg, addr, hi, lo); 204} 205 206void 207gfx_msr_asm_read(unsigned short reg, unsigned long addr, 208 unsigned long *hi, unsigned long *lo) 209{ 210 static int msr_method = 0; 211 212 if (msr_method == 0) { 213 if (!GeodeReadMSR(addr | reg, lo, hi)) 214 return; 215 216 ErrorF("Unable to read the MSR - reverting to the VSA method.\n"); 217 msr_method = 1; 218 } 219 220 /* This is the fallback VSA method - not preferred */ 221 vsa_msr_read(reg, addr, hi, lo); 222} 223 224#include "gfx_init.c" 225#include "gfx_msr.c" 226#include "gfx_rndr.c" 227#include "gfx_mode.h" 228#include "gfx_disp.c" 229#include "gfx_vid.c" 230#include "gfx_vip.c" 231#include "gfx_dcdr.c" 232#include "gfx_i2c.c" 233#include "gfx_tv.c" 234#include "gfx_vga.c" 235