Index: branches/meklort/i386/libsaio/SMBIOS.h =================================================================== --- branches/meklort/i386/libsaio/SMBIOS.h (revision 575) +++ branches/meklort/i386/libsaio/SMBIOS.h (revision 576) @@ -43,6 +43,7 @@ SMBByte length; SMBWord handle; } __attribute__((packed)); +typedef struct DMIHeader DMIHeader; struct DMIEntryPoint { SMBByte anchor[5]; @@ -52,6 +53,7 @@ SMBWord structureCount; SMBByte bcdRevision; } __attribute__((packed)); +typedef struct DMIEntryPoint DMIEntryPoint; struct SMBEntryPoint { SMBByte anchor[4]; @@ -64,6 +66,7 @@ SMBByte formattedArea[5]; struct DMIEntryPoint dmi; } __attribute__((packed)); +typedef struct SMBEntryPoint SMBEntryPoint; struct DMIMemoryControllerInfo {/* 3.3.6 Memory Controller Information (Type 5) */ struct DMIHeader dmiHeader; @@ -77,6 +80,7 @@ SMBByte memoryModuleVoltage; SMBByte numberOfMemorySlots; } __attribute__((packed)); +typedef struct DMIMemoryControllerInfo DMIMemoryControllerInfo; struct DMIMemoryModuleInfo { /* 3.3.7 Memory Module Information (Type 6) */ struct DMIHeader dmiHeader; @@ -88,7 +92,9 @@ SMBByte enabledSize; SMBByte errorStatus; } __attribute__((packed)); +typedef struct DMIMemoryModuleInfo DMIMemoryModuleInfo; + struct DMIPhysicalMemoryArray { /* 3.3.17 Physical Memory Array (Type 16) */ struct DMIHeader dmiHeader; SMBByte location; @@ -98,6 +104,7 @@ SMBWord memoryErrorInformationHandle; SMBWord numberOfMemoryDevices; } __attribute__((packed)); +typedef struct DMIPhysicalMemoryArray DMIPhysicalMemoryArray; struct DMIMemoryDevice { /* 3.3.18 Memory Device (Type 17) */ struct DMIHeader dmiHeader; @@ -114,5 +121,31 @@ SMBWord typeDetail; SMBWord speed; } __attribute__((packed)); +typedef struct DMIMemoryDevice DMIMemoryDevice; + +struct SMBStructHeader { + SMBByte type; + SMBByte length; + SMBWord handle; +}; + +typedef struct SMBStructHeader SMBStructHeader; + +#define SMB_STRUCT_HEADER SMBStructHeader header; + +struct SMBSystemInformation { + // 2.0+ spec (8 bytes) + SMB_STRUCT_HEADER // Type 1 + SMBString manufacturer; + SMBString productName; + SMBString version; + SMBString serialNumber; + // 2.1+ spec (25 bytes) + SMBByte uuid[16]; // can be all 0 or all 1's + SMBByte wakeupReason; // reason for system wakeup +}; +typedef struct SMBSystemInformation SMBSystemInformation; + + #endif /* !_LIBSAIO_SMBIOS_H */ Index: branches/meklort/i386/libsaio/smbios_patcher.c =================================================================== --- branches/meklort/i386/libsaio/smbios_patcher.c (revision 575) +++ branches/meklort/i386/libsaio/smbios_patcher.c (revision 576) @@ -24,6 +24,7 @@ uint64_t smbios_p; +char* gSMBIOSBoardModel; typedef struct { const char* key; @@ -1068,3 +1069,69 @@ return NULL; // not found }; + +const char * smbiosStringAtIndex(DMIHeader* smHeader, int index, int* length ) +{ + const char * last = 0; + const char * next = (const char *) smHeader + smHeader->length; + + if ( length ) *length = 0; + while ( index-- ) + { + last = 0; + const char * cp = 0; + for ( cp = next; *cp || cp[1]; cp++ ) + { + if ( *cp == '\0' ) + { + last = next; + next = cp + 1; + break; + } + } + if ( last == 0 ) break; + } + + if ( last ) + { + while (*last == ' ') last++; + if (length) + { + UInt8 len; + for ( len = next - last - 1; len && last[len - 1] == ' '; len-- ) + ; + *length = len; // number of chars not counting the terminating NULL + } + } + + return last ? last : ""; +} + + +char* getSmbiosProductName() +{ + struct SMBEntryPoint *smbios; + SMBSystemInformation *p; + char* tempString; + int tmpLen; + + smbios = getSmbios(SMBIOS_ORIGINAL); + if (smbios==NULL) return 0; + + p = (SMBSystemInformation*) FindFirstDmiTableOfType(1, 0x19); // Type 1: (3.3.2) System Information + if (p==NULL) return NULL; + + + tempString = (char*)smbiosStringAtIndex((DMIHeader*)p, p->productName, &tmpLen); + tempString[tmpLen] = 0; + + gSMBIOSBoardModel = malloc(tmpLen + 1); + if(gSMBIOSBoardModel) + { + strncpy(gSMBIOSBoardModel, tempString, tmpLen); + Node* node = DT__FindNode("/", false); + DT__AddProperty(node, "orig-model", tmpLen, gSMBIOSBoardModel); + } + verbose("Actual model name is '%s'\n", tempString); +} + Index: branches/meklort/i386/libsaio/smbios_patcher.h =================================================================== --- branches/meklort/i386/libsaio/smbios_patcher.h (revision 575) +++ branches/meklort/i386/libsaio/smbios_patcher.h (revision 576) @@ -55,5 +55,6 @@ extern struct SMBEntryPoint *getSmbios(int); extern struct DMIHeader* FindNextDmiTableOfType(int type, int minlen); extern struct DMIHeader* FindFirstDmiTableOfType(int type, int minlen); +const char * smbiosStringAtIndex(DMIHeader*, int index, int *length ); #endif /* !__LIBSAIO_SMBIOS_PATCHER_H */ Index: branches/meklort/i386/libsaio/fake_efi.c =================================================================== --- branches/meklort/i386/libsaio/fake_efi.c (revision 575) +++ branches/meklort/i386/libsaio/fake_efi.c (revision 576) @@ -471,16 +471,14 @@ { int i, isZero, isOnes; struct SMBEntryPoint *smbios; - SMBByte *p; - + SMBByte *p; smbios = getSmbios(SMBIOS_PATCHED); // checks for _SM_ anchor and table header checksum if (smbios==NULL) return 0; // getSmbios() return a non null value if smbios is found p = (SMBByte*) FindFirstDmiTableOfType(1, 0x19); // Type 1: (3.3.2) System Information if (p==NULL) return NULL; - + p += 8; verbose("Found SMBIOS System Information Table 1\n"); - p += 8; for (i=0, isZero=1, isOnes=1; i> 6); bool add_name = true; - + uint8_t j; for (j=0; j<4; j++) @@ -214,7 +243,7 @@ 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0x00 }; - + if (Platform->CPU.Vendor != 0x756E6547) { verbose ("Not an Intel platform: C-States will not be generated !!!\n"); return NULL; @@ -242,71 +271,71 @@ bool c4_enabled = false; getBoolForKey(kEnableC4States, &c4_enabled, &bootInfo->bootConfig); - + unsigned char cstates_count = 1 + (c2_enabled ? 1 : 0) + (c3_enabled ? 1 : 0); struct aml_chunk* root = aml_create_node(NULL); - aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header - struct aml_chunk* scop = aml_add_scope(root, "\\_PR_"); - struct aml_chunk* name = aml_add_name(scop, "CST_"); - struct aml_chunk* pack = aml_add_package(name); - aml_add_byte(pack, cstates_count); + aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header + struct aml_chunk* scop = aml_add_scope(root, "\\_PR_"); + struct aml_chunk* name = aml_add_name(scop, "CST_"); + struct aml_chunk* pack = aml_add_package(name); + aml_add_byte(pack, cstates_count); - struct aml_chunk* tmpl = aml_add_package(pack); - cstate_resource_template[11] = 0x00; // C1 - aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template)); - aml_add_byte(tmpl, 0x01); // C1 - aml_add_byte(tmpl, 0x01); // Latency - aml_add_word(tmpl, 0x03e8); // Power - - // C2 - if (c2_enabled) - { - tmpl = aml_add_package(pack); - cstate_resource_template[11] = 0x10; // C2 - aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template)); - aml_add_byte(tmpl, 0x02); // C2 - aml_add_byte(tmpl, fadt->C2_Latency); - aml_add_word(tmpl, 0x01f4); // Power - } - // C4 - if (c4_enabled) - { - tmpl = aml_add_package(pack); - cstate_resource_template[11] = 0x30; // C4 - aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template)); - aml_add_byte(tmpl, 0x04); // C4 - aml_add_word(tmpl, fadt->C3_Latency / 2); // TODO: right latency for C4 - aml_add_byte(tmpl, 0xfa); // Power - } - else - // C3 - if (c3_enabled) - { - tmpl = aml_add_package(pack); - cstate_resource_template[11] = 0x20; // C3 - aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template)); - aml_add_byte(tmpl, 0x03); // C3 - aml_add_word(tmpl, fadt->C3_Latency); - aml_add_word(tmpl, 0x015e); // Power - } - - - // Aliaces - int i; - for (i = 0; i < acpi_cpu_count; i++) + struct aml_chunk* tmpl = aml_add_package(pack); + cstate_resource_template[11] = 0x00; // C1 + aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template)); + aml_add_byte(tmpl, 0x01); // C1 + aml_add_byte(tmpl, 0x01); // Latency + aml_add_word(tmpl, 0x03e8); // Power + + // C2 + if (c2_enabled) + { + tmpl = aml_add_package(pack); + cstate_resource_template[11] = 0x10; // C2 + aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template)); + aml_add_byte(tmpl, 0x02); // C2 + aml_add_byte(tmpl, fadt->C2_Latency); + aml_add_word(tmpl, 0x01f4); // Power + } + // C4 + if (c4_enabled) + { + tmpl = aml_add_package(pack); + cstate_resource_template[11] = 0x30; // C4 + aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template)); + aml_add_byte(tmpl, 0x04); // C4 + aml_add_word(tmpl, fadt->C3_Latency / 2); // TODO: right latency for C4 + aml_add_byte(tmpl, 0xfa); // Power + } + else + // C3 + if (c3_enabled) { - 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]); - - scop = aml_add_scope(root, name); - aml_add_alias(scop, "CST_", "_CST"); + tmpl = aml_add_package(pack); + cstate_resource_template[11] = 0x20; // C3 + aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template)); + aml_add_byte(tmpl, 0x03); // C3 + aml_add_word(tmpl, fadt->C3_Latency); + aml_add_word(tmpl, 0x015e); // Power } + + // Aliaces + int 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]); + + scop = aml_add_scope(root, name); + aml_add_alias(scop, "CST_", "_CST"); + } + aml_calculate_size(root); struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size); - + aml_write_node(root, (void*)ssdt, 0); ssdt->Length = root->Size; @@ -316,7 +345,7 @@ aml_destroy_node(root); //dumpPhysAddr("C-States SSDT content: ", ssdt, ssdt->Length); - + verbose ("SSDT with CPU C-States generated successfully\n"); return ssdt; @@ -325,7 +354,7 @@ { verbose ("ACPI CPUs not found: C-States not generated !!!\n"); } - + return NULL; } @@ -504,23 +533,23 @@ int i; struct aml_chunk* root = aml_create_node(NULL); - aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header - struct aml_chunk* scop = aml_add_scope(root, "\\_PR_"); - struct aml_chunk* name = aml_add_name(scop, "PSS_"); - struct aml_chunk* pack = aml_add_package(name); + aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header + struct aml_chunk* scop = aml_add_scope(root, "\\_PR_"); + struct aml_chunk* name = aml_add_name(scop, "PSS_"); + struct aml_chunk* pack = aml_add_package(name); - for (i = 0; i < p_states_count; i++) - { - struct aml_chunk* pstt = aml_add_package(pack); - - aml_add_dword(pstt, p_states[i].Frequency); - aml_add_dword(pstt, 0x00000000); // Power - aml_add_dword(pstt, 0x0000000A); // Latency - aml_add_dword(pstt, 0x0000000A); // Latency - aml_add_dword(pstt, p_states[i].Control); - aml_add_dword(pstt, i+1); // Status - } + for (i = 0; i < p_states_count; i++) + { + struct aml_chunk* pstt = aml_add_package(pack); + aml_add_dword(pstt, p_states[i].Frequency); + aml_add_dword(pstt, 0x00000000); // Power + aml_add_dword(pstt, 0x0000000A); // Latency + aml_add_dword(pstt, 0x0000000A); // Latency + aml_add_dword(pstt, p_states[i].Control); + aml_add_dword(pstt, i+1); // Status + } + // Add aliaces for (i = 0; i < acpi_cpu_count; i++) { @@ -674,11 +703,11 @@ { int version; void *new_dsdt; - + const char *filename; char dirSpec[128]; int len = 0; - + // Try using the file specified with the DSDT option if (getValueForKey(kDSDT, &filename, &len, &bootInfo->bootConfig)) { @@ -714,7 +743,7 @@ 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)) @@ -727,7 +756,7 @@ } } } - + // Do the same procedure for both versions of ACPI for (version=0; version<2; version++) { struct acpi_2_rsdp *rsdp, *rsdp_mod; @@ -793,7 +822,7 @@ if(new_dsdt) rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt; - + continue; } if (tableSign(table, "FACP")) @@ -847,10 +876,10 @@ for (j=0; jChecksum); @@ -966,10 +995,10 @@ for (j=0; jChecksum=0; xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length); Index: branches/meklort/i386/modules/ACPIPatcher/ACPIPatcher.c =================================================================== --- branches/meklort/i386/modules/ACPIPatcher/ACPIPatcher.c (revision 575) +++ branches/meklort/i386/modules/ACPIPatcher/ACPIPatcher.c (revision 576) @@ -69,7 +69,7 @@ } fsize = file_size(fd); - + if ((new_dsdt = malloc(fsize)) == NULL) { verbose("[ERROR] alloc DSDT memory failed\n"); close (fd);