summaryrefslogtreecommitdiff
path: root/src/durango.c
blob: 8795d41c8440f0f91003e6682dd2dae25f2e5d35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* Copyright (c) 2003-2006 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Neither the name of the Advanced Micro Devices, Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 * */

/* The previous version of this file was way more complex then it should have
   been - remove the unnessesary #defines and routines, and concentrate on
   Linux for now.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <unistd.h>
#include <errno.h>
#include <compiler.h>
#include <os.h>			       /* ErrorF() */

/* Compiler options */

#define GFX_DISPLAY_GU1	       0       /* 1st generation display controller */
#define GFX_DISPLAY_GU2	       1       /* 2nd generation display controller */

#define GFX_INIT_DYNAMIC       0       /* runtime selection */
#define GFX_INIT_GU1           0       /* SC1200/GX1        */
#define GFX_INIT_GU2           1       /* GX                */

#define GFX_MSR_DYNAMIC        0       /* runtime selection */
#define GFX_MSR_REDCLOUD       1       /* GX */

#define GFX_2DACCEL_DYNAMIC    0       /* runtime selection                                */
#define GFX_2DACCEL_GU1	       0       /* 1st generation 2D accelerator    */
#define GFX_2DACCEL_GU2	       1       /* 2nd generation 2D accelerator    */

#define GFX_VIDEO_DYNAMIC      0       /* runtime selection  */
#define GFX_VIDEO_CS5530       0       /* support for CS5530 */
#define GFX_VIDEO_SC1200       0       /* support for SC1200 */
#define GFX_VIDEO_REDCLOUD     1       /* support for GX */

#define GFX_VIP_DYNAMIC	       0       /* runtime selection  */
#define GFX_VIP_SC1200	       0       /* support for SC1200 */

#define GFX_DECODER_DYNAMIC    0       /* runtime selection */
#define GFX_DECODER_SAA7114    0       /* Philips SAA7114 decoder */

#define GFX_TV_DYNAMIC	       0       /* runtime selection */
#define GFX_TV_FS451	       0       /* Focus Enhancements FS450  */
#define GFX_TV_SC1200	       0       /* SC1200 integrated TV encoder */

#define GFX_I2C_DYNAMIC	       0       /* runtime selection  */
#define GFX_I2C_ACCESS	       0       /* support for ACCESS.BUS  */
#define GFX_I2C_GPIO	       0       /* support for CS5530 GPIOs */

#define GFX_VGA_DYNAMIC	       0       /* runtime selection */
#define GFX_VGA_GU1	       0       /* 1st generation graphics unit */

#define FB4MB		       1       /* Set to use 4Mb vid ram for Pyramid */

#define GFX_NO_IO_IN_WAIT_MACROS    1  /* Set to remove I/O accesses in GP */
#define GFX_READ_ROUTINES  1

#include "gfx_rtns.h"
#include "gfx_priv.h"
#include "gfx_regs.h"
#include "gfx_defs.h"

unsigned char *gfx_virt_regptr = (unsigned char *)0x40000000;
unsigned char *gfx_virt_fbptr = (unsigned char *)0x40800000;
unsigned char *gfx_virt_vidptr = (unsigned char *)0x40010000;
unsigned char *gfx_virt_vipptr = (unsigned char *)0x40015000;
unsigned char *gfx_virt_spptr = (unsigned char *)0x40000000;
unsigned char *gfx_virt_gpptr = (unsigned char *)0x40000000;

unsigned char *gfx_phys_regptr = (unsigned char *)0x40000000;
unsigned char *gfx_phys_fbptr = (unsigned char *)0x40800000;
unsigned char *gfx_phys_vidptr = (unsigned char *)0x40010000;
unsigned char *gfx_phys_vipptr = (unsigned char *)0x40015000;

