Chameleon

Chameleon Commit Details

Date:2014-09-27 14:57:42 (6 years 6 months ago)
Author:ErmaC
Commit:2399
Parents: 2398
Message:temp revert (Acpi Patcher) as for issue 379 (thx Alex J)
Changes:
M/trunk/i386/libsaio/acpi_patcher.c

File differences

trunk/i386/libsaio/acpi_patcher.c
677677
678678
679679
680
680
681681
682682
683683
......
708708
709709
710710
711
712
713
714
715
716
717
718
711
712
713
714
715
716
717
718
719
720
721
722
723
719724
720
721
722
723
724
725
726
727
728
725
726
727
728
729
730
731
732
733
734
729735
730
731
732
733736
734737
735738
......
800803
801804
802805
803
804
806
805807
806808
807809
......
841843
842844
843845
844
845846
846847
847848
......
859860
860861
861862
862
863
864
865
866863
867864
868865
......
899896
900897
901898
902
899
903900
904901
905902
......
913910
914911
915912
916
913
917914
918915
919916
920917
921
918
922919
923920
924921
925922
926923
924
925
927926
928927
929
930928
931929
932930
......
935933
936934
937935
938
936
939937
940938
941939
......
960958
961959
962960
963
964961
962
965963
964
965
966
967
968
969
970
971
972
966973
967974
975
976
968977
969978
970979
971980
972
973981
974
975
976
977982
978983
979
980
981
982
983
984
985
986
987
988
989984
990985
991986
......
10091004
10101005
10111006
1012
1007
10131008
10141009
10151010
......
10241019
10251020
10261021
1027
1028
1029
10301022
10311023
10321024
......
10341026
10351027
10361028
1037
10381029
1030
1031
10391032
10401033
10411034
10421035
1036
1037
10431038
10441039
10451040
10461041
10471042
10481043
1049
1044
1045
10501046
10511047
10521048
......
10781074
10791075
10801076
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
10941077
1095
1078
10961079
10971080
10981081
......
11001083
11011084
11021085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
11031097
1104
11051098
11061099
1107
11081100
11091101
1102
11101103
1104
11111105
11121106
11131107
1108
11141109
11151110
11161111
bool fadt_rev2_needed = false;
bool fix_restart;
bool fix_restart_ps2;
int value = 1;
const char * value;
// Restart Fix
if (Platform.CPU.Vendor == 0x756E6547) { /* Intel */
fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
memcpy(fadt_mod, fadt, fadt->Length);
}
// Determine PM Profile
if (getIntForKey(kSystemType, &value, &bootInfo->chameleonConfig)) {
DBG("FADT: changing PM Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, (unsigned char)value);
// user has overriden the PM Profile so take care of it in FACP
fadt_mod->PM_Profile = (unsigned char)value;
} else {
DBG("FADT: PM Profile=0x%02x\n", fadt_mod->PM_Profile);
// Determine system type / PM_Model
if ( (value=getStringForKey(kSystemType, &bootInfo->chameleonConfig))!=NULL)
{
if (Platform.Type > 6) {
if(fadt_mod->PM_Profile<=6) {
Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct
} else {
Platform.Type = 1;/* Set a fixed value (Desktop) */
}
DBG("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);
} else {
Platform.Type = (unsigned char) strtoul(value, NULL, 10);
}
}
// Check if PM Profile is correct (1..3), otherwise set it to value
switch (fadt_mod->PM_Profile) {
case 1: break;
case 2: break;
case 3: break;
default:
value = 1;
DBG("FADT: wrong PM Profile (0x%02x), must be 1..3. Defaulting to 0x%02x!\n", fadt_mod->PM_Profile, (unsigned char)value);
fadt_mod->PM_Profile = (unsigned char)value;
// Set PM_Profile from System-type if only user wanted this value to be forced
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 {
// 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;
}
}
// Setup system-type
Platform.Type = fadt_mod->PM_Profile;
// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()
// because we need to take care of FACP original content, if it is correct.
setupSystemType();
int setupAcpi(void)
{
int version;
void *new_dsdt = NULL; // DSDT.aml DSDT
void *new_table;
void *new_dsdt = NULL;
const char *filename;
DBG("Generating P-States config: %s\n", generate_pstates ? "YES" : "NO");
DBG("Generating C-States config: %s\n", generate_cstates ? "YES" : "NO");
//DBG("Generating T-States config: %s\n", generate_tstates ? "YES" : "NO");
{
int i;
}
}
// Load new table
sprintf(dirSpec, "ECDT.aml");
new_table = loadACPITable(dirSpec);
// Do the same procedure for both versions of ACPI
for (version = 0; version < 2; version++) {
struct acpi_2_rsdp *rsdp, *rsdp_mod;
if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000) {
uint32_t *rsdt_entries;
int rsdt_entries_num;
int dropoffset=0, i, j;
int dropoffset=0, i;
// mozo: using malloc cos I didn't found how to free already allocated kernel memory
rsdt_mod=(struct acpi_2_rsdt *)malloc(rsdt->Length);
continue;
}
DBG("TABLE %c%c%c%c@%x: ", table[0],table[1],table[2],table[3],rsdt_entries[i]);
DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);
rsdt_entries[i-dropoffset]=rsdt_entries[i];
if (drop_ssdt && tableSign(table, "SSDT")) {
DBG("dropped (OEM)\n");
DBG("OEM SSDT tables was dropped\n");
dropoffset++;
continue;
}
if (tableSign(table, "DSDT")) {
DBG("DSDT found\n");
verbose("Custom DSDT table was found\n");
if(new_dsdt) {
rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
DBG("custom table added\n");
}
continue;
}
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)rsdt_entries[i];
DBG("found, Length %d\n",fadt->Length);
DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);
if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000) {
DBG("FADT incorrect. Not modified\n");
}
continue;
}
DBG("copied (OEM)\n");
}
DBG("\n");
// Allocate rsdt in Kernel memory area
rsdt_mod->Length += 4*ssdt_count - 4*dropoffset;
struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);
memcpy (rsdt_copy, rsdt_mod, rsdt_mod->Length);
free(rsdt_mod); rsdt_mod = rsdt_copy;
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);
// Mozodojo: Insert additional SSDTs into RSDT
if(ssdt_count > 0) {
int 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);
}
if (new_table) {
rsdt_entries[i-dropoffset+j]=(uint32_t)new_table;
DBG("RSDT: Added custom table %s @%x\n", "ECDT", new_table);
}
// Allocate rsdt in Kernel memory area
rsdt_mod->Length += 4*ssdt_count + 4 - 4*dropoffset;
struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);
memcpy (rsdt_copy, rsdt_mod, rsdt_mod->Length);
free(rsdt_mod);
rsdt_mod = rsdt_copy;
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);
// Correct the checksum of RSDT
DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);
if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000) {
uint64_t *xsdt_entries;
int xsdt_entries_num, i, j;
int xsdt_entries_num, i;
int dropoffset=0;
// mozo: using malloc cos I didn't found how to free already allocated kernel memory
if (!table) {
continue;
}
DBG("TABLE %c%c%c%c@%x: ", table[0],table[1],table[2],table[3],xsdt_entries[i]);
xsdt_entries[i-dropoffset]=xsdt_entries[i];
if (drop_ssdt && tableSign(table, "SSDT")) {
dropoffset++;
continue;
}
if (tableSign(table, "DSDT")) {
DBG("DSDT found\n");
if (new_dsdt) {
xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
DBG("custom table added\n");
}
DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
continue;
}
if (tableSign(table, "FACP")) {
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
DBG("found, Length %d\n",(uint32_t)(xsdt_entries[i]>>32), fadt->Length);
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) {
DBG("FADT incorrect or after 4GB. Dropping XSDT\n");
// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
}
// Mozodojo: Insert additional SSDTs into XSDT
if(ssdt_count > 0) {
for (j=0; j<ssdt_count; j++) {
xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
}
DBG("Added %d SSDT table(s) into XSDT\n", ssdt_count);
}
if (new_table) {
xsdt_entries[i-dropoffset+j]=(uint32_t)new_table;
DBG("XSDT: Added custom table %s @%x\n", "ECDT", new_table);
}
// Allocate xsdt in Kernel memory area
xsdt_mod->Length += 8*ssdt_count + 8 - 8*dropoffset;
xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;
struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);
memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);
free(xsdt_mod); xsdt_mod = xsdt_copy;
xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;
xsdt_entries=(uint64_t *)(xsdt_mod+1);
// Mozodojo: Insert additional SSDTs into XSDT
if(ssdt_count > 0) {
int 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
DBG("XSDT: Original checksum %d, ", xsdt_mod->Checksum);
xsdt_mod->Checksum=0;
xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);
DBG("New checksum %d\n", xsdt_mod->Checksum);
} else {
drop_xsdt:
DBG("About to drop XSDT\n");
/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT.
* A Better strategy would be to generate
*/
rsdp_mod->XsdtAddress=0xffffffffffffffffLL;
verbose("XSDT not found or XSDT incorrect\n");
}

Archive Download the corresponding diff file

Revision: 2399