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