Index: branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c (revision 2460) +++ branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c (revision 2461) @@ -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'; @@ -130,7 +132,7 @@ int fd = search_and_get_acpi_fd(filename, &dirspec); - if (fd>=0) + if (fd >= 0) { void *tableAddr = (void*)AllocateKernelMemory(file_size (fd)); if (tableAddr) @@ -164,7 +166,7 @@ DBG("Start finding cpu names. length %d\n", length); - for (i=0; ichameleonConfig) && 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; } @@ -709,31 +721,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; } @@ -743,8 +767,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 @@ -753,7 +779,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 @@ -767,11 +795,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; } @@ -796,9 +826,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; @@ -808,6 +841,15 @@ 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 @@ -825,9 +867,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"); } @@ -836,63 +881,84 @@ 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 @@ -911,14 +977,6 @@ // 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); @@ -937,27 +995,35 @@ 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; @@ -978,7 +1044,8 @@ 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; @@ -989,9 +1056,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; } @@ -1128,14 +1223,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++; @@ -1155,10 +1252,12 @@ 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 @@ -1186,7 +1288,8 @@ 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; @@ -1198,59 +1301,70 @@ 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; } @@ -1361,14 +1491,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++; @@ -1397,20 +1529,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"); @@ -1428,15 +1565,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: branches/ErmaC/Enoch/i386/libsaio/allocate.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/allocate.c (revision 2460) +++ branches/ErmaC/Enoch/i386/libsaio/allocate.c (revision 2461) @@ -49,7 +49,8 @@ buffer = malloc(2 * sizeof(uint32_t)); - if (buffer == 0) { + if (buffer == 0) + { free(nameBuf); return -1; } @@ -71,13 +72,15 @@ { 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"); }