Chameleon

Chameleon Commit Details

Date:2014-11-02 01:31:04 (9 years 4 months ago)
Author:ErmaC
Commit:2461
Parents: 2460
Message:Typo
Changes:
M/branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c
M/branches/ErmaC/Enoch/i386/libsaio/allocate.c

File differences

branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c
105105
106106
107107
108
108
109
109110
110111
111112
112113
113114
114115
115
116
117
116118
117119
118120
......
130132
131133
132134
133
135
134136
135137
136138
......
164166
165167
166168
167
169
168170
169171
170172
......
176178
177179
178180
179
181
180182
181183
182184
......
195197
196198
197199
200
198201
202
199203
200204
201205
202
206
207
203208
204209
205210
......
685690
686691
687692
688
693
694
689695
690696
691
697
698
692699
693
700
701
702
694703
695704
696
705
706
707
697708
698709
699710
700711
701
712
713
702714
703715
704716
......
709721
710722
711723
712
724
725
726
713727
714728
715729
716730
717731
718732
719
720
733
734
735
736
721737
722
738
739
740
723741
724742
725743
726
744
745
746
727747
728748
729749
730750
731
732
751
752
753
754
733755
734756
735757
736
758
759
760
737761
738762
739763
......
743767
744768
745769
746
747
770
771
772
773
748774
749775
750776
......
753779
754780
755781
756
782
783
784
757785
758786
759787
......
767795
768796
769797
770
798
799
771800
772801
773802
774
803
804
775805
776806
777807
......
796826
797827
798828
799
829
830
800831
801
832
833
834
802835
803836
804837
......
808841
809842
810843
844
845
846
847
848
849
850
851
852
811853
812854
813855
......
825867
826868
827869
828
870
871
829872
830
873
874
875
831876
832877
833878
......
836881
837882
838883
839
884
885
840886
841
887
888
889
842890
843891
844892
845893
846894
847895
848
896
897
849898
850
899
900
901
851902
852903
853904
854905
855906
856907
857
908
909
858910
859
911
912
913
860914
861915
862916
863917
864918
865919
866
920
921
867922
868
923
924
925
869926
870927
871928
872929
873930
874931
875
932
933
876934
877
935
936
937
878938
879939
880940
881941
882942
883943
884
944
945
885946
886
947
948
949
887950
888951
889952
890953
891954
892955
893
956
957
894958
895
959
960
961
896962
897963
898964
......
911977
912978
913979
914
915
916
917
918
919
920
921
922980
923981
924982
......
937995
938996
939997
940
998
999
9411000
942
1001
1002
1003
9431004
9441005
9451006
9461007
9471008
9481009
949
1010
1011
9501012
9511013
9521014
9531015
9541016
9551017
956
1018
1019
9571020
958
1021
1022
9591023
960
1024
1025
1026
9611027
9621028
9631029
......
9781044
9791045
9801046
981
1047
1048
9821049
9831050
9841051
......
9891056
9901057
9911058
992
1059
1060
9931061
994
1062
1063
9951064
9961065
9971066
......
9991068
10001069
10011070
1002
1071
1072
10031073
10041074
10051075
10061076
10071077
1008
1078
1079
10091080
10101081
10111082
10121083
10131084
1014
1085
1086
10151087
10161088
10171089
10181090
10191091
1020
1092
1093
10211094
10221095
10231096
10241097
10251098
1026
1099
1100
10271101
10281102
10291103
10301104
10311105
1032
1106
1107
10331108
10341109
10351110
10361111
10371112
1038
1113
1114
10391115
10401116
10411117
10421118
10431119
1044
1120
1121
10451122
10461123
1047
1124
1125
10481126
10491127
10501128
10511129
10521130
1053
1131
1132
10541133
10551134
1056
1135
1136
10571137
10581138
10591139
10601140
10611141
1062
1142
1143
10631144
10641145
1065
1146
1147
10661148
10671149
10681150
10691151
10701152
1071
1153
1154
10721155
10731156
1074
1157
1158
10751159
10761160
10771161
10781162
10791163
1080
1164
1165
10811166
10821167
1083
1168
1169
10841170
10851171
10861172
10871173
10881174
1089
1175
1176
10901177
10911178
1092
1179
1180
10931181
10941182
10951183
10961184
10971185
1098
1186
1187
10991188
11001189
1101
1190
1191
11021192
11031193
11041194
11051195
11061196
1107
1197
1198
11081199
11091200
1110
1201
1202
11111203
11121204
1205
11131206
11141207
11151208
1116
1209
1210
11171211
11181212
11191213
11201214
11211215
1122
1216
1217
11231218
11241219
11251220
......
11281223
11291224
11301225
1131
1226
1227
11321228
11331229
11341230
11351231
11361232
11371233
1138
1234
1235
11391236
11401237
11411238
......
11551252
11561253
11571254
1158
1255
1256
11591257
11601258
1161
1259
1260
11621261
11631262
11641263
......
11721271
11731272
11741273
1175
1274
1275
1276
11761277
11771278
11781279
11791280
11801281
1181
1282
1283
11821284
11831285
11841286
......
11861288
11871289
11881290
1189
1291
1292
11901293
11911294
11921295
......
11981301
11991302
12001303
1201
1304
1305
12021306
1203
1307
1308
12041309
12051310
12061311
12071312
1208
1313
1314
12091315
12101316
12111317
12121318
12131319
1214
1320
1321
12151322
12161323
12171324
12181325
12191326
1220
1327
1328
12211329
12221330
12231331
12241332
12251333
1226
1334
1335
12271336
12281337
12291338
12301339
12311340
1232
1341
1342
12331343
12341344
12351345
12361346
12371347
1238
1348
1349
12391350
12401351
12411352
12421353
12431354
1244
1355
1356
12451357
12461358
12471359
12481360
12491361
1250
1362
1363
12511364
12521365
1253
1366
1367
12541368
12551369
12561370
......
12591373
12601374
12611375
1262
1376
1377
12631378
12641379
1265
1380
1381
12661382
12671383
12681384
......
12711387
12721388
12731389
1274
1390
1391
12751392
12761393
1277
1394
1395
12781396
12791397
12801398
......
12831401
12841402
12851403
1286
1404
1405
12871406
12881407
1289
1408
1409
12901410
12911411
12921412
......
12951415
12961416
12971417
1298
1418
1419
12991420
13001421
1301
1422
1423
13021424
13031425
13041426
......
13071429
13081430
13091431
1310
1432
1433
13111434
13121435
1313
1436
1437
13141438
13151439
13161440
......
13191443
13201444
13211445
1322
1446
1447
13231448
13241449
1325
1450
1451
13261452
13271453
13281454
......
13311457
13321458
13331459
1334
1460
1461
13351462
13361463
1337
1464
1465
13381466
13391467
13401468
......
13431471
13441472
13451473
1346
1474
1475
13471476
13481477
13491478
13501479
13511480
13521481
1353
1482
1483
13541484
13551485
13561486
......
13611491
13621492
13631493
1364
1494
1495
13651496
13661497
13671498
13681499
13691500
13701501
1371
1502
1503
13721504
13731505
13741506
......
13971529
13981530
13991531
1400
1532
1533
14011534
14021535
1403
1536
1537
14041538
14051539
14061540
14071541
1542
14081543
14091544
14101545
14111546
14121547
1413
1548
1549
1550
14141551
14151552
14161553
......
14281565
14291566
14301567
1568
14311569
14321570
1571
14331572
14341573
1435
1574
1575
14361576
1577
14371578
14381579
1580
14391581
1582
14401583
14411584
14421585
// Start searching any potential location for ACPI Table
snprintf(dirSpec, sizeof(dirSpec), "%s", filename);
fd = open(dirSpec, 0);
if (fd < 0) {
if (fd < 0)
{
snprintf(dirSpec, sizeof(dirSpec), "/Extra/%s", filename);
fd = open(dirSpec, 0);
if (fd < 0)
{
snprintf(dirSpec, sizeof(dirSpec), "bt(0,0)/Extra/%s", filename);
fd = open(dirSpec, 0);
if (fd < 0) {
if (fd < 0)
{
// NOT FOUND:
DBG("ACPI Table not found: %s\n", filename);
*dirSpec = '\0';
int fd = search_and_get_acpi_fd(filename, &dirspec);
if (fd>=0)
if (fd >= 0)
{
void *tableAddr = (void*)AllocateKernelMemory(file_size (fd));
if (tableAddr)
DBG("Start finding cpu names. length %d\n", length);
for (i=0; i<length-7; i++)
for (i=0; i<length-7; i++)
{
if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP
{
uint8_t j;
for (j=0; j<4; j++)
for (j=0; j<4; j++)
{
char c = dsdt[offset+j];
i = offset + 5;
if (acpi_cpu_count == 0)
{
acpi_cpu_p_blk = dsdt[i] | (dsdt[i+1] << 8);
}
DBG("Found ACPI CPU: %c%c%c%c\n", acpi_cpu_name[acpi_cpu_count][0], acpi_cpu_name[acpi_cpu_count][1], acpi_cpu_name[acpi_cpu_count][2], acpi_cpu_name[acpi_cpu_count][3]);
if (++acpi_cpu_count == 32) {
if (++acpi_cpu_count == 32)
{
return;
}
}
const char * value;
// Restart Fix
if (Platform.CPU.Vendor == 0x756E6547) { /* Intel */
if (Platform.CPU.Vendor == 0x756E6547)
{/* Intel */
fix_restart = true;
fix_restart_ps2 = false;
if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2) {
if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2)
{
fix_restart = true;
} else {
}
else
{
getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);
}
} else {
}
else
{
DBG("Not an Intel platform: Restart Fix not applied !!!\n");
fix_restart = false;
}
if (fix_restart) {
if (fix_restart)
{
fadt_rev2_needed = true;
}
memcpy(fadt_mod, fadt, fadt->Length);
fadt_mod->Length = 0x84;
fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)
} else {
}
else
{
fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
memcpy(fadt_mod, fadt, fadt->Length);
}
// Determine system type / PM_Model
if ( (value=getStringForKey(kSystemType, &bootInfo->chameleonConfig))!=NULL)
{
if (Platform.Type > 6) {
if(fadt_mod->PM_Profile<=6) {
if (Platform.Type > 6)
{
if(fadt_mod->PM_Profile<=6)
{
Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct
} else {
}
else
{
Platform.Type = 1;/* Set a fixed value (Desktop) */
}
DBG("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);
} else {
}
else
{
Platform.Type = (unsigned char) strtoul(value, NULL, 10);
}
}
// Set PM_Profile from System-type if only user wanted this value to be forced
if (fadt_mod->PM_Profile != Platform.Type) {
if (value) {
if (fadt_mod->PM_Profile != Platform.Type)
{
if (value)
{
// user has overriden the SystemType so take care of it in FACP
DBG("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type);
fadt_mod->PM_Profile = Platform.Type;
} else {
}
else
{
// PM_Profile has a different value and no override has been set, so reflect the user value to ioregs
Platform.Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1;
}
setupSystemType();
// Patch FADT to fix restart
if (fix_restart) {
if (fix_restart_ps2) {
if (fix_restart)
{
if (fix_restart_ps2)
{
fadt_mod->Flags|= 0x400;
fadt_mod->Reset_SpaceID= 0x01; // System I/O
fadt_mod->Reset_BitWidth= 0x08; // 1 byte
fadt_mod->Reset_Address= 0x64; // Address of the register
fadt_mod->Reset_Value= 0xfe; // Value to write to reset the system
DBG("FADT: PS2 Restart Fix applied!\n");
} else {
}
else
{
fadt_mod->Flags|= 0x400;
fadt_mod->Reset_SpaceID= 0x01; // System I/O
fadt_mod->Reset_BitWidth= 0x08; // 1 byte
}
// Patch DSDT Address if we have loaded DSDT.aml
if(new_dsdt) {
if(new_dsdt)
{
DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);
fadt_mod->DSDT=(uint32_t)new_dsdt;
if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length) {
if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)
{
fadt_mod->X_DSDT=(uint32_t)new_dsdt;
}
acpi10_p = (uint64_t)(uint32_t)getAddressOfAcpiTable();
acpi20_p = (uint64_t)(uint32_t)getAddressOfAcpi20Table();
addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
if(acpi20_p) {
if(acpi20_p)
{
addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
} else {
}
else
{
DBG("No ACPI 2.\n");
}
return 1;
int setupAcpi(void)
{
int version;
// ACPI Tables
bool drop_dmar = getBoolForKey(kDropDMAR, &drop_dmar, &bootInfo->chameleonConfig);
bool drop_hpet = getBoolForKey(kDropHPET, &drop_hpet, &bootInfo->chameleonConfig);
bool drop_slic = getBoolForKey(kDropSLIC, &drop_slic, &bootInfo->chameleonConfig);
bool drop_sbst = getBoolForKey(kDropSBST, &drop_sbst, &bootInfo->chameleonConfig);
bool drop_ecdt = getBoolForKey(kDropECDT, &drop_ecdt, &bootInfo->chameleonConfig);
bool drop_asft = getBoolForKey(kDropASFT, &drop_asft, &bootInfo->chameleonConfig);
void *new_dsdt = NULL; // DSDT.aml DSDT
void *new_hpet = NULL; // HPET.aml HPET
void *new_sbst = NULL; // SBST.aml SBST
acpi_cpu_count = 0;
/* Try using the file specified with the DSDT option */
if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig)) {
if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig))
{
snprintf(dirSpec, sizeof(dirSpec), filename);
} else {
}
else
{
sprintf(dirSpec, "DSDT.aml");
//verbose("dirSpec, DSDT.aml");
}
new_dsdt = loadACPITable(dirSpec);
/* Try using the file specified with the HPET option */
if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig)) {
if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig))
{
snprintf(dirSpec, sizeof(dirSpec), filename);
} else {
}
else
{
sprintf(dirSpec, "HPET.aml");
}
// Load replacement HPET
new_hpet = loadACPITable(dirSpec);
/* Try using the file specified with the SBST option */
if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig)) {
if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig))
{
snprintf(dirSpec, sizeof(dirSpec), filename);
} else {
}
else
{
sprintf(dirSpec, "SBST.aml");
}
// Load replacement SBST
new_sbst = loadACPITable(dirSpec);
/* Try using the file specified with the ECDT option */
if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig)) {
if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig))
{
snprintf(dirSpec, sizeof(dirSpec), filename);
} else {
}
else
{
sprintf(dirSpec, "ECDT.aml");
}
// Load replacement ECDT
new_ecdt = loadACPITable(dirSpec);
/* Try using the file specified with the ASF! option */
if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig)) {
if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig))
{
snprintf(dirSpec, sizeof(dirSpec), filename);
} else {
}
else
{
sprintf(dirSpec, "ASFT.aml");
}
// Load replacement ASF!
new_asft = loadACPITable(dirSpec);
/* Try using the file specified with the DMAR option */
if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig)) {
if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig))
{
snprintf(dirSpec, sizeof(dirSpec), filename);
} else {
}
else
{
sprintf(dirSpec, "DMAR.aml");
}
// Load replacement DMAR
new_dmar = loadACPITable(dirSpec);
/* Try using the file specified with the APIC option */
if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig)) {
if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig))
{
snprintf(dirSpec, sizeof(dirSpec), filename);
} else {
}
else
{
sprintf(dirSpec, "APIC.aml");
}
// Load replacement APIC
new_apic = loadACPITable(dirSpec);
// Try using the file specified with the MCFG option */
if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig)) {
if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig))
{
snprintf(dirSpec, sizeof(dirSpec), filename);
} else {
}
else
{
sprintf(dirSpec, "MCFG.aml");
}
// Load replacement MCFG
// SSDT Options
bool drop_ssdt=false, generate_pstates=false, generate_cstates=false;
// ACPI Tables
bool drop_dmar = getBoolForKey(kDropDMAR, &drop_dmar, &bootInfo->chameleonConfig);
bool drop_hpet = getBoolForKey(kDropHPET, &drop_hpet, &bootInfo->chameleonConfig);
bool drop_slic = getBoolForKey(kDropSLIC, &drop_slic, &bootInfo->chameleonConfig);
bool drop_sbst = getBoolForKey(kDropSBST, &drop_sbst, &bootInfo->chameleonConfig);
bool drop_ecdt = getBoolForKey(kDropECDT, &drop_ecdt, &bootInfo->chameleonConfig);
bool drop_asft = getBoolForKey(kDropASFT, &drop_asft, &bootInfo->chameleonConfig);
getBoolForKey(kDropSSDT, &drop_ssdt, &bootInfo->chameleonConfig);
getBoolForKey(kGeneratePStates, &generate_pstates, &bootInfo->chameleonConfig);
getBoolForKey(kGenerateCStates, &generate_cstates, &bootInfo->chameleonConfig);
sprintf(filename, i > 0 ? "SSDT-%d.aml" : "SSDT.aml", i);
if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) ) {
if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) )
{
ssdt_count++;
} else {
}
else
{
break;
}
}
}
// Do the same procedure for both versions of ACPI
for (version = 0; version < 2; version++) {
for (version = 0; version < 2; version++)
{
struct acpi_2_rsdp *rsdp, *rsdp_mod;
struct acpi_2_rsdt *rsdt, *rsdt_mod;
int rsdplength;
// Find original rsdp
rsdp=(struct acpi_2_rsdp *)(version ? getAddressOfAcpi20Table() : getAddressOfAcpiTable());
if (!rsdp) {
if (!rsdp)
{
DBG("No ACPI version %d found. Ignoring\n", version+1);
if (version) {
if (version)
{
addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");
} else {
}
else
{
addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");
}
continue;
DBG("RSDT @%x, Length %d\n",rsdt, rsdt ? rsdt->Length : 0);
if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000) {
if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)
{
uint32_t *rsdt_entries;
int rsdt_entries_num;
int dropoffset=0, i;
rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;
rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;
rsdt_entries=(uint32_t *)(rsdt_mod+1);
for (i=0;i<rsdt_entries_num;i++) {
for (i=0;i<rsdt_entries_num;i++)
{
char *table=(char *)(rsdt_entries[i]);
if (!table) {
if (!table)
{
continue;
}
rsdt_entries[i-dropoffset]=rsdt_entries[i];
if (drop_ssdt && tableSign(table, "SSDT")) {
if (drop_ssdt && tableSign(table, "SSDT"))
{
DBG("OEM SSDT tables was dropped\n");
dropoffset++;
continue;
}
if (drop_hpet && tableSign(table, "HPET")) {
if (drop_hpet && tableSign(table, "HPET"))
{
DBG("OEM HPET table was dropped\n");
dropoffset++;
continue;
}
if (drop_slic && tableSign(table, "SLIC")) {
if (drop_slic && tableSign(table, "SLIC"))
{
DBG("OEM SLIC table was dropped\n");
dropoffset++;
continue;
}
if (drop_sbst && tableSign(table, "SBST")) {
if (drop_sbst && tableSign(table, "SBST"))
{
DBG("OEM SBST table was dropped\n");
dropoffset++;
continue;
}
if (drop_ecdt && tableSign(table, "ECDT")) {
if (drop_ecdt && tableSign(table, "ECDT"))
{
DBG("OEM ECDT table was dropped\n");
dropoffset++;
continue;
}
if (drop_asft && tableSign(table, "ASF!")) {
if (drop_asft && tableSign(table, "ASF!"))
{
DBG("OEM ASF! table was dropped\n");
dropoffset++;
continue;
}
if (drop_dmar && tableSign(table, "DMAR")) {
if (drop_dmar && tableSign(table, "DMAR"))
{
DBG("OEM DMAR table was dropped\n");
dropoffset++;
continue;
}
if (tableSign(table, "HPET")) {
if (tableSign(table, "HPET"))
{
DBG("HPET found\n");
DBG("Custom HPET table was found\n");
if(new_hpet) {
if(new_hpet)
{
rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;
}
continue;
}
if (tableSign(table, "SBST")) {
if (tableSign(table, "SBST"))
{
DBG("SBST found\n");
DBG("Custom SBST table was found\n");
if(new_sbst) {
if(new_sbst)
{
rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;
}
continue;
}
if (tableSign(table, "ECDT")) {
if (tableSign(table, "ECDT"))
{
DBG("ECDT found\n");
DBG("Custom ECDT table was found\n");
if(new_ecdt) {
if(new_ecdt)
{
rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;
}
continue;
}
if (tableSign(table, "ASF!")) {
if (tableSign(table, "ASF!"))
{
DBG("ASF! found\n");
DBG("Custom ASF! table was found\n");
if(new_asft) {
if(new_asft)
{
rsdt_entries[i-dropoffset]=(uint32_t)new_asft;
}
continue;
}
if (tableSign(table, "DMAR")) {
if (tableSign(table, "DMAR"))
{
DBG("DMAR found\n");
DBG("Custom DMAR table was found\n");
if(new_dmar) {
if(new_dmar)
{
rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;
}
continue;
}
if (tableSign(table, "APIC")) {
if (tableSign(table, "APIC"))
{
DBG("APIC found\n");
DBG("Custom APIC table was found\n");
if(new_apic) {
if(new_apic)
{
rsdt_entries[i-dropoffset]=(uint32_t)new_apic;
}
continue;
}
if (tableSign(table, "MCFG")) {
if (tableSign(table, "MCFG"))
{
DBG("MCFG found\n");
DBG("Custom MCFG table was found\n");
if(new_mcfg) {
if(new_mcfg)
{
rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;
}
continue;
}
if (tableSign(table, "DSDT")) {
if (tableSign(table, "DSDT"))
{
DBG("DSDT found\n");
DBG("Custom DSDT table was found\n");
if(new_dsdt) {
if(new_dsdt)
{
rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
}
continue;
}
if (tableSign(table, "FACP")) {
if (tableSign(table, "FACP"))
{
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)rsdt_entries[i];
DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);
if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000) {
if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)
{
DBG("FADT incorrect. Not modified\n");
continue;
}
rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;
// Generate _CST SSDT
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) {
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
{
DBG("C-States generated\n");
generate_cstates = false; // Generate SSDT only once!
ssdt_count++;
}
// Generating _PSS SSDT
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) {
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
{
DBG("P-States generated\n");
generate_pstates = false; // Generate SSDT only once!
ssdt_count++;
rsdt_entries=(uint32_t *)(rsdt_mod+1);
// Mozodojo: Insert additional SSDTs into RSDT
if(ssdt_count > 0) {
if(ssdt_count > 0)
{
int j;
for (j=0; j<ssdt_count; j++) {
for (j=0; j<ssdt_count; j++)
{
rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
}
DBG("RSDT: Added %d SSDT table(s)\n", ssdt_count);
rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);
DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);
} else {
}
else
{
rsdp_mod->RsdtAddress=0;
DBG("RSDT not found or RSDT incorrect\n");
}
DBG("\n");
if (version) {
if (version)
{
struct acpi_2_xsdt *xsdt, *xsdt_mod;
// FIXME: handle 64-bit address correctly
xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);
DBG("XSDT @%x;%x, Length=%d Sign=%c%c%c%c\n", (uint32_t)(rsdp->XsdtAddress>>32),
(uint32_t)rsdp->XsdtAddress, xsdt->Length, xsdt[0], xsdt[1], xsdt[2], xsdt[3]);
if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000) {
if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)
{
uint64_t *xsdt_entries;
int xsdt_entries_num, i;
int dropoffset=0;
rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;
xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;
xsdt_entries=(uint64_t *)(xsdt_mod+1);
for (i=0;i<xsdt_entries_num;i++) {
for (i=0;i<xsdt_entries_num;i++)
{
char *table=(char *)((uint32_t)(xsdt_entries[i]));
if (!table) {
if (!table)
{
continue;
}
xsdt_entries[i-dropoffset]=xsdt_entries[i];
if (drop_ssdt && tableSign(table, "SSDT")) {
if (drop_ssdt && tableSign(table, "SSDT"))
{
verbose("OEM SSDT tables was dropped\n");
dropoffset++;
continue;
}
if (drop_hpet && tableSign(table, "HPET")) {
if (drop_hpet && tableSign(table, "HPET"))
{
verbose("OEM HPET table was dropped\n");
dropoffset++;
continue;
}
if (drop_slic && tableSign(table, "SLIC")) {
if (drop_slic && tableSign(table, "SLIC"))
{
verbose("OEM SLIC table was dropped\n");
dropoffset++;
continue;
}
if (drop_sbst && tableSign(table, "SBST")) {
if (drop_sbst && tableSign(table, "SBST"))
{
verbose("OEM SBST table was dropped\n");
dropoffset++;
continue;
}
if (drop_ecdt && tableSign(table, "ECDT")) {
if (drop_ecdt && tableSign(table, "ECDT"))
{
verbose("OEM ECDT table was dropped\n");
dropoffset++;
continue;
}
if (drop_asft && tableSign(table, "ASF!")) {
if (drop_asft && tableSign(table, "ASF!"))
{
verbose("OEM ASF! table was dropped\n");
dropoffset++;
continue;
}
if (drop_dmar && tableSign(table, "DMAR")) {
if (drop_dmar && tableSign(table, "DMAR"))
{
verbose("OEM DMAR table was dropped\n");
dropoffset++;
continue;
}
if (tableSign(table, "DSDT")) {
if (tableSign(table, "DSDT"))
{
DBG("DSDT found\n");
if (new_dsdt) {
if (new_dsdt)
{
xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
}
continue;
}
if (tableSign(table, "HPET")) {
if (tableSign(table, "HPET"))
{
DBG("HPET found\n");
if (new_hpet) {
if (new_hpet)
{
xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;
}
continue;
}
if (tableSign(table, "SBST")) {
if (tableSign(table, "SBST"))
{
DBG("SBST found\n");
if (new_sbst) {
if (new_sbst)
{
xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;
}
continue;
}
if (tableSign(table, "ECDT")) {
if (tableSign(table, "ECDT"))
{
DBG("ECDT found\n");
if (new_ecdt) {
if (new_ecdt)
{
xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;
}
continue;
}
if (tableSign(table, "ASF!")) {
if (tableSign(table, "ASF!"))
{
DBG("ASF! found\n");
if (new_asft) {
if (new_asft)
{
xsdt_entries[i-dropoffset]=(uint32_t)new_asft;
}
continue;
}
if (tableSign(table, "DMAR")) {
if (tableSign(table, "DMAR"))
{
DBG("DMAR found\n");
if (new_dmar) {
if (new_dmar)
{
xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;
}
continue;
}
if (tableSign(table, "APIC")) {
if (tableSign(table, "APIC"))
{
DBG("APIC found\n");
if (new_apic) {
if (new_apic)
{
xsdt_entries[i-dropoffset]=(uint32_t)new_apic;
}
continue;
}
if (tableSign(table, "MCFG")) {
if (tableSign(table, "MCFG"))
{
DBG("MCFG found\n");
if (new_mcfg) {
if (new_mcfg)
{
xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;
}
continue;
}
if (tableSign(table, "FACP")) {
if (tableSign(table, "FACP"))
{
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
DBG("FADT found @%x%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt,
fadt->Length);
if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000) {
if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)
{
DBG("FADT incorrect or after 4GB. Dropping XSDT\n");
goto drop_xsdt;
}
// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
// Generate _CST SSDT
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) {
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
{
DBG("C-States generated\n");
generate_cstates = false; // Generate SSDT only once!
ssdt_count++;
}
// Generating _PSS SSDT
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) {
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
{
DBG("P-States generated\n");
generate_pstates = false; // Generate SSDT only once!
ssdt_count++;
xsdt_entries=(uint64_t *)(xsdt_mod+1);
// Mozodojo: Insert additional SSDTs into XSDT
if(ssdt_count > 0) {
if(ssdt_count > 0)
{
int j;
for (j=0; j<ssdt_count; j++) {
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);
} else {
}
else
{
drop_xsdt:
DBG("About to drop XSDT\n");
// Correct the checksum of RSDP
DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);
rsdp_mod->Checksum=0;
rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);
DBG("New checksum %d\n", rsdp_mod->Checksum);
if (version) {
if (version)
{
DBG("RSDP: Original extended checksum %d, ", rsdp_mod->ExtendedChecksum);
rsdp_mod->ExtendedChecksum=0;
rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);
DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);
}
if (version)
branches/ErmaC/Enoch/i386/libsaio/allocate.c
4949
5050
5151
52
52
53
5354
5455
5556
......
7172
7273
7374
74
75
76
7577
7678
7779
7880
7981
80
82
83
8184
8285
8386
buffer = malloc(2 * sizeof(uint32_t));
if (buffer == 0) {
if (buffer == 0)
{
free(nameBuf);
return -1;
}
{
long addr;
if (gImageLastKernelAddr == 0) {
if (gImageLastKernelAddr == 0)
{
gImageLastKernelAddr = RoundPage(bootArgs->kaddr + bootArgs->ksize);
}
addr = gImageLastKernelAddr;
gImageLastKernelAddr += RoundPage(inSize);
if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) ) {
if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) )
{
stop ("AllocateKernelMemory error");
}

Archive Download the corresponding diff file

Revision: 2461