Index: trunk/i386/libsaio/acpi_patcher.c =================================================================== --- trunk/i386/libsaio/acpi_patcher.c (revision 2474) +++ trunk/i386/libsaio/acpi_patcher.c (revision 2475) @@ -105,14 +105,16 @@ // 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'; @@ -126,14 +128,13 @@ void *loadACPITable (const char * filename) { - void *tableAddr; const char * dirspec=NULL; int fd = search_and_get_acpi_fd(filename, &dirspec); - if (fd>=0) + if (fd >= 0) { - tableAddr=(void*)AllocateKernelMemory(file_size (fd)); + void *tableAddr = (void*)AllocateKernelMemory(file_size (fd)); if (tableAddr) { if (read (fd, tableAddr, file_size (fd))!=file_size (fd)) @@ -165,7 +166,7 @@ DBG("Start finding cpu names. length %d\n", length); - for (i=0; i> 1); - if (p_states[i].FID < 0x6) { - if (cpu_dynamic_fsb) { + if (p_states[i].FID < 0x6) + { + if (cpu_dynamic_fsb) + { p_states[i].FID = (p_states[i].FID << 1) | 0x80; } - } else if (cpu_noninteger_bus_ratio) { + } + else if (cpu_noninteger_bus_ratio) + { p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1)); } - if (i && p_states[i].FID == p_states[i-1].FID) { + if (i && p_states[i].FID == p_states[i-1].FID) + { invalid++; } p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2; @@ -567,9 +577,9 @@ case CPU_MODEL_WESTMERE: // Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core case CPU_MODEL_WESTMERE_EX: // Intel Xeon E7 case CPU_MODEL_SANDYBRIDGE: // Intel Core i3, i5, i7 LGA1155 (32nm) - case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm) + case CPU_MODEL_JAKETOWN: // Intel Core i7, Xeon E5 LGA2011 (32nm) case CPU_MODEL_IVYBRIDGE: // Intel Core i3, i5, i7 LGA1155 (22nm) - case CPU_MODEL_HASWELL: // + case CPU_MODEL_HASWELL: // case CPU_MODEL_IVYBRIDGE_XEON: // //case CPU_MODEL_HASWELL_H: // case CPU_MODEL_HASWELL_SVR: // @@ -583,7 +593,9 @@ (Platform.CPU.Model == CPU_MODEL_HASWELL_ULT) || (Platform.CPU.Model == CPU_MODEL_CRYSTALWELL)) { maximum.Control = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0xff; - } else { + } + else + { maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff; } @@ -592,14 +604,18 @@ DBG("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control); // Sanity check - if (maximum.Control < minimum.Control) { + if (maximum.Control < minimum.Control) + { DBG("Insane control values!"); p_states_count = 0; - } else { + } + else + { uint8_t i; p_states_count = 0; - for (i = maximum.Control; i >= minimum.Control; i--) { + for (i = maximum.Control; i >= minimum.Control; i--) + { p_states[p_states_count].Control = i; p_states[p_states_count].CID = p_states[p_states_count].Control << 1; p_states[p_states_count].Frequency = (Platform.CPU.FSBFrequency / 1000000) * i; @@ -617,7 +633,8 @@ } // Generating SSDT - if (p_states_count > 0) { + if (p_states_count > 0) + { int i; AML_CHUNK* root = aml_create_node(NULL); @@ -626,7 +643,8 @@ AML_CHUNK* name = aml_add_name(scop, "PSS_"); AML_CHUNK* pack = aml_add_package(name); - for (i = 0; i < p_states_count; i++) { + for (i = 0; i < p_states_count; i++) + { AML_CHUNK* pstt = aml_add_package(pack); aml_add_dword(pstt, p_states[i].Frequency); @@ -638,7 +656,8 @@ } // Add aliaces - for (i = 0; i < acpi_cpu_count; 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]); @@ -664,7 +683,9 @@ return ssdt; } - } else { + } + else + { DBG("ACPI CPUs not found: P-States not generated !!!\n"); } @@ -682,20 +703,27 @@ 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; } @@ -706,31 +734,43 @@ 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; } @@ -740,8 +780,10 @@ 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 @@ -750,7 +792,9 @@ 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 @@ -764,11 +808,13 @@ } // 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; } @@ -793,9 +839,12 @@ 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; @@ -816,9 +865,12 @@ 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"); } @@ -849,32 +901,41 @@ { int i; - for (i = 0; i < 30; i++) { + 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)) ) { + 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; @@ -893,9 +954,10 @@ rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress); - DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length); + 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; @@ -906,9 +968,11 @@ 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;iLength); - 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; } @@ -946,14 +1016,16 @@ 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++; @@ -973,12 +1045,15 @@ 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; jChecksum=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 @@ -1004,7 +1082,8 @@ xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress); DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress, xsdt->Length); - 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; @@ -1016,22 +1095,27 @@ 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>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; } @@ -1058,14 +1144,16 @@ // 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++; @@ -1087,20 +1175,25 @@ 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; jChecksum=0; xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length); - } else { + } + else + { drop_xsdt: DBG("About to drop XSDT\n"); @@ -1118,15 +1211,21 @@ // 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) Index: trunk/CHANGES =================================================================== --- trunk/CHANGES (revision 2474) +++ trunk/CHANGES (revision 2475) @@ -1,3 +1,4 @@ +- bitshoveler : Make some constant arrays static; other minor fixes (acpi_patcher.c) - bitshoveler : Make 'buffer' arg to aml_add_buffer 'const char *', was just 'char *' (aml_generator) - bitshoveler : Various fixes to problems exposed by Clang static analyzer (picopng.c) - ErmaC : Rollback changes for msdos.c (2327) thx to bltz