~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/kdrive/vesa/vga.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
Import upstream version 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $RCSId: xc/programs/Xserver/hw/kdrive/vesa/vga.c,v 1.1 2000/10/20 00:19:51 keithp Exp $
 
3
 *
 
4
 * Copyright � 2000 Keith Packard
 
5
 *
 
6
 * Permission to use, copy, modify, distribute, and sell this software and its
 
7
 * documentation for any purpose is hereby granted without fee, provided that
 
8
 * the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the name of Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
 
 
25
#ifdef HAVE_CONFIG_H
 
26
#include <kdrive-config.h>
 
27
#endif
 
28
#include "vesa.h"
 
29
 
 
30
static const VesaModeRec vgaModes[] = {
 
31
    {
 
32
        6,  0,
 
33
        MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_LINEAR,
 
34
        1, 1, MEMORY_PLANAR, 
 
35
        0, 0, 0, 0, 0, 0, 0, 0, 0,
 
36
        640, 200, 80,
 
37
    },
 
38
    {
 
39
        0xd, 0,
 
40
        MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
 
41
        4, 4, MEMORY_PLANAR, 
 
42
        0, 0, 0, 0, 0, 0, 0, 0, 0,
 
43
        320, 200, 40,
 
44
    },
 
45
    {
 
46
        0xe, 0,
 
47
        MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
 
48
        4, 4, MEMORY_PLANAR, 
 
49
        0, 0, 0, 0, 0, 0, 0, 0, 0,
 
50
        640, 200, 80,
 
51
    },
 
52
    {
 
53
        0x10, 0,
 
54
        MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
 
55
        4, 4, MEMORY_PLANAR, 
 
56
        0, 0, 0, 0, 0, 0, 0, 0, 0,
 
57
        640, 350, 80,
 
58
    },
 
59
    {
 
60
        0x11, 0,
 
61
        MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_LINEAR,
 
62
        1, 1, MEMORY_PLANAR, 
 
63
        0, 0, 0, 0, 0, 0, 0, 0, 0,
 
64
        640, 480, 80,
 
65
    },
 
66
    {
 
67
        0x12, 0,
 
68
        MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
 
69
        4, 4, MEMORY_PLANAR, 
 
70
        0, 0, 0, 0, 0, 0, 0, 0, 0,
 
71
        640, 480, 80,
 
72
    },
 
73
    {
 
74
        0x13, 0,
 
75
        MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR | MODE_LINEAR,
 
76
        8, 8, MEMORY_PSEUDO,
 
77
        0, 0, 0, 0, 0, 0, 0, 0, 0,
 
78
        320, 200, 320,
 
79
    },
 
80
};
 
81
 
 
82
#define NUM_VGA_MODE    (sizeof vgaModes / sizeof vgaModes[0])
 
83
 
 
84
int
 
85
VgaGetNmode (Vm86InfoPtr vi)
 
86
{
 
87
    return NUM_VGA_MODE;
 
88
}
 
89
 
 
90
int
 
91
VgaGetModes (Vm86InfoPtr vi, VesaModePtr mode, int nmode)
 
92
{
 
93
    if (nmode > NUM_VGA_MODE)
 
94
        nmode = NUM_VGA_MODE;
 
95
    memcpy (mode, vgaModes, nmode * sizeof (VesaModeRec));
 
96
    return nmode;
 
97
}
 
98
 
 
99
int
 
100
VgaSetMode(Vm86InfoPtr vi, int mode)
 
101
{
 
102
    int code;
 
103
    
 
104
    vi->vms.regs.eax = mode & 0x7f;
 
105
    code = Vm86DoInterrupt (vi, 0x10);
 
106
    if(code < 0)
 
107
        return -1;
 
108
    return 0;
 
109
}
 
110
 
 
111
int
 
112
VgaGetMode (Vm86InfoPtr vi, int *mode)
 
113
{
 
114
    *mode = Vm86Memory (vi, 0x449);
 
115
    return 0;
 
116
}
 
117
 
 
118
void
 
119
VgaSetWritePlaneMask(Vm86InfoPtr vi, int mask)
 
120
{
 
121
    asm volatile ("outb %b0,%w1" : : "a" (2), "d" (0x3c4));
 
122
    asm volatile ("outb %b0,%w1" : : "a" (mask), "d" (0x3c5));
 
123
}
 
124
 
 
125
void
 
126
VgaSetReadPlaneMap(Vm86InfoPtr vi, int map)
 
127
{
 
128
    asm volatile ("outb %b0,%w1" : : "a" (4), "d" (0x3ce));
 
129
    asm volatile ("outb %b0,%w1" : : "a" (map), "d" (0x3cf));
 
130
}
 
131
 
 
132
int 
 
133
VgaSetPalette(Vm86InfoPtr vi, int first, int number, U8 *entries)
 
134
{
 
135
    U8      *palette_scratch;
 
136
    int     mark;
 
137
    int     palette_base;
 
138
    int     i, j, code;
 
139
 
 
140
    if(number == 0)
 
141
        return 0;
 
142
 
 
143
    if(first < 0 || number < 0 || first + number > 256) {
 
144
        ErrorF("Cannot set %d, %d palette entries\n", first, number);
 
145
        return -1;
 
146
    }
 
147
 
 
148
    mark = Vm86MarkMemory (vi);
 
149
    palette_base = Vm86AllocateMemory (vi, 3 * 256);
 
150
    
 
151
    palette_scratch = &LM(vi, palette_base);
 
152
 
 
153
    vi->vms.regs.eax = 0x1012;
 
154
    vi->vms.regs.ebx = first;
 
155
    vi->vms.regs.ecx = number;
 
156
    vi->vms.regs.es = POINTER_SEGMENT(palette_base);
 
157
    vi->vms.regs.edx = POINTER_OFFSET(palette_base);
 
158
    j = 0;
 
159
    i = 0;
 
160
    while (number--)
 
161
    {
 
162
        palette_scratch[j++] = entries[i++] >> 2;
 
163
        palette_scratch[j++] = entries[i++] >> 2;
 
164
        palette_scratch[j++] = entries[i++] >> 2;
 
165
        i++;
 
166
    }
 
167
    code = Vm86DoInterrupt(vi, 0x10);
 
168
    Vm86ReleaseMemory (vi, mark);
 
169
    
 
170
    if(code < 0)
 
171
        return -1;
 
172
    return 0;
 
173
}
 
174
        
 
175
int 
 
176
VgaGetPalette(Vm86InfoPtr vi, int first, int number, U8 *entries)
 
177
{
 
178
    U8      *palette_scratch;
 
179
    int     mark;
 
180
    int     palette_base;
 
181
    int     i, j, code;
 
182
 
 
183
    if(number == 0)
 
184
        return 0;
 
185
 
 
186
    if(first < 0 || number < 0 || first + number > 256) {
 
187
        ErrorF("Cannot get %d, %d palette entries\n", first, number);
 
188
        return -1;
 
189
    }
 
190
 
 
191
    mark = Vm86MarkMemory (vi);
 
192
    palette_base = Vm86AllocateMemory (vi, 3 * 256);
 
193
    
 
194
    palette_scratch = &LM(vi, palette_base);
 
195
 
 
196
    vi->vms.regs.eax = 0x1017;
 
197
    vi->vms.regs.ebx = first;
 
198
    vi->vms.regs.ecx = number;
 
199
    vi->vms.regs.es = POINTER_SEGMENT(palette_base);
 
200
    vi->vms.regs.edx = POINTER_OFFSET(palette_base);
 
201
    
 
202
    code = VbeDoInterrupt10(vi);
 
203
    if(code < 0)
 
204
        return -1;
 
205
    
 
206
    j = 0;
 
207
    i = 0;
 
208
    while (number--)
 
209
    {
 
210
        entries[i++] = palette_scratch[j++] << 2;
 
211
        entries[i++] = palette_scratch[j++] << 2;
 
212
        entries[i++] = palette_scratch[j++] << 2;
 
213
        entries[i++] = 0;
 
214
    }
 
215
    
 
216
    Vm86ReleaseMemory (vi, mark);
 
217
 
 
218
    return 0;
 
219
}   
 
220
        
 
221
#define VGA_FB(vm)  ((vm) < 8 ? 0xb8000 : 0xa0000)
 
222
 
 
223
void *
 
224
VgaSetWindow (Vm86InfoPtr vi, int vmode, int bytes, int mode, int *size)
 
225
{
 
226
    *size = 0x10000 - bytes;
 
227
    return &LM(vi,VGA_FB(vmode) + bytes);
 
228
}
 
229
 
 
230
void *
 
231
VgaMapFramebuffer (Vm86InfoPtr vi, int vmode, int *size, CARD32 *ret_phys)
 
232
{
 
233
    if (VGA_FB(vmode) == 0xa0000)
 
234
        *size = 0x10000;
 
235
    else
 
236
        *size = 0x4000;
 
237
    *ret_phys = VGA_FB(vmode);
 
238
    return &LM(vi,VGA_FB(vmode));
 
239
}
 
240
 
 
241
void
 
242
VgaUnmapFramebuffer (Vm86InfoPtr vi)
 
243
{
 
244
}