#define INB(port) inb(port)
#define INW(port) inw(port)
#define IND(port) inl(port)
#define OUTB(port,data) outb(port, data)
#define OUTW(port,data) outw(port, data)
#define OUTD(port,data) outl(port, data)

/* Squash warnings */
unsigned char gfx_inb(unsigned short);
unsigned short gfx_inw(unsigned short);
unsigned long gfx_ind(unsigned short);

void gfx_outb(unsigned short, unsigned char);
void gfx_outw(unsigned short, unsigned short);
void gfx_outd(unsigned short, unsigned long);

inline unsigned char
gfx_inb(unsigned short port)
{
    return inb(port);
}

inline unsigned short
gfx_inw(unsigned short port)
{
    return inw(port);
}

inline unsigned long
gfx_ind(unsigned short port)
{
    return inl(port);
}

inline void
gfx_outb(unsigned short port, unsigned char data)
{
    outb(port, data);
}

inline void
gfx_outw(unsigned short port, unsigned short data)
{
    outw(port, data);
}

inline void
gfx_outd(unsigned short port, unsigned long data)
{
    outl(port, data);
}

/* These routines use VSA to read the MSRs - these are a second resort to the Linux MSR method */

#define vsa_msr_read(msr,adr,high,low)      \
     __asm__ __volatile__(                      \
        " mov $0x0AC1C, %%edx\n"                \
        " mov $0xFC530007, %%eax\n"             \
        " out %%eax,%%dx\n"                     \
        " add $2,%%dl\n"                        \
        " in %%dx, %%ax"                        \
        : "=a" (*(low)), "=d" (*(high))         \
        : "c" (msr | adr))

#define vsa_msr_write(msr,adr,high,low) \
  { int d0, d1, d2, d3, d4;        \
  __asm__ __volatile__(            \
    " push %%ebx\n"                \
    " mov $0x0AC1C, %%edx\n"       \
    " mov $0xFC530007, %%eax\n"    \
    " out %%eax,%%dx\n"            \
    " add $2,%%dl\n"               \
    " mov %6, %%ebx\n"             \
    " mov %7, %0\n"                \
    " mov %5, %3\n"                \
    " xor %2, %2\n"                \
    " xor %1, %1\n"                \
    " out %%ax, %%dx\n"            \
    " pop %%ebx\n"                 \
    : "=a"(d0),"=&D"(d1),"=&S"(d2), \
      "=c"(d3),"=d"(d4)  \
    : "1"(msr | adr),"2"(*(high)),"3"(*(low))); \
  }

extern int GeodeWriteMSR(unsigned long, unsigned long, unsigned long);
extern int GeodeReadMSR(unsigned long, unsigned long *, unsigned long *);

void
gfx_msr_asm_write(unsigned short reg, unsigned long addr,
    unsigned long *hi, unsigned long *lo)
{
    static int msr_method = 0;

    if (msr_method == 0) {
	if (!GeodeWriteMSR(addr | reg, *lo, *hi))
	    return;

	msr_method = 1;
    }

    /* This is the fallback VSA method - not preferred */
    vsa_msr_write(reg, addr, hi, lo);
}

void
gfx_msr_asm_read(unsigned short reg, unsigned long addr,
    unsigned long *hi, unsigned long *lo)
{
    static int msr_method = 0;

    if (msr_method == 0) {
	if (!GeodeReadMSR(addr | reg, lo, hi))
	    return;

	ErrorF("Unable to read the MSR - reverting to the VSA method.\n");
	msr_method = 1;
    }

    /* This is the fallback VSA method - not preferred */
    vsa_msr_read(reg, addr, hi, lo);
}

#include "gfx_init.c"
#include "gfx_msr.c"
#include "gfx_rndr.c"
#include "gfx_mode.h"
#include "gfx_disp.c"
#include "gfx_vid.c"
#include "gfx_vip.c"
#include "gfx_dcdr.c"
#include "gfx_i2c.c"
#include "gfx_tv.c"
#include "gfx_vga.c"