summaryrefslogtreecommitdiff
path: root/src/atibank.c
blob: c53cc5454aa6bc5e34c0883210072a4c4b1b4ee0 (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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
 * Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of Marc Aurele La France not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  Marc Aurele La France makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as-is" without express or implied warranty.
 *
 * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO
 * EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

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

#include "ati.h"
#include "atibank.h"
#include "atimach64io.h"
#include "atiwonderio.h"

#ifndef AVOID_CPIO

/*
 * ATI VGA Wonder V4 and V5 adapters use an ATI 18800-1 chip.  Bank selection
 * is done with ATI extended VGA register index 0xB2.  The format is:
 *
 *   0xE0 - Read bank select bits 0x07
 *   0x1E - Write bank select bits 0x0F
 *   0x01 - Read bank select bit 0x08.
 */

/*
 * ATIV4V5SetBank --
 *
 * Set an ATI 18800-1's read and write bank numbers.
 */
void
ATIV4V5SetBank
(
    ATIPtr       pATI,
    unsigned int iBank
)
{
    pATI->B2Reg = SetBits(iBank, 0x1EU) | SetBits(iBank, 0xE0U) |
        SetBits(GetBits(iBank, 0x08U), 0x01U);
    ATIPutExtReg(0xB2U, pATI->B2Reg);
}

/*
 * ATIV4V5SetRead --
 *
 * Set an ATI 18800-1's read bank number.
 */
int
ATIV4V5SetRead
(
    ScreenPtr    pScreen,
    unsigned int iBank
)
{
    ATIPtr pATI  = ATIPTR(XF86SCRNINFO(pScreen));
    CARD8  B2Reg = (pATI->B2Reg & 0x1EU) | SetBits(iBank, 0xE0U) |
                   SetBits(GetBits(iBank, 0x08U), 0x01U);

    if (B2Reg != pATI->B2Reg)
    {
        ATIPutExtReg(0xB2U, B2Reg);
        pATI->B2Reg = B2Reg;
    }

    return 0;
}

/*
 * ATIV4V5SetWrite --
 *
 * Set an ATI 18800-1's write bank number.
 */
int
ATIV4V5SetWrite
(
    ScreenPtr    pScreen,
    unsigned int iBank
)
{
    ATIPtr pATI = ATIPTR(XF86SCRNINFO(pScreen));
    CARD8  B2Reg = (pATI->B2Reg & 0xE1U) | SetBits(iBank, 0x1EU);

    if (B2Reg != pATI->B2Reg)
    {
        ATIPutExtReg(0xB2U, B2Reg);
        pATI->B2Reg = B2Reg;
    }
    return 0;
}

/*
 * In addition to ATI extended register index 0xB2, 28800's, 68800's and
 * 88800's define banking bits in bits 0x0F of ATI extended VGA register index
 * 0xAE.  These are only needed for adapters with more than 1MB of video
 * memory, and it is questionable whether or not they are actually implemented
 * by 28800's and 88800's.  ATI extended VGA register index 0xAE is defined as
 * follows:
 *
 *    0xF0 - reserved
 *    0x0C - read bank select bits 0x30
 *    0x03 - write bank select bits 0x30
 */

/*
 * ATIx8800SetBank --
 *
 * Set an ATI 28800's, 68800's or 88800's read and write bank numbers.
 */
void
ATIx8800SetBank
(
    ATIPtr       pATI,
    unsigned int iBank
)
{
    ATIV4V5SetBank(pATI, iBank);
    iBank = GetBits(iBank, 0x30U);
    ATIModifyExtReg(pATI, 0xAEU, -1, (CARD8)(~0x0FU),
        SetBits(iBank, 0x03U) | SetBits(iBank, 0x0CU));
}

/*
 * ATIx8800SetRead --
 *
 * Set an ATI 28800's, 68800's or 88800's read bank numbers.
 */
int
ATIx8800SetRead
(
    ScreenPtr    pScreen,
    unsigned int iBank
)
{
    (void)ATIV4V5SetRead(pScreen, iBank);
    ATIModifyExtReg(ATIPTR(XF86SCRNINFO(pScreen)), 0xAEU, -1, (CARD8)(~0x0CU),
        SetBits(GetBits(iBank, 0x30U), 0x0CU));
    return 0;
}

/*
 * ATIx8800SetWrite --
 *
 * Set an ATI 28800's, 68800's or 88800's write bank numbers.
 */
int
ATIx8800SetWrite
(
    ScreenPtr    pScreen,
    unsigned int iBank
)
{
    (void)ATIV4V5SetWrite(pScreen, iBank);
    ATIModifyExtReg(ATIPTR(XF86SCRNINFO(pScreen)), 0xAEU, -1, (CARD8)(~0x03U),
        SetBits(GetBits(iBank, 0x30U), 0x03U));
    return 0;
}

/*
 * ATIx8800SetReadWrite --
 *
 * Set an ATI 28800's, 68800's or 88800's read and write bank numbers.
 */
int
ATIx8800SetReadWrite
(
    ScreenPtr    pScreen,
    unsigned int iBank
)
{
    ATIx8800SetBank(ATIPTR(XF86SCRNINFO(pScreen)), iBank);
    return 0;
}

/*
 * Functions to simulate a banked VGA aperture using a Mach64's small dual
 * paged apertures.  There are two sets of these:  one for packed modes, the
 * other for planar modes.
 */

static CARD32
ATIMach64MassagePackedBankNumber
(
    CARD8 iBank
)
{
    iBank <<= 1;
    return ((iBank + 1) << 16) | iBank;
}

/*
 * ATIMach64SetBankPacked --
 *
 * Set read and write bank numbers for small dual paged apertures.
 */
void
ATIMach64SetBankPacked
(
    ATIPtr       pATI,
    unsigned int iBank
)
{
    CARD32 tmp = ATIMach64MassagePackedBankNumber(iBank);

    outr(MEM_VGA_RP_SEL, tmp);
    outr(MEM_VGA_WP_SEL, tmp);
}

/*
 * ATIMach64SetReadPacked --
 *
 * Set read bank number for small dual paged apertures.
 */
int
ATIMach64SetReadPacked
(
    ScreenPtr    pScreen,
    unsigned int iBank
)
{
    ATIPtr pATI = ATIPTR(XF86SCRNINFO(pScreen));

    outr(MEM_VGA_RP_SEL, ATIMach64MassagePackedBankNumber(iBank));
    return 0;
}

/*
 * ATIMach64SetWritePacked --
 *
 * Set write bank number for small dual paged apertures.
 */
int
ATIMach64SetWritePacked
(
    ScreenPtr    pScreen,
    unsigned int iBank
)
{
    ATIPtr pATI = ATIPTR(XF86SCRNINFO(pScreen));

    outr(MEM_VGA_WP_SEL, ATIMach64MassagePackedBankNumber(iBank));
    return 0;
}

/*
 * ATIMach64SetReadWritePacked --
 *
 * Set read and write bank numbers for small dual paged apertures.
 */
int
ATIMach64SetReadWritePacked
(
    ScreenPtr    pScreen,
    unsigned int iBank
)
{
    ATIMach64SetBankPacked(ATIPTR(XF86SCRNINFO(pScreen)), iBank);
    return 0;
}

static CARD32
ATIMach64MassagePlanarBankNumber
(
    CARD8 iBank
)
{
    iBank <<= 3;
    return ((iBank + 4) << 16) | iBank;
}

/*
 * ATIMach64SetBankPlanar --
 *
 * Set read and write bank numbers for small dual paged apertures.
 */
void
ATIMach64SetBankPlanar
(
    ATIPtr       pATI,
    unsigned int iBank
)
{
    CARD32 tmp = ATIMach64MassagePlanarBankNumber(iBank);

    outr(MEM_VGA_RP_SEL, tmp);
    outr(MEM_VGA_WP_SEL, tmp);
}

#endif /* AVOID_CPIO */