Chameleon

Chameleon Commit Details

Date:2010-10-09 07:48:24 (13 years 6 months ago)
Author:Evan Lojewski
Commit:576
Parents: 575
Message:Retrieve and store the machine's smbios product name. Load machin.DSDT.aml file if it exists.
Changes:
M/branches/meklort/i386/libsaio/smbios_patcher.c
M/branches/meklort/i386/libsaio/smbios_patcher.h
M/branches/meklort/i386/libsaio/fake_efi.c
M/branches/meklort/i386/modules/ACPIPatcher/acpi_patcher.c
M/branches/meklort/i386/modules/ACPIPatcher/ACPIPatcher.c
M/branches/meklort/i386/libsaio/SMBIOS.h

File differences

branches/meklort/i386/libsaio/SMBIOS.h
4343
4444
4545
46
4647
4748
4849
......
5253
5354
5455
56
5557
5658
5759
......
6466
6567
6668
69
6770
6871
6972
......
7780
7881
7982
83
8084
8185
8286
......
8892
8993
9094
95
9196
97
9298
9399
94100
......
98104
99105
100106
107
101108
102109
103110
......
114121
115122
116123
124
117125
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
118151
SMBBytelength;
SMBWordhandle;
} __attribute__((packed));
typedef struct DMIHeader DMIHeader;
struct DMIEntryPoint {
SMBByteanchor[5];
SMBWordstructureCount;
SMBBytebcdRevision;
} __attribute__((packed));
typedef struct DMIEntryPoint DMIEntryPoint;
struct SMBEntryPoint {
SMBByteanchor[4];
SMBByteformattedArea[5];
struct DMIEntryPointdmi;
} __attribute__((packed));
typedef struct SMBEntryPoint SMBEntryPoint;
struct DMIMemoryControllerInfo {/* 3.3.6 Memory Controller Information (Type 5) */
struct DMIHeaderdmiHeader;
SMBBytememoryModuleVoltage;
SMBBytenumberOfMemorySlots;
} __attribute__((packed));
typedef struct DMIMemoryControllerInfo DMIMemoryControllerInfo;
struct DMIMemoryModuleInfo {/* 3.3.7 Memory Module Information (Type 6) */
struct DMIHeaderdmiHeader;
SMBByteenabledSize;
SMBByteerrorStatus;
} __attribute__((packed));
typedef struct DMIMemoryModuleInfo DMIMemoryModuleInfo;
struct DMIPhysicalMemoryArray {/* 3.3.17 Physical Memory Array (Type 16) */
struct DMIHeaderdmiHeader;
SMBBytelocation;
SMBWordmemoryErrorInformationHandle;
SMBWordnumberOfMemoryDevices;
} __attribute__((packed));
typedef struct DMIPhysicalMemoryArray DMIPhysicalMemoryArray;
struct DMIMemoryDevice {/* 3.3.18 Memory Device (Type 17) */
struct DMIHeaderdmiHeader;
SMBWordtypeDetail;
SMBWord speed;
} __attribute__((packed));
typedef struct DMIMemoryDevice DMIMemoryDevice;
struct SMBStructHeader {
SMBByte type;
SMBByte length;
SMBWord handle;
};
typedef struct SMBStructHeader SMBStructHeader;
#define SMB_STRUCT_HEADER SMBStructHeader header;
struct SMBSystemInformation {
// 2.0+ spec (8 bytes)
SMB_STRUCT_HEADER // Type 1
SMBString manufacturer;
SMBString productName;
SMBString version;
SMBString serialNumber;
// 2.1+ spec (25 bytes)
SMBByte uuid[16]; // can be all 0 or all 1's
SMBByte wakeupReason; // reason for system wakeup
};
typedef struct SMBSystemInformation SMBSystemInformation;
#endif /* !_LIBSAIO_SMBIOS_H */
branches/meklort/i386/libsaio/smbios_patcher.c
2424
2525
2626
27
2728
2829
2930
......
10681069
10691070
10701071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
uint64_t smbios_p;
char* gSMBIOSBoardModel;
typedef struct {
const char* key;
return NULL; // not found
};
const char * smbiosStringAtIndex(DMIHeader* smHeader, int index, int* length )
{
const char * last = 0;
const char * next = (const char *) smHeader + smHeader->length;
if ( length ) *length = 0;
while ( index-- )
{
last = 0;
const char * cp = 0;
for ( cp = next; *cp || cp[1]; cp++ )
{
if ( *cp == '\0' )
{
last = next;
next = cp + 1;
break;
}
}
if ( last == 0 ) break;
}
if ( last )
{
while (*last == ' ') last++;
if (length)
{
UInt8 len;
for ( len = next - last - 1; len && last[len - 1] == ' '; len-- )
;
*length = len; // number of chars not counting the terminating NULL
}
}
return last ? last : "";
}
char* getSmbiosProductName()
{
struct SMBEntryPoint*smbios;
SMBSystemInformation*p;
char*tempString;
inttmpLen;
smbios = getSmbios(SMBIOS_ORIGINAL);
if (smbios==NULL) return 0;
p = (SMBSystemInformation*) FindFirstDmiTableOfType(1, 0x19); // Type 1: (3.3.2) System Information
if (p==NULL) return NULL;
tempString = (char*)smbiosStringAtIndex((DMIHeader*)p, p->productName, &tmpLen);
tempString[tmpLen] = 0;
gSMBIOSBoardModel = malloc(tmpLen + 1);
if(gSMBIOSBoardModel)
{
strncpy(gSMBIOSBoardModel, tempString, tmpLen);
Node* node = DT__FindNode("/", false);
DT__AddProperty(node, "orig-model", tmpLen, gSMBIOSBoardModel);
}
verbose("Actual model name is '%s'\n", tempString);
}
branches/meklort/i386/libsaio/smbios_patcher.h
5555
5656
5757
58
5859
5960
extern struct SMBEntryPoint*getSmbios(int);
extern struct DMIHeader* FindNextDmiTableOfType(int type, int minlen);
extern struct DMIHeader* FindFirstDmiTableOfType(int type, int minlen);
const char * smbiosStringAtIndex(DMIHeader*, int index, int *length );
#endif /* !__LIBSAIO_SMBIOS_PATCHER_H */
branches/meklort/i386/libsaio/fake_efi.c
471471
472472
473473
474
475
474
476475
477476
478477
479478
480479
481
480
482481
483
484482
485483
486484
......
662660
663661
664662
665
666663
667664
668665
......
715712
716713
717714
715
716
717
718718
719719
720720
{
int i, isZero, isOnes;
struct SMBEntryPoint*smbios;
SMBByte*p;
SMBByte*p;
smbios = getSmbios(SMBIOS_PATCHED); // checks for _SM_ anchor and table header checksum
if (smbios==NULL) return 0; // getSmbios() return a non null value if smbios is found
p = (SMBByte*) FindFirstDmiTableOfType(1, 0x19); // Type 1: (3.3.2) System Information
if (p==NULL) return NULL;
p += 8;
verbose("Found SMBIOS System Information Table 1\n");
p += 8;
for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++)
{
// get a chance to scan mem dynamically if user asks for it while having the config options loaded as well,
// as opposed to when it was in scan_platform(); also load the orig. smbios so that we can access dmi info without
// patching the smbios yet
getSmbios(SMBIOS_ORIGINAL);
scan_mem();
smbios_p = (EFI_PTR32)getSmbios(SMBIOS_PATCHED);// process smbios asap
}
// Initialize the device tree
setupEfiDeviceTree();
getSmbios(SMBIOS_ORIGINAL);
getSmbiosProductName();
execute_hook("setupEfiConfigurationTable", NULL, NULL, NULL, NULL);
branches/meklort/i386/modules/ACPIPatcher/acpi_patcher.c
2929
3030
3131
32
33
3234
3335
3436
......
9395
9496
9597
96
98
9799
98100
99101
100102
101
102
103
104
105
106
107
108
109
103110
104
105
111
112
106113
107114
108
109
110
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
111140
112141
113
142
114143
115144
116145
......
168197
169198
170199
171
200
172201
173202
174203
......
214243
215244
216245
217
246
218247
219248
220249
......
242271
243272
244273
245
274
246275
247276
248277
249
250
251
252
253
278
279
280
281
282
254283
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
298314
299
300
301
302
303
315
316
317
318
319
320
304321
305322
323
324
325
326
327
328
329
330
331
332
333
334
306335
307336
308337
309
338
310339
311340
312341
......
316345
317346
318347
319
348
320349
321350
322351
......
325354
326355
327356
328
357
329358
330359
331360
......
504533
505534
506535
507
508
509
510
536
537
538
539
511540
512
513
514
515
516
517
518
519
520
521
522
541
542
543
523544
545
546
547
548
549
550
551
552
524553
525554
526555
......
674703
675704
676705
677
706
678707
679708
680709
681
710
682711
683712
684713
......
714743
715744
716745
717
746
718747
719748
720749
......
727756
728757
729758
730
759
731760
732761
733762
......
793822
794823
795824
796
825
797826
798827
799828
......
847876
848877
849878
850
879
851880
852881
853
882
854883
855884
856885
......
966995
967996
968997
969
998
970999
9711000
972
1001
9731002
9741003
9751004
uint64_t acpi20_p;
extern char* gSMBIOSBoardModel;
// Slice: New signature compare function
boolean_t tableSign(char *table, const char *sgn)
{
/** The folowing ACPI Table search algo. should be reused anywhere needed:*/
int search_and_get_acpi_fd(const char * filename, const char ** outDirspec)
{
int fd = 0;
int fd = -1;
char dirSpec[512] = "";
// Try finding 'filename' in the usual places
// Start searching any potential location for ACPI Table
sprintf(dirSpec, "%s", filename);
fd = open(dirSpec, 0);
if(gSMBIOSBoardModel)
{
sprintf(dirSpec,"%s.%s", gSMBIOSBoardModel, filename);
fd = open(dirSpec, 0);
}
if (fd < 0)
{
sprintf(dirSpec, "/Extra/%s", filename);
{
sprintf(dirSpec, "%s", filename);
fd = open(dirSpec, 0);
if (fd < 0)
{
sprintf(dirSpec, "bt(0,0)/Extra/%s", filename);
fd = open(dirSpec, 0);
{
if(gSMBIOSBoardModel)
{
sprintf(dirSpec, "/Extra/%s.%s", gSMBIOSBoardModel, filename);
fd = open(dirSpec, 0);
}
if (fd < 0)
{
sprintf(dirSpec, "/Extra/%s", filename);
fd = open(dirSpec, 0);
if (fd < 0)
{
if(gSMBIOSBoardModel)
{
sprintf(dirSpec, "bt(0,0)/Extra/%s.%s", gSMBIOSBoardModel, filename);
fd = open(dirSpec, 0);
}
if (fd < 0)
{
sprintf(dirSpec, "bt(0,0)/Extra/%s", filename);
fd = open(dirSpec, 0);
}
}
}
}
}
if (fd < 0)
{
// NOT FOUND:
uint32_t offset = i + 3 + (dsdt[i+2] >> 6);
bool add_name = true;
uint8_t j;
for (j=0; j<4; j++)
0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x79, 0x00
};
if (Platform->CPU.Vendor != 0x756E6547) {
verbose ("Not an Intel platform: C-States will not be generated !!!\n");
return NULL;
bool c4_enabled = false;
getBoolForKey(kEnableC4States, &c4_enabled, &bootInfo->bootConfig);
unsigned char cstates_count = 1 + (c2_enabled ? 1 : 0) + (c3_enabled ? 1 : 0);
struct aml_chunk* root = aml_create_node(NULL);
aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header
struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");
struct aml_chunk* name = aml_add_name(scop, "CST_");
struct aml_chunk* pack = aml_add_package(name);
aml_add_byte(pack, cstates_count);
aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header
struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");
struct aml_chunk* name = aml_add_name(scop, "CST_");
struct aml_chunk* pack = aml_add_package(name);
aml_add_byte(pack, cstates_count);
struct aml_chunk* tmpl = aml_add_package(pack);
cstate_resource_template[11] = 0x00; // C1
aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
aml_add_byte(tmpl, 0x01); // C1
aml_add_byte(tmpl, 0x01); // Latency
aml_add_word(tmpl, 0x03e8); // Power
// C2
if (c2_enabled)
{
tmpl = aml_add_package(pack);
cstate_resource_template[11] = 0x10; // C2
aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
aml_add_byte(tmpl, 0x02); // C2
aml_add_byte(tmpl, fadt->C2_Latency);
aml_add_word(tmpl, 0x01f4); // Power
}
// C4
if (c4_enabled)
{
tmpl = aml_add_package(pack);
cstate_resource_template[11] = 0x30; // C4
aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
aml_add_byte(tmpl, 0x04); // C4
aml_add_word(tmpl, fadt->C3_Latency / 2); // TODO: right latency for C4
aml_add_byte(tmpl, 0xfa); // Power
}
else
// C3
if (c3_enabled)
{
tmpl = aml_add_package(pack);
cstate_resource_template[11] = 0x20; // C3
aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
aml_add_byte(tmpl, 0x03); // C3
aml_add_word(tmpl, fadt->C3_Latency);
aml_add_word(tmpl, 0x015e); // Power
}
// Aliaces
int i;
for (i = 0; i < acpi_cpu_count; i++)
struct aml_chunk* tmpl = aml_add_package(pack);
cstate_resource_template[11] = 0x00; // C1
aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
aml_add_byte(tmpl, 0x01); // C1
aml_add_byte(tmpl, 0x01); // Latency
aml_add_word(tmpl, 0x03e8); // Power
// C2
if (c2_enabled)
{
tmpl = aml_add_package(pack);
cstate_resource_template[11] = 0x10; // C2
aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
aml_add_byte(tmpl, 0x02); // C2
aml_add_byte(tmpl, fadt->C2_Latency);
aml_add_word(tmpl, 0x01f4); // Power
}
// C4
if (c4_enabled)
{
tmpl = aml_add_package(pack);
cstate_resource_template[11] = 0x30; // C4
aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
aml_add_byte(tmpl, 0x04); // C4
aml_add_word(tmpl, fadt->C3_Latency / 2); // TODO: right latency for C4
aml_add_byte(tmpl, 0xfa); // Power
}
else
// C3
if (c3_enabled)
{
char name[9];
sprintf(name, "_PR_%c%c%c%c", acpi_cpu_name[i][0], acpi_cpu_name[i][1], acpi_cpu_name[i][2], acpi_cpu_name[i][3]);
scop = aml_add_scope(root, name);
aml_add_alias(scop, "CST_", "_CST");
tmpl = aml_add_package(pack);
cstate_resource_template[11] = 0x20; // C3
aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
aml_add_byte(tmpl, 0x03); // C3
aml_add_word(tmpl, fadt->C3_Latency);
aml_add_word(tmpl, 0x015e); // Power
}
// Aliaces
int i;
for (i = 0; i < acpi_cpu_count; i++)
{
char name[9];
sprintf(name, "_PR_%c%c%c%c", acpi_cpu_name[i][0], acpi_cpu_name[i][1], acpi_cpu_name[i][2], acpi_cpu_name[i][3]);
scop = aml_add_scope(root, name);
aml_add_alias(scop, "CST_", "_CST");
}
aml_calculate_size(root);
struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);
aml_write_node(root, (void*)ssdt, 0);
ssdt->Length = root->Size;
aml_destroy_node(root);
//dumpPhysAddr("C-States SSDT content: ", ssdt, ssdt->Length);
verbose ("SSDT with CPU C-States generated successfully\n");
return ssdt;
{
verbose ("ACPI CPUs not found: C-States not generated !!!\n");
}
return NULL;
}
int i;
struct aml_chunk* root = aml_create_node(NULL);
aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header
struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");
struct aml_chunk* name = aml_add_name(scop, "PSS_");
struct aml_chunk* pack = aml_add_package(name);
aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header
struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");
struct aml_chunk* name = aml_add_name(scop, "PSS_");
struct aml_chunk* pack = aml_add_package(name);
for (i = 0; i < p_states_count; i++)
{
struct aml_chunk* pstt = aml_add_package(pack);
aml_add_dword(pstt, p_states[i].Frequency);
aml_add_dword(pstt, 0x00000000); // Power
aml_add_dword(pstt, 0x0000000A); // Latency
aml_add_dword(pstt, 0x0000000A); // Latency
aml_add_dword(pstt, p_states[i].Control);
aml_add_dword(pstt, i+1); // Status
}
for (i = 0; i < p_states_count; i++)
{
struct aml_chunk* pstt = aml_add_package(pack);
aml_add_dword(pstt, p_states[i].Frequency);
aml_add_dword(pstt, 0x00000000); // Power
aml_add_dword(pstt, 0x0000000A); // Latency
aml_add_dword(pstt, 0x0000000A); // Latency
aml_add_dword(pstt, p_states[i].Control);
aml_add_dword(pstt, i+1); // Status
}
// Add aliaces
for (i = 0; i < acpi_cpu_count; i++)
{
{
int version;
void *new_dsdt;
const char *filename;
char dirSpec[128];
int len = 0;
// Try using the file specified with the DSDT option
if (getValueForKey(kDSDT, &filename, &len, &bootInfo->bootConfig))
{
for (i=0; i<30; i++)
{
char filename[512];
sprintf(filename, i>0?"SSDT-%d.aml":"SSDT.aml", i);
if(new_ssdt[ssdt_count] = loadACPITable(filename))
}
}
}
// Do the same procedure for both versions of ACPI
for (version=0; version<2; version++) {
struct acpi_2_rsdp *rsdp, *rsdp_mod;
if(new_dsdt)
rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
continue;
}
if (tableSign(table, "FACP"))
for (j=0; j<ssdt_count; j++)
rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
verbose("RSDT: Added %d SSDT table(s)\n", ssdt_count);
}
// Correct the checksum of RSDT
DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);
for (j=0; j<ssdt_count; j++)
xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
}
// Correct the checksum of XSDT
xsdt_mod->Checksum=0;
xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);
branches/meklort/i386/modules/ACPIPatcher/ACPIPatcher.c
6969
7070
7171
72
72
7373
7474
7575
}
fsize = file_size(fd);
if ((new_dsdt = malloc(fsize)) == NULL) {
verbose("[ERROR] alloc DSDT memory failed\n");
close (fd);

Archive Download the corresponding diff file

Revision: 576