Chameleon

Chameleon Commit Details

Date:2010-09-23 15:15:34 (13 years 6 months ago)
Author:Evan Lojewski
Commit:546
Parents: 545
Message:More code shrinkage
Changes:
M/branches/meklort/i386/libsaio/cpu.c
M/branches/meklort/i386/libsaio/platform.h
M/branches/meklort/i386/libsaio/pci.c

File differences

branches/meklort/i386/libsaio/cpu.c
9292
9393
9494
95
9596
9697
9798
......
99100
100101
101102
102
103
104
105
103
104
105
106
107
106108
107109
108110
......
177179
178180
179181
180
181
182
183
184
185
186
187
188
182189
183
184
190
191
192
193
185194
186195
187196
188197
189198
190
199
200
191201
192
202
203
193204
194205
195206
......
198209
199210
200211
201
212
213
214
202215
203216
204217
......
207220
208221
209222
210
223
224
211225
212226
213227
214
228
229
230
215231
216232
217233
218234
219235
220
221
236
237
238
239
222240
223
241
242
243
224244
225245
226
246
247
248
227249
228
250
251
252
229253
230254
231255
......
233257
234258
235259
236
260
261
237262
238263
239264
240265
241
242
266
267
268
269
243270
244271
245272
246
273
274
275
247276
248277
249278
......
252281
253282
254283
255
256
284
285
286
287
257288
258289
259
290
291
292
260293
261294
262295
......
265298
266299
267300
268
301
302
269303
270304
271305
void scan_cpu(PlatformInfo_t *p)
{
int i = 0;
uint64_ttscFrequency, fsbFrequency, cpuFrequency;
uint64_tmsr, flex_ratio;
uint8_tmaxcoef, maxdiv, currcoef, currdiv;
maxcoef = maxdiv = currcoef = currdiv = 0;
/* get cpuid values */
do_cpuid(0x00000000, p->CPU.CPUID[CPUID_0]);
do_cpuid(0x00000001, p->CPU.CPUID[CPUID_1]);
do_cpuid(0x00000002, p->CPU.CPUID[CPUID_2]);
do_cpuid(0x00000003, p->CPU.CPUID[CPUID_3]);
for( ; i < 3; i++)
{
do_cpuid(i, p->CPU.CPUID[i]);
}
do_cpuid2(0x00000004, 0, p->CPU.CPUID[CPUID_4]);
do_cpuid(0x80000000, p->CPU.CPUID[CPUID_80]);
if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) {
fsbFrequency = 0;
cpuFrequency = 0;
if ((p->CPU.Vendor == 0x756E6547 /* Intel */) && ((p->CPU.Family == 0x06) || (p->CPU.Family == 0x0f))) {
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0c) || (p->CPU.Family == 0x0f && p->CPU.Model >= 0x03)) {
if ((p->CPU.Vendor == 0x756E6547 /* Intel */) &&
((p->CPU.Family == 0x06) ||
(p->CPU.Family == 0x0f)))
{
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0c) ||
(p->CPU.Family == 0x0f && p->CPU.Model >= 0x03))
{
/* Nehalem CPU model */
if (p->CPU.Family == 0x06 && (p->CPU.Model == 0x1a || p->CPU.Model == 0x1e
|| p->CPU.Model == 0x1f || p->CPU.Model == 0x25 || p->CPU.Model == 0x2c)) {
if (p->CPU.Family == 0x06 && (p->CPU.Model == 0x1a || p->CPU.Model == 0x1e ||
p->CPU.Model == 0x1f || p->CPU.Model == 0x25 ||
p->CPU.Model == 0x2c))
{
msr = rdmsr64(MSR_PLATFORM_INFO);
DBG("msr(%d): platform_info %08x\n", __LINE__, msr & 0xffffffff);
currcoef = (msr >> 8) & 0xff;
msr = rdmsr64(MSR_FLEX_RATIO);
DBG("msr(%d): flex_ratio %08x\n", __LINE__, msr & 0xffffffff);
if ((msr >> 16) & 0x01) {
if ((msr >> 16) & 0x01)
{
flex_ratio = (msr >> 8) & 0xff;
if (currcoef > flex_ratio) {
if (currcoef > flex_ratio)
{
currcoef = flex_ratio;
}
}
fsbFrequency = (tscFrequency / currcoef);
}
cpuFrequency = tscFrequency;
} else {
}
else
{
msr = rdmsr64(MSR_IA32_PERF_STATUS);
DBG("msr(%d): ia32_perf_stat 0x%08x\n", __LINE__, msr & 0xffffffff);
currcoef = (msr >> 8) & 0x1f;
/* Non-integer bus ratio for the current-multi (undocumented)*/
currdiv = (msr >> 14) & 0x01;
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f)) // This will always be model >= 3
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) ||
(p->CPU.Family == 0x0f)) // This will always be model >= 3
{
/* On these models, maxcoef defines TSC freq */
maxcoef = (msr >> 40) & 0x1f;
} else {
}
else
{
/* On lower models, currcoef defines TSC freq */
/* XXX */
maxcoef = currcoef;
}
if (maxcoef) {
if (maxdiv) {
if (maxcoef)
{
if (maxdiv)
{
fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1));
} else {
}
else
{
fsbFrequency = (tscFrequency / maxcoef);
}
if (currdiv) {
if (currdiv)
{
cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2);
} else {
}
else
{
cpuFrequency = (fsbFrequency * currcoef);
}
DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : "");
}
}
/* Mobile CPU ? */
if (rdmsr64(0x17) & (1<<28)) {
if (rdmsr64(0x17) & (1<<28))
{
p->CPU.Features |= CPU_FEATURE_MOBILE;
}
}
#if 0
else if((p->CPU.Vendor == 0x68747541 /* AMD */) && (p->CPU.Family == 0x0f)) {
if(p->CPU.ExtFamily == 0x00 /* K8 */) {
else if((p->CPU.Vendor == 0x68747541 /* AMD */) && (p->CPU.Family == 0x0f))
{
if(p->CPU.ExtFamily == 0x00 /* K8 */)
{
msr = rdmsr64(K8_FIDVID_STATUS);
currcoef = (msr & 0x3f) / 2 + 4;
currdiv = (msr & 0x01) * 2;
} else if(p->CPU.ExtFamily >= 0x01 /* K10+ */) {
}
else if(p->CPU.ExtFamily >= 0x01 /* K10+ */)
{
msr = rdmsr64(K10_COFVID_STATUS);
if(p->CPU.ExtFamily == 0x01 /* K10 */)
currcoef = (msr & 0x3f) + 0x10;
currdiv = (2 << ((msr >> 6) & 0x07));
}
if (currcoef) {
if (currdiv) {
if (currcoef)
{
if (currdiv)
{
fsbFrequency = ((tscFrequency * currdiv) / currcoef);
DBG("%d.%d\n", currcoef / currdiv, ((currcoef % currdiv) * 100) / currdiv);
} else {
}
else
{
fsbFrequency = (tscFrequency / currcoef);
DBG("%d\n", currcoef);
}
}
}
if (!fsbFrequency) {
if (!fsbFrequency)
{
fsbFrequency = (DEFAULT_FSB * 1000);
cpuFrequency = tscFrequency;
DBG("0 ! using the default value for FSB !\n");
branches/meklort/i386/libsaio/platform.h
5151
5252
5353
54
54
55
5556
5657
5758
#define CPU_FEATURE_EM64Tbit(29)// 64Bit Support
#define CPU_FEATURE_HTTbit(28)// HyperThreading
#define CPU_FEATURE_MSRbit(5)// MSR Support
// NOTE: Determine correc tbit for bellow
// NOTE: Determine correct bit for bellow (28 is already in use)
#define CPU_FEATURE_MOBILEbit(1)// Mobile CPU
branches/meklort/i386/libsaio/pci.c
2020
2121
2222
23
2324
2425
2526
......
7475
7576
7677
77
78
79
78
79
80
81
82
8083
8184
82
85
86
8387
8488
8589
......
8993
9094
9195
92
96
9397
94
95
96
97
98
99
100
101
98
99
100
101
102
103
104
105
106
107
102108
103109
104110
105
106
111
112
113
107114
108115
109116
......
114121
115122
116123
117
124
118125
119126
120127
......
130137
131138
132139
140
133141
134142
135143
......
140148
141149
142150
143
144151
145152
146153
147154
148155
149
156
150157
151158
152159
......
160167
161168
162169
163
164
170
171
172
173
165174
166
175
167176
168177
169178
170179
171180
172181
182
173183
174184
175185
176
186
177187
178
188
189
179190
180
181
182
191
192
193
183194
184195
185196
186197
198
#endif
pci_dt_t*root_pci_dev;
static char* dev_path;
uint8_t pci_config_read8(uint32_t pci_addr, uint8_t reg)
uint8_tfunc;
uint8_tsecondary_bus;
uint8_theader_type;
for (dev = 0; dev < 32; dev++) {
for (func = 0; func < 8; func++) {
for (dev = 0; dev < 32; dev++)
{
for (func = 0; func < 8; func++)
{
pci_addr = PCIADDR(bus, dev, func);
id = pci_config_read32(pci_addr, PCI_VENDOR_ID);
if (!id || id == 0xffffffff) {
if (!id || id == 0xffffffff)
{
continue;
}
new = (pci_dt_t*)malloc(sizeof(pci_dt_t));
new->device_id= (id >> 16) & 0xffff;
new->class_id= pci_config_read16(pci_addr, PCI_CLASS_DEVICE);
new->parent= start;
header_type = pci_config_read8(pci_addr, PCI_HEADER_TYPE);
switch (header_type & 0x7f) {
case PCI_HEADER_TYPE_BRIDGE:
case PCI_HEADER_TYPE_CARDBUS:
secondary_bus = pci_config_read8(pci_addr, PCI_SECONDARY_BUS);
if (secondary_bus != 0) {
scan_pci_bus(new, secondary_bus);
}
break;
switch (header_type & 0x7f)
{
case PCI_HEADER_TYPE_BRIDGE:
case PCI_HEADER_TYPE_CARDBUS:
secondary_bus = pci_config_read8(pci_addr, PCI_SECONDARY_BUS);
if (secondary_bus != 0)
{
scan_pci_bus(new, secondary_bus);
}
break;
}
*current = new;
current = &new->next;
if ((func == 0) && ((header_type & 0x80) == 0)) {
if ((func == 0) && ((header_type & 0x80) == 0))
{
break;
}
}
{
uint16_t id;
uint32_t rcba, *fd;
id = pci_config_read16(PCIADDR(0, 0x00, 0), 0x00);
/* make sure we're on Intel chipset */
if (id != 0x8086)
void build_pci_dt(void)
{
dev_path = malloc(sizeof(char) * 256);
root_pci_dev = malloc(sizeof(pci_dt_t));
bzero(root_pci_dev, sizeof(pci_dt_t));
enable_pci_devs();
#endif
}
static char dev_path[256];
char *get_pci_dev_path(pci_dt_t *pci_dt)
{
pci_dt_t*current;
pci_dt_t*end;
chartmp[64];
dev_path[0] = 0;
end = root_pci_dev;
if (current->parent == root_pci_dev)
{
sprintf(tmp, "PciRoot(0x%x)/Pci(0x%x,0x%x)", uid,
current->dev.bits.dev, current->dev.bits.func);
} else {
current->dev.bits.dev, current->dev.bits.func);
}
else
{
sprintf(tmp, "/Pci(0x%x,0x%x)",
current->dev.bits.dev, current->dev.bits.func);
current->dev.bits.dev, current->dev.bits.func);
}
strcat(dev_path, tmp);
}
return dev_path;
}
#if DEBUG_PCI
void dump_pci_dt(pci_dt_t *pci_dt)
{
pci_dt_t*current;
current = pci_dt;
while (current) {
while (current)
{
printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, current->vendor_id, current->device_id,
get_pci_dev_path(current));
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, current->vendor_id, current->device_id,
get_pci_dev_path(current));
dump_pci_dt(current->children);
current = current->next;
}
}
#endif

Archive Download the corresponding diff file

Revision: 546