-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCHIPSET.C
More file actions
288 lines (228 loc) · 9.87 KB
/
CHIPSET.C
File metadata and controls
288 lines (228 loc) · 9.87 KB
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
#include "chipset.h"
#include "pci.h"
#include "vgacon.h"
#include "util.h"
#define __LIB866D_TAG__ "CHIPSET"
#include "debug.h"
#define retPrintErrorIf(condition, message, value) if (condition) { vgacon_printError(message "\n", value); return false; }
/* Function pointer to tweaking action for each chipset */
typedef bool (*chipsetTweakHandler)(const chipset_GfxTweakConfig*, pci_Device);
typedef struct {
u16 vendor;
u16 device;
const char *name;
chipsetTweakHandler handler;
} chipset_KnownChipset;
/* ALI ALADDIN IV/V:
The lower 3 bits of the "PCI Programmable Frame Buffer Memory Region" register
maps to the size of the framebuffer.
Officially this ends at 100 (-> 16MB) but I suspect
that it actually supports bigger ones. */
static u16 aliGetFbSizeRegValue(u32 sizeKB) {
u32 sizeMB = sizeKB / 1024UL;
u16 ret = 0;
if (sizeMB > 16) {
vgacon_printWarning("Frame Buffer size > 16MB not officially supported by chipset!\n");
} else if (sizeMB > 128) {
vgacon_printWarning("Frame Buffer (%lu MB) too big! Clamping to 128MB\n", sizeMB);
return 0x7;
}
while ((1 << ret) < (u16) sizeMB) {
ret++;
}
return ret;
}
/* ALI ALADDIN III / IV: Write registers to enable Frame Buffer cycles for given parameters */
static bool aliWriteAladdin34Regs(u32 offset, u32 sizeKB, bool vgaFb, pci_Device pciDev) {
struct { /* Bitfield for register 54-55, PCI Programmable Frame Buffer Memory Region */
u16 fbSize : 3;
u16 __rsvd : 1;
u16 a31_20 : 12;
} fbMemReg;
struct { /* Bitfield for register 56, CPU to PCI Write Buffer Option */
u8 fbEnable : 1;
u8 vgaFbEnable : 1;
u8 pciWriteBurst : 1;
u8 pciFastBackToBack: 1;
u8 fbByteMerge : 1;
u8 fbWordMerge : 1;
u8 fbLinearMerge : 1;
u8 allPCIMemory : 1;
} cpuPciWriteBufferReg;
fbMemReg.a31_20 = (u16) (offset >> 20UL);
fbMemReg.fbSize = aliGetFbSizeRegValue(sizeKB);
fbMemReg.__rsvd = 0;
cpuPciWriteBufferReg.fbEnable = true;
cpuPciWriteBufferReg.vgaFbEnable = vgaFb;
cpuPciWriteBufferReg.pciWriteBurst = true;
cpuPciWriteBufferReg.pciFastBackToBack = true;
cpuPciWriteBufferReg.fbByteMerge = true;
cpuPciWriteBufferReg.fbWordMerge = true;
cpuPciWriteBufferReg.fbLinearMerge = false;
cpuPciWriteBufferReg.allPCIMemory = false;
pci_writeBytes(pciDev, &fbMemReg, 0x54, 2);
pci_writeBytes(pciDev, &cpuPciWriteBufferReg, 0x56, 1);
}
/* ALI ALADDIN V: Write registers to enable Frame Buffer cycles for given parameters */
static bool aliWriteAladdin5Regs(u32 offset, u32 sizeKB, bool vgaFb, pci_Device pciDev) {
struct { /* Bitfield for register 84/85, PCI Programmable Frame Buffer Memory Region */
u16 fbSize : 3;
u16 allPCIMemory : 1;
u16 a31_20 : 12;
} fbMemReg;
struct { /* Bitfield for register 86, CPU to PCI Write Buffer Option */
u8 fbEnable : 1;
u8 vgaFbEnable : 1;
u8 fbPciWriteBurst : 1;
u8 fbLinearMerge : 1;
u8 __rsvd : 4;
} cpuPciWriteBufferReg;
pci_Device secondaryDev;
bool secondaryDevFound = pci_findDevByID(0x10b9, 0x5243, &secondaryDev);
L866_ASSERT(secondaryDevFound);
fbMemReg.a31_20 = (u16) (offset >> 20UL);
fbMemReg.fbSize = aliGetFbSizeRegValue(sizeKB);
fbMemReg.allPCIMemory = false;
cpuPciWriteBufferReg.fbEnable = true;
cpuPciWriteBufferReg.vgaFbEnable = vgaFb;
cpuPciWriteBufferReg.fbPciWriteBurst = true;
cpuPciWriteBufferReg.fbLinearMerge = false;
cpuPciWriteBufferReg.__rsvd = 0;
pci_writeBytes(pciDev, &fbMemReg, 0x84, 2);
pci_writeBytes(pciDev, &cpuPciWriteBufferReg, 0x86, 1);
/* PCI Bridge done, do the same for the AGP bridge */
pci_writeBytes(secondaryDev, &fbMemReg, 0x84, 2);
pci_writeBytes(secondaryDev, &cpuPciWriteBufferReg, 0x86, 1);
}
static bool aliAladdinTweaks(const chipset_GfxTweakConfig *cfg, pci_Device pciDev, bool isAladdin5) {
if (cfg->setLfb) {
/* We found a suitable FB region to set up for the chipset */
if (isAladdin5) aliWriteAladdin5Regs (cfg->offset, cfg->sizeKB, cfg->setVgaFb, pciDev);
else aliWriteAladdin34Regs(cfg->offset, cfg->sizeKB, cfg->setVgaFb, pciDev);
} else if (cfg->setVgaFb) {
vgacon_printWarning("This chipset can't do VGA burst cycles without another linear FB region!\n");
}
return true;
}
static bool chipset_aliAladdin34(const chipset_GfxTweakConfig *cfg, pci_Device pciDev) {
return aliAladdinTweaks(cfg, pciDev, false);
}
static bool chipset_aliAladdin5(const chipset_GfxTweakConfig *cfg, pci_Device pciDev) {
return aliAladdinTweaks(cfg, pciDev, true);
}
/* Like Aladdin chipsets; power of 1 boundary.*/
static u16 sisGetFbSizeRegValue(u32 sizeKB) {
u16 ret = 0xFFF;
u16 i = 0;
/* 0b1111111111111111 = 1MB
0b0000000000000000 = 4GB */
while ((1 << i) < (u16) (sizeKB / 1024UL)) {
ret <<= 1;
ret &= 0xFFF;
i++;
}
return ret;
}
static void sisWrite5591Regs(u32 offset, u32 sizeKB, pci_Device pciDev) {
struct { /* Bitfield for register 83, CPU-To-PCI Characteristics Register */
u8 __dontcare1 : 4;
u8 fastBackToBack : 1;
u8 __dontcare2 : 3;
} cpuPciCharacteristicsReg;
struct { /* Bitfield for register 88-89, Frame Buffer Base Register */
u16 __rsvd : 4;
u16 a31_20 : 12;
} fbBaseReg;
struct { /* Bitfield for register 8A-8B, Frame Buffer Size Register */
u16 __rsvd : 4;
u16 fbSizeMask : 12;
} fbSizeReg;
/* PCI bridge parameters register must retain the irrelevant values */
pci_readBytes(pciDev, &cpuPciCharacteristicsReg, 0x83, 1);
cpuPciCharacteristicsReg.fastBackToBack = true;
fbBaseReg.a31_20 = (u16) (offset >> 20UL);
fbBaseReg.__rsvd = 0;
fbSizeReg.fbSizeMask = sisGetFbSizeRegValue(sizeKB);
fbSizeReg.__rsvd = 0;
pci_writeBytes(pciDev, &fbBaseReg, 0x88, 2);
pci_writeBytes(pciDev, &fbSizeReg, 0x8A, 2);
pci_writeBytes(pciDev, &cpuPciCharacteristicsReg, 0x83, 1);
}
static void sisWrite530Regs(u32 offset, u32 sizeKB, pci_Device pciDev) {
struct { /* Bitfield for Prefetchable Memory Base / Limit registers */
u16 __rsvd : 4;
u16 a31_20 : 12;
} pmReg[2];
u32 limit = offset + (sizeKB * 1024UL);
pmReg[0].a31_20 = (u16) (offset >> 20UL);
pmReg[0].__rsvd = 0;
pmReg[1].a31_20 = (u16) (limit >> 20UL);
pmReg[1].__rsvd = 0;
pci_writeBytes(pciDev, &pmReg[0], 0x22, 2);
pci_writeBytes(pciDev, &pmReg[1], 0x24, 2);
}
/* SiS 557, 5581, 5591, 5597 chipset tweaks
5591 calls it PCI Fast back to back frame buffer
5597 and 5581 generically call it "fast back to back area"
registers are the same though. */
static bool chipset_sis559x(const chipset_GfxTweakConfig *cfg, pci_Device pciDev) {
if (cfg->setVgaFb) {
vgacon_printWarning("Chipset does not support VGA region acceleration.\n");
}
if (cfg->setLfb) {
sisWrite5591Regs(cfg->offset, cfg->sizeKB, pciDev);
}
return true;
}
/* SiS 530/540 chipset tweaks
Not sure if this works at all. The datasheet is confusing to read. */
static bool chipset_sis5x0(const chipset_GfxTweakConfig *cfg, pci_Device pciDev) {
if (cfg->setVgaFb) {
vgacon_printWarning("Chipset does not support VGA region acceleration.\n");
}
if (cfg->setLfb) {
sisWrite530Regs(cfg->offset, cfg->sizeKB, pciDev);
}
return true;
}
static const chipset_KnownChipset chipset_knownChipsets[] = {
{ 0x10B9, 0x1521, "ALI Aladdin III", chipset_aliAladdin34 },
{ 0x10B9, 0x1531, "ALI Aladdin IV", chipset_aliAladdin34 },
{ 0x10B9, 0x1541, "ALI Aladdin V", chipset_aliAladdin5 },
{ 0x1039, 0x5571, "SiS 5571", chipset_sis559x },
{ 0x1039, 0x5581, "SiS 5581/5582", chipset_sis559x },
{ 0x1039, 0x5591, "SiS 5591/5592", chipset_sis559x },
{ 0x1039, 0x5597, "SiS 5597/5598", chipset_sis559x },
{ 0x1039, 0x0001, "SiS 530/540", chipset_sis5x0 },
};
bool chipset_doFramebufferTweaks(const chipset_GfxTweakConfig *cfg) {
size_t i;
size_t chipsetCount = ARRAY_SIZE(chipset_knownChipsets);
bool found = false;
L866_NULLCHECK(cfg);
if (!cfg->setLfb && !cfg->setVgaFb) {
/* Leave everything untouched if not wanted */
vgacon_printWarning("Framebuffer setup not requested, nothing to set up in the chipset.\n");
return true;
}
if (!pci_test()) {
vgacon_printWarning("PCI Bus inaccessible, skipping chipset tweaks\n");
return true;
}
for (i = 0; i < chipsetCount; i++) {
const chipset_KnownChipset *cs = &chipset_knownChipsets[i];
pci_Device pciDev;
if (pci_findDevByID(chipset_knownChipsets[i].vendor, chipset_knownChipsets[i].device, &pciDev)) {
L866_NULLCHECK(cs->handler);
vgacon_print("Found supported chipset '%s', applying tweaks...\n", cs->name);
retPrintErrorIf(false == cs->handler(cfg, pciDev), "Error applying tweaks for '%s'!", cs->name);
vgacon_printOK("Chipset register setup successful.\n");
if (cfg->setLfb) {
vgacon_printOK("Frame buffer @ 0x%08lx, size %lu KB\n", cfg->offset, cfg->sizeKB);
}
return true;
}
}
vgacon_printWarning("No supported chipset found; skipping chipset tweaks\n");
return true;
}