1
/* Copyright (c) 2003-2005 Advanced Micro Devices, Inc.
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:
10
* The above copyright notice and this permission notice shall be included in
11
* all copies or substantial portions of the Software.
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
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.
27
* This is the main file used to add Durango graphics support to a software
28
* project. The main reason to have a single file include the other files
29
* is that it centralizes the location of the compiler options. This file
30
* should be tuned for a specific implementation, and then modified as needed
31
* for new Durango releases. The releases.txt file indicates any updates to
32
* this main file, such as a new definition for a new hardware platform.
34
* In other words, this file should be copied from the Durango source files
35
* once when a software project starts, and then maintained as necessary.
36
* It should not be recopied with new versions of Durango unless the
37
* developer is willing to tune the file again for the specific project.
48
#define GU2_WAIT_PENDING \
49
while(READ_GP32(MGP_BLT_STATUS) & MGP_BS_BLT_PENDING)
50
#define GU2_WAIT_HALF_EMPTY \
51
while(!(READ_GP32(MGP_BLT_STATUS) & MGP_BS_HALF_EMPTY))
53
extern unsigned long gu2_pitch;
54
extern unsigned long gu2_xshift;
55
extern unsigned short GFXpatternFlags;
56
extern unsigned long gu2_rop32;
57
extern unsigned short gu2_blt_mode;
59
void gfx_write_reg8(unsigned long offset, unsigned char value);
60
void gfx_write_reg16(unsigned long offset, unsigned short value);
61
void gfx_write_reg32(unsigned long offset, unsigned long value);
62
unsigned short gfx_read_reg16(unsigned long offset);
63
unsigned long gfx_read_reg32(unsigned long offset);
64
void gfx_write_vid32(unsigned long offset, unsigned long value);
65
unsigned long gfx_read_vid32(unsigned long offset);
66
unsigned long gfx_read_vip32(unsigned long offset);
67
void gfx_write_vip32(unsigned long offset, unsigned long value);
68
void gfx_mono_bitmap_to_screen_blt_swp(unsigned short srcx,
73
unsigned short height,
74
unsigned char *data, short pitch);
75
unsigned int GetVideoMemSize(void);
77
/* ROUTINES added accessing hardware reg */
79
gfx_write_reg8(unsigned long offset, unsigned char value)
81
WRITE_REG8(offset, value);
85
gfx_write_reg16(unsigned long offset, unsigned short value)
87
WRITE_REG16(offset, value);
91
gfx_write_reg32(unsigned long offset, unsigned long value)
93
WRITE_REG32(offset, value);
97
gfx_read_reg16(unsigned long offset)
101
value = READ_REG16(offset);
106
gfx_read_reg32(unsigned long offset)
110
value = READ_REG32(offset);
115
gfx_write_vid32(unsigned long offset, unsigned long value)
117
WRITE_VID32(offset, value);
121
gfx_read_vid32(unsigned long offset)
125
value = READ_VID32(offset);
129
/*Addition for the VIP code */
131
gfx_read_vip32(unsigned long offset)
135
value = READ_VIP32(offset);
140
gfx_write_vip32(unsigned long offset, unsigned long value)
142
WRITE_VIP32(offset, value);
145
#define SWAP_BITS_IN_BYTES(v) \
146
(((0x01010101 & (v)) << 7) | ((0x02020202 & (v)) << 5) | \
147
((0x04040404 & (v)) << 3) | ((0x08080808 & (v)) << 1) | \
148
((0x10101010 & (v)) >> 1) | ((0x20202020 & (v)) >> 3) | \
149
((0x40404040 & (v)) >> 5) | ((0x80808080 & (v)) >> 7))
151
#define WRITE_GPREG_STRING32_SWP(regoffset, dwords, \
152
counter, array, array_offset, temp) \
154
temp = (unsigned long)array + (array_offset); \
155
for (counter = 0; counter < dwords; counter++) \
156
WRITE_GP32 (regoffset, \
157
SWAP_BITS_IN_BYTES(*((unsigned long *)temp + counter))); \
161
gfx_mono_bitmap_to_screen_blt_swp(unsigned short srcx, unsigned short srcy,
162
unsigned short dstx, unsigned short dsty,
163
unsigned short width, unsigned short height,
164
unsigned char *data, short pitch)
166
unsigned long dstoffset, size, bytes;
167
unsigned long offset, temp_offset, temp1 = 0, temp2 = 0;
168
unsigned long i, j = 0, fifo_lines, dwords_extra, bytes_extra;
169
unsigned long shift = 0;
171
size = (((unsigned long) width) << 16) | height;
173
/* CALCULATE STARTING OFFSETS */
175
offset = (unsigned long) srcy *pitch + ((unsigned long) srcx >> 3);
177
dstoffset = (unsigned long) dsty *gu2_pitch +
178
(((unsigned long) dstx) << gu2_xshift);
180
/* CHECK IF PATTERN ORIGINS NEED TO BE SET */
182
if (GFXpatternFlags) {
183
/* COMBINE X AND Y PATTERN ORIGINS WITH OFFSET */
185
dstoffset |= ((unsigned long) (dstx & 7)) << 26;
186
dstoffset |= ((unsigned long) (dsty & 7)) << 29;
189
bytes = ((srcx & 7) + width + 7) >> 3;
190
fifo_lines = bytes >> 5;
191
dwords_extra = (bytes & 0x0000001Cl) >> 2;
192
bytes_extra = bytes & 0x00000003l;
194
/* POLL UNTIL ABLE TO WRITE TO THE REGISTERS */
195
/* Put off poll for as long as possible (do most calculations first). */
196
/* The source offset is always 0 since we allow misaligned dword reads. */
197
/* Need to wait for busy instead of pending, since hardware clears */
198
/* the host data FIFO at the beginning of a BLT. */
201
WRITE_GP32(MGP_RASTER_MODE, gu2_rop32);
202
WRITE_GP32(MGP_SRC_OFFSET, ((unsigned long) srcx & 7) << 26);
203
WRITE_GP32(MGP_DST_OFFSET, dstoffset);
204
WRITE_GP32(MGP_WID_HEIGHT, size);
205
WRITE_GP32(MGP_STRIDE, gu2_pitch);
206
WRITE_GP16(MGP_BLT_MODE, gu2_blt_mode | MGP_BM_SRC_HOST | MGP_BM_SRC_MONO);
208
/* WAIT FOR BLT TO BE LATCHED */
212
/* WRITE ALL OF THE DATA TO THE HOST SOURCE REGISTER */
215
temp_offset = offset;
217
/* WRITE ALL FULL FIFO LINES */
219
for (i = 0; i < fifo_lines; i++) {
221
WRITE_GPREG_STRING32_SWP(MGP_HST_SOURCE, 8, j, data, temp_offset,
226
/* WRITE ALL FULL DWORDS */
230
WRITE_GPREG_STRING32_SWP(MGP_HST_SOURCE, dwords_extra, i, data,
232
temp_offset += (dwords_extra << 2);
235
/* WRITE REMAINING BYTES */
239
WRITE_GPREG_STRING8(MGP_HST_SOURCE, bytes_extra, shift, i, data,
240
temp_offset, temp1, temp2);
247
GetVideoMemSize(void)
249
unsigned int graphicsMemBaseAddr;
250
unsigned int totalMem = 0;
252
unsigned int graphicsMemMask, graphicsMemShift;
253
unsigned int mcBankCfg = gfx_read_reg32(0x8408);
254
unsigned int dimmShift = 4;
256
/* Read graphics base address. */
258
graphicsMemBaseAddr = gfx_read_reg32(0x8414);
260
graphicsMemMask = 0x7FF;
261
graphicsMemShift = 19;
263
/* Calculate total memory size for GXm. */
265
for (i = 0; i < 2; i++) {
266
if (((mcBankCfg >> dimmShift) & 0x7) != 0x7) {
267
switch ((mcBankCfg >> (dimmShift + 4)) & 0x7) {
269
totalMem += 0x400000;
272
totalMem += 0x800000;
275
totalMem += 0x1000000;
278
totalMem += 0x2000000;
281
totalMem += 0x4000000;
284
totalMem += 0x8000000;
287
totalMem += 0x10000000;
290
totalMem += 0x20000000;
299
/* Calculate graphics memory base address */
301
graphicsMemBaseAddr &= graphicsMemMask;
302
graphicsMemBaseAddr <<= graphicsMemShift;
304
return (totalMem - graphicsMemBaseAddr);