Index: trunk/i386/libsaio/acpi_patcher.c =================================================================== --- trunk/i386/libsaio/acpi_patcher.c (revision 2655) +++ trunk/i386/libsaio/acpi_patcher.c (revision 2656) @@ -33,7 +33,7 @@ int i; for (i = 0; i < 4; i++) { - if ((table[i] &~0x20) != (sgn[i] &~0x20)) + if ((table[i] & ~0x20) != (sgn[i] & ~0x20)) { return false; } @@ -53,7 +53,7 @@ if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE) { uint8_t csum = checksum8(acpi_addr, 20); - if(csum == 0) + if (csum == 0) { // Only return the table if it is a true version 1.0 table (Revision 0) if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0) @@ -135,12 +135,12 @@ if (fd >= 0) { - void *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)) { - DBG("Couldn't read table %s\n",dirspec); + DBG("Couldn't read table %s\n", dirspec); free(tableAddr); close(fd); return NULL; @@ -151,70 +151,12 @@ return tableAddr; } close(fd); - DBG("Couldn't allocate memory for table \n", dirspec); - } + DBG("Couldn't allocate memory for table: %s.\n", dirspec); + } //printf("Couldn't find table %s\n", filename); return NULL; } -uint8_t acpi_cpu_count = 0; -uint32_t acpi_cpu_p_blk = 0; -char *acpi_cpu_name[32]; - -void get_acpi_cpu_names(unsigned char *dsdt, uint32_t length) -{ - uint32_t i; - - DBG("ACPIpatcher: start finding cpu names. Length %d\n", length); - - for (i=0; i> 6); - - bool add_name = true; - - uint8_t j; - - for (j=0; j<4; j++) - { - char c = dsdt[offset+j]; - - if (!aml_isvalidchar(c)) - { - add_name = false; - DBG("ACPIpatcher: invalid character found in ProcessorOP '0x%X'!\n", c); - break; - } - } - - if (add_name) - { - acpi_cpu_name[acpi_cpu_count] = malloc(4); - memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4); - i = offset + 5; - - if (acpi_cpu_count == 0) - { - acpi_cpu_p_blk = dsdt[i] | (dsdt[i+1] << 8); - } - - DBG("ACPIpatcher: 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) - { - return; - } - } - } - } - - DBG("ACPIpatcher: finished finding cpu names. Found: %d.\n", acpi_cpu_count); -} - struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt) { extern void setupSystemType(); @@ -241,7 +183,7 @@ } else { - DBG("Not an Intel platform: Restart Fix not applied !!!\n"); + DBG("\tNot an Intel platform, FACP Restart Fix will not be applied!\n"); fix_restart = false; } @@ -251,12 +193,12 @@ } // Allocate new fadt table - if (fadt->Length < 0x84 && fadt_rev2_needed) + if ((fadt->Length < 0x84) && fadt_rev2_needed) { fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x84); memcpy(fadt_mod, fadt, fadt->Length); fadt_mod->Length = 0x84; - fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions) + fadt_mod->Revision = 0x02; // FACP rev 2 (ACPI 1.0B MS extensions) } else { @@ -302,7 +244,7 @@ // because we need to take care of FACP original content, if it is correct. setupSystemType(); - // Patch FADT to fix restart + // Patch FACP to fix restart if (fix_restart) { if (fix_restart_ps2) @@ -314,7 +256,7 @@ fadt_mod->Reset_AccessWidth = 0x01; // Byte access 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"); + DBG("\tFACP PS2 Restart Fix applied!\n"); } else { @@ -325,15 +267,15 @@ fadt_mod->Reset_AccessWidth = 0x01; // Byte access fadt_mod->Reset_Address = 0x0cf9; // Address of the register fadt_mod->Reset_Value = 0x06; // Value to write to reset the system - DBG("FADT: ACPI Restart Fix applied!\n"); + DBG("\tFACP Restart Fix applied!\n"); } } // Bungo: Save Hardware Signature (machine-signature) - if ((fadt_mod->FIRMWARE_CTRL > 0) && (fadt_mod->FIRMWARE_CTRL < 0xFFFFFFFF) && (((struct acpi_2_facs *)fadt_mod->FIRMWARE_CTRL)->Length >= 64)) + if ((fadt_mod->FACS > 0) && (fadt_mod->FACS < 0xFFFFFFFF) && (((struct acpi_2_facs *)fadt_mod->FACS)->Length >= 64)) { - Platform.HWSignature = ((struct acpi_2_facs *)fadt_mod->FIRMWARE_CTRL)->HWSignature; + Platform.HWSignature = ((struct acpi_2_facs *)fadt_mod->FACS)->HWSignature; DBG("\tHardware Signature=0x%08X: using.\n", Platform.HWSignature); } else @@ -502,7 +444,7 @@ { uint32_t *rsdt_entries; int rsdt_entries_num; - int dropoffset=0, i; + 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); @@ -510,7 +452,7 @@ 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) @@ -535,7 +477,7 @@ DBG("Custom DSDT table was found\n"); if(new_dsdt) { - rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt; + rsdt_entries[i-dropoffset] = (uint32_t)new_dsdt; } continue; @@ -560,7 +502,7 @@ // Generate _CST SSDT if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) { - DBG("C-States generated\n"); + DBG("\tC-States generated.\n"); generate_cstates = false; // Generate SSDT only once! ssdt_count++; } @@ -568,7 +510,7 @@ // Generating _PSS SSDT if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) { - DBG("P-States generated\n"); + DBG("\tP-States generated.\n"); generate_pstates = false; // Generate SSDT only once! ssdt_count++; } @@ -594,7 +536,7 @@ for (j=0; jLength); + xsdt_mod = (struct acpi_2_xsdt *)malloc(xsdt->Length); memcpy(xsdt_mod, xsdt, xsdt->Length); 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) @@ -660,7 +602,7 @@ if (new_dsdt) { xsdt_entries[i-dropoffset] = (uint32_t)new_dsdt; - DBG("custom table added\n"); + DBG("custom table added.\n"); } DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]); @@ -682,14 +624,14 @@ } fadt_mod = patch_fadt(fadt, new_dsdt); - xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod; + xsdt_entries[i - dropoffset] = (uint32_t)fadt_mod; // 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))) { - DBG("C-States generated\n"); + DBG("\tC-States generated.\n"); generate_cstates = false; // Generate SSDT only once! ssdt_count++; } @@ -697,7 +639,7 @@ // Generating _PSS SSDT if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) { - DBG("P-States generated\n"); + DBG("\tP-States generated.\n"); generate_pstates = false; // Generate SSDT only once! ssdt_count++; } @@ -725,7 +667,7 @@ for (j=0; j> 8) | \ + (((uint16_t)x & 0x00FF) << 8)) + +#define swapUint32(x) ((((uint32_t)x & 0xFF000000) >> 24) | \ + (((uint32_t)x & 0x00FF0000) >> 16) | \ + (((uint32_t)x & 0x0000FF00) >> 8) | \ + (((uint32_t)x & 0x000000FF) << 24)) + /* Per ACPI 3.0a spec */ // TODO Migrate @@ -35,6 +46,19 @@ char Reserved[3]; } __attribute__((packed)); +struct acpi_2_header +{ + char Signature[4]; + uint32_t Length; + uint8_t Revision; + uint8_t Checksum; + char OEMID[6]; + char OEMTableId[8]; + uint32_t OEMRevision; + uint32_t CreatorId; + uint32_t CreatorRevision; +} __attribute__((packed)); + // TODO Migrate struct acpi_2_rsdt { @@ -77,6 +101,16 @@ uint32_t CreatorRevision; } __attribute__((packed)); +struct ssdt_pmref +{ + char oemTabID[9]; + char byte1; + uint32_t addr; + char byte2; + uint32_t length; + char byte3; +} __attribute__((packed)); + // TODO Migrate struct acpi_2_dsdt { @@ -103,7 +137,7 @@ uint32_t OEMRevision; uint32_t CreatorId; uint32_t CreatorRevision; - uint32_t FIRMWARE_CTRL; + uint32_t FACS; uint32_t DSDT; uint8_t Model; // JrCs uint8_t PM_Profile; // JrCs @@ -152,7 +186,7 @@ uint8_t Reset_Value; uint8_t Reserved[3]; - uint64_t X_FIRMWARE_CTRL; + uint64_t X_FACS; uint64_t X_DSDT; /* End Asere */ /*We absolutely don't care about theese fields*/ Index: trunk/i386/libsaio/state_generator.c =================================================================== --- trunk/i386/libsaio/state_generator.c (revision 2655) +++ trunk/i386/libsaio/state_generator.c (revision 2656) @@ -33,10 +33,64 @@ #define DBG(x...) msglog(x) #endif -extern uint8_t acpi_cpu_count; -extern uint32_t acpi_cpu_p_blk; -extern char* acpi_cpu_name[32]; +uint8_t acpi_cpu_count = 0; +uint32_t acpi_cpu_p_blk = 0; +char *acpi_cpu_name[32]; +void get_acpi_cpu_names(unsigned char *dsdt, uint32_t length) +{ + uint32_t i; + + DBG("ACPIpatcher: start finding cpu names. Length %d\n", length); + + for (i=0; i> 6); + + bool add_name = true; + + uint8_t j; + + for (j=0; j<4; j++) + { + char c = dsdt[offset+j]; + + if (!aml_isvalidchar(c)) + { + add_name = false; + DBG("ACPIpatcher: invalid character found in ProcessorOP '0x%X'!\n", c); + break; + } + } + + if (add_name) + { + acpi_cpu_name[acpi_cpu_count] = malloc(4); + memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4); + i = offset + 5; + + if (acpi_cpu_count == 0) + { + acpi_cpu_p_blk = dsdt[i] | (dsdt[i+1] << 8); + } + + DBG("ACPIpatcher: 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) + { + return; + } + } + } + } + + DBG("ACPIpatcher: finished finding cpu names. Found: %d.\n", acpi_cpu_count); +} + static char const pss_ssdt_header[] = { 0x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */ Index: trunk/i386/libsaio/state_generator.h =================================================================== --- trunk/i386/libsaio/state_generator.h (revision 2655) +++ trunk/i386/libsaio/state_generator.h (revision 2656) @@ -15,6 +15,10 @@ #include "aml_generator.h" #include "libsaio.h" +extern uint8_t acpi_cpu_count; +extern uint32_t acpi_cpu_p_blk; +extern char *acpi_cpu_name[32]; + void get_acpi_cpu_names(uint8_t *dsdt, uint32_t length); struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt *fadt); struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt *dsdt);