Index: branches/cparm/CHANGES =================================================================== --- branches/cparm/CHANGES (revision 1118) +++ branches/cparm/CHANGES (revision 1119) @@ -1,3 +1,25 @@ +- Applied some fix from the trunk +- Applied many under the hood fix +- Added Andy Vandijck Server spoof +- Added a Patch from Andy Vandijck in SMBiosPatcher and SMBiosGetters +- Added a Patch from Netkas in GraphicEnabler (ati.c) +- Fixed an issue where the GUI module couldn't find the themes directory +- Fixed an issue where the GUI module failed to display the GUI +- Added AcpiCodec module +- Re-wrote ACPI code in fake_efi.c +- Fixed a bug with AcpiPatcher when built with xcode4 +- Optimized AcpiPatcher code +- Minor change of SMBIOS code in fake_efi.c +- Applied some changes to the CPU detection +- Fixed Pict-FailedBoot allocation +- Board-id fix is now handled by the smbios modules + +- Added boot-args in the device tree +- Added BootCLUT and Pict-FailedBoot +- Added Board-id spoof +- Fixed kernelcache loading with 10.5, 10.6 and 10.7 +- Added Lion Compatibility + - Re-enabled Ignore Boot File Flag option , now "-B" - Fixed a bug in get_PM_Profile(), where the function return the profile 0 = 'Unspecified' when the facp is incorrect or not found, and so, override the PM type set by the cpu features Index: branches/cparm/i386/libsaio/pci_setup.c =================================================================== --- branches/cparm/i386/libsaio/pci_setup.c (revision 1118) +++ branches/cparm/i386/libsaio/pci_setup.c (revision 1119) @@ -1,19 +0,0 @@ -#include "libsaio.h" -#include "boot.h" -#include "bootstruct.h" -#include "pci.h" -#include "modules.h" - -void setup_pci_devs(pci_dt_t *pci_dt) -{ - pci_dt_t *current = pci_dt; - - - while (current) - { - execute_hook("PCIDevice", current, NULL, NULL, NULL); - - setup_pci_devs(current->children); - current = current->next; - } -} Index: branches/cparm/i386/libsaio/fake_efi.h =================================================================== --- branches/cparm/i386/libsaio/fake_efi.h (revision 1118) +++ branches/cparm/i386/libsaio/fake_efi.h (revision 1119) @@ -6,22 +6,20 @@ #define __LIBSAIO_FAKE_EFI_H /* Set up space for up to 10 configuration table entries */ -#define MAX_CONFIGURATION_TABLE_ENTRIES 10 +#define MAX_CONFIGURATION_TABLE_ENTRIES (uint32_t)10 #include "efi.h" #include "SMBIOS.h" + extern void setupFakeEfi(void); -extern uint64_t acpi10_p; -extern uint64_t acpi20_p; - extern EFI_STATUS addConfigurationTable(); extern struct SMBEntryPoint *getSmbiosOriginal(); extern void setupSmbiosConfigFile(const char *filename); -extern void local_readSMBIOS(int value); +extern void finalizeEFIConfigTable(void ); #endif /* !__LIBSAIO_FAKE_EFI_H */ Index: branches/cparm/i386/libsaio/smp.c =================================================================== --- branches/cparm/i386/libsaio/smp.c (revision 0) +++ branches/cparm/i386/libsaio/smp.c (revision 1119) @@ -0,0 +1,99 @@ +/* + * smp.c + * Chameleon + * + * Created by cparm on 17/06/11. + * Copyright 2011 __MyCompanyName__. All rights reserved. + * + */ + +#include "smp.h" +#include "libsaio.h" + +#define ACPI_RANGE_START (0x0E0000) +#define ACPI_RANGE_END (0x0FFFFF) + +static struct mp_t * +bios_search_mp(char *base, int length); +static struct mp_t* getAddressOfMPSTable(); + +static int lapic_dummy = 0; +unsigned imps_lapic_addr = ((unsigned)(&lapic_dummy)) - LAPIC_ID; + +struct mp_t { + uint8_t sig[4]; + uint32_t config_ptr; + uint8_t len; + uint8_t ver; + uint8_t checksum; + uint8_t f1; + uint8_t f2; + uint8_t fr[3]; +}__attribute__((packed)) mp_t; + +static struct mp_t* getAddressOfMPSTable() +{ + struct mp_t *mp; + uint16_t *addr; + + /* EBDA is the 1 KB addressed by the 16 bit pointer at 0x40E. */ + addr = (uint16_t *)ptov(EBDA_SEG_ADDR); + if ((mp = bios_search_mp((char *)(*addr << 4), EBDA_SEG_LEN)) != NULL) + return (mp); + + unsigned mem_lower = ((CMOS_READ_BYTE(CMOS_BASE_MEMORY+1) << 8) + | CMOS_READ_BYTE(CMOS_BASE_MEMORY)) << 10; + + if ((mp = bios_search_mp((char *)mem_lower, EBDA_SEG_LEN)) != NULL) + return (mp); + + if ((mp = bios_search_mp((char *)0x00F0000, ACPI_RANGE_END)) != NULL) + return (mp); + + return (NULL); + +} + +static struct mp_t * +bios_search_mp(char *base, int length) +{ + struct mp_t *mp; + int ofs; + + /* search on 16-byte boundaries */ + for (ofs = 0; ofs < length; ofs += 16) { + + mp = (struct mp_t*)ptov(base + ofs); + + /* compare signature, validate checksum */ + if (!strncmp((char*)mp->sig, MP_SIGSTR, strlen(MP_SIGSTR))) { + uint8_t csum = checksum8(mp, sizeof(struct mp_t)); + if(csum == 0) { + return mp; + } + + } + } + return NULL; +} + +void * getMPSTable() +{ + struct mp_t *mps_p = getAddressOfMPSTable() ; + + if (mps_p) + { + if (mps_p->config_ptr) { + + struct imps_cth *local_cth_ptr + = (struct imps_cth *)ptov(mps_p->config_ptr); + + imps_lapic_addr = local_cth_ptr->lapic_addr; + + } else { + imps_lapic_addr = LAPIC_ADDR_DEFAULT; + } + } + + return (void *)mps_p; +} \ No newline at end of file Index: branches/cparm/i386/libsaio/xml.c =================================================================== --- branches/cparm/i386/libsaio/xml.c (revision 1118) +++ branches/cparm/i386/libsaio/xml.c (revision 1119) @@ -86,8 +86,8 @@ }; typedef struct DriverInfo DriverInfo, *DriverInfoPtr; -#define kDriverPackageSignature1 'MKXT' -#define kDriverPackageSignature2 'MOSX' +//#define kDriverPackageSignature1 'MKXT' +//#define kDriverPackageSignature2 'MOSX' struct DriversPackage { unsigned long signature1; @@ -231,7 +231,7 @@ int i; s++; - for ( i = 0; i < sizeof(ents); i++) + for ( i = 0; (unsigned)i < sizeof(ents); i++) { if ( strncmp(s, ents[i].name, ents[i].nameLen) == 0 ) { @@ -1084,7 +1084,7 @@ bool XMLIsType(TagPtr dict, enum xmltype type) { if(!dict) return (type == kTagTypeNone); - return (dict->type == type); + return (dict->type == (long)type); } Index: branches/cparm/i386/libsaio/smp.h =================================================================== --- branches/cparm/i386/libsaio/smp.h (revision 1118) +++ branches/cparm/i386/libsaio/smp.h (revision 1119) @@ -14,7 +14,48 @@ #ifndef _SMP_H #define _SMP_H +#include "libsaio.h" + +//#define MP_SIGL 0x5f504d5f +#define MP_SIGSTR "_MP_" + /* + * MP Configuration Table Header (cth) + * + * Look at page 4-5 of the MP spec for the starting definitions of + * this structure. + */ +struct imps_cth +{ + unsigned sig; + unsigned short base_length; + unsigned char spec_rev; + unsigned char checksum; + char oem_id[8]; + char prod_id[12]; + unsigned oem_table_ptr; + unsigned short oem_table_size; + unsigned short entry_count; + unsigned lapic_addr; + unsigned short extended_length; + unsigned char extended_checksum; + char reserved[1]; +}; + +/* + * Defines that are here so as not to be in the global header file. + */ +#define EBDA_SEG_ADDR 0x40E +#define EBDA_SEG_LEN 0x400 +#define BIOS_RESET_VECTOR 0x467 +#define LAPIC_ADDR_DEFAULT 0xFEE00000uL +#define IOAPIC_ADDR_DEFAULT 0xFEC00000uL +#define CMOS_RESET_CODE 0xF +#define CMOS_RESET_JUMP 0xa +#define CMOS_BASE_MEMORY 0x15 +#define LAPIC_ID 0x20 + +/* * This contains the local APIC hardware address. */ extern unsigned imps_lapic_addr; Index: branches/cparm/i386/libsaio/xml.h =================================================================== --- branches/cparm/i386/libsaio/xml.h (revision 1118) +++ branches/cparm/i386/libsaio/xml.h (revision 1119) @@ -71,18 +71,9 @@ #define kPropIOKitPersonalities ("IOKitPersonalities") #define kPropIONameMatch ("IONameMatch") -/* -struct Tag { - long type; - char *string; - struct Tag *tag; - struct Tag *tagNext; -}; -typedef struct Tag Tag, *TagPtr; - */ -extern long gImageFirstBootXAddr; -extern long gImageLastKernelAddr; +//extern long gImageFirstBootXAddr; +//extern long gImageLastKernelAddr; TagPtr XMLGetProperty( TagPtr dict, const char * key ); TagPtr XMLGetElement( TagPtr dict, int id ); Index: branches/cparm/i386/libsaio/efi.h =================================================================== --- branches/cparm/i386/libsaio/efi.h (revision 1118) +++ branches/cparm/i386/libsaio/efi.h (revision 1119) @@ -210,7 +210,6 @@ EFI_UINT32 Reserved; } __attribute__((aligned(8))) EFI_TABLE_HEADER; -#define STRUCT_EFI_TABLE_HEADER EFI_TABLE_HEADER Hdr; // // possible caching types for the memory range // @@ -231,7 +230,7 @@ // range requires a runtime mapping // #define EFI_MEMORY_RUNTIME 0x8000000000000000ULL - +#define EFI_MEMORY_KERN_RESERVED (1ULL << 59) typedef EFI_UINT64 EFI_PHYSICAL_ADDRESS; typedef EFI_UINT64 EFI_VIRTUAL_ADDRESS; @@ -254,7 +253,7 @@ IN EFI_UINTN DescriptorSize, IN EFI_UINT32 DescriptorVersion, IN EFI_MEMORY_DESCRIPTOR * VirtualMap - ) __attribute__((regparm(0))); + ); typedef EFI_RUNTIMESERVICE @@ -262,7 +261,7 @@ (EFIAPI *EFI_CONVERT_POINTER) ( IN EFI_UINTN DebugDisposition, IN OUT VOID **Address - ) __attribute__((regparm(0))); + ); // // Variable attributes @@ -281,7 +280,7 @@ OUT EFI_UINT32 * Attributes OPTIONAL, IN OUT EFI_UINTN * DataSize, OUT VOID * Data - ) __attribute__((regparm(0))); + ); typedef EFI_RUNTIMESERVICE @@ -290,7 +289,7 @@ IN OUT EFI_UINTN * VariableNameSize, IN OUT EFI_CHAR16 * VariableName, IN OUT EFI_GUID * VendorGuid - ) __attribute__((regparm(0))); + ); typedef EFI_RUNTIMESERVICE @@ -301,7 +300,7 @@ IN EFI_UINT32 Attributes, IN EFI_UINTN DataSize, IN VOID * Data - ) __attribute__((regparm(0))); + ); // // EFI Time @@ -318,14 +317,14 @@ (EFIAPI *EFI_GET_TIME) ( OUT EFI_TIME * Time, OUT EFI_TIME_CAPABILITIES * Capabilities OPTIONAL - ) __attribute__((regparm(0))); + ); typedef EFI_RUNTIMESERVICE EFI_STATUS (EFIAPI *EFI_SET_TIME) ( IN EFI_TIME * Time - ) __attribute__((regparm(0))); + ); typedef EFI_RUNTIMESERVICE @@ -334,7 +333,7 @@ OUT EFI_BOOLEAN * Enabled, OUT EFI_BOOLEAN * Pending, OUT EFI_TIME * Time - ) __attribute__((regparm(0))); + ); typedef EFI_RUNTIMESERVICE @@ -342,7 +341,7 @@ (EFIAPI *EFI_SET_WAKEUP_TIME) ( IN EFI_BOOLEAN Enable, IN EFI_TIME * Time OPTIONAL - ) __attribute((regparm(0))); + ); typedef enum { EfiResetCold, @@ -363,14 +362,14 @@ IN EFI_STATUS ResetStatus, IN EFI_UINTN DataSize, IN EFI_CHAR16 * ResetData OPTIONAL - ) __attribute__((regparm(0))); + ); typedef EFI_RUNTIMESERVICE EFI_STATUS (EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT) ( OUT EFI_UINT32 * HighCount - ) __attribute__((regparm(0))); + ); // // Definition of Status Code extended data header @@ -395,7 +394,7 @@ IN EFI_UINT32 Instance, IN EFI_GUID * CallerId OPTIONAL, IN EFI_STATUS_CODE_DATA * Data OPTIONAL - ) __attribute__((regparm(0))); + ); #endif // @@ -405,7 +404,8 @@ #define EFI_RUNTIME_SERVICES_REVISION ((EFI_SPECIFICATION_MAJOR_REVISION << 16) | (EFI_SPECIFICATION_MINOR_REVISION)) typedef struct { - STRUCT_EFI_TABLE_HEADER + EFI_TABLE_HEADER Hdr; + // // Time services // @@ -445,7 +445,8 @@ } __attribute__((aligned(8))) EFI_RUNTIME_SERVICES_32; typedef struct { - STRUCT_EFI_TABLE_HEADER + EFI_TABLE_HEADER Hdr; + // // Time services // @@ -507,7 +508,8 @@ #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | 10) typedef struct EFI_SYSTEM_TABLE_32 { - STRUCT_EFI_TABLE_HEADER + EFI_TABLE_HEADER Hdr; + EFI_PTR32 FirmwareVendor; EFI_UINT32 FirmwareRevision; @@ -529,7 +531,8 @@ } __attribute__((aligned(8))) EFI_SYSTEM_TABLE_32; typedef struct EFI_SYSTEM_TABLE_64 { - STRUCT_EFI_TABLE_HEADER + EFI_TABLE_HEADER Hdr; + EFI_PTR64 FirmwareVendor; EFI_UINT32 FirmwareRevision; Index: branches/cparm/i386/libsaio/bootstruct.c =================================================================== --- branches/cparm/i386/libsaio/bootstruct.c (revision 1118) +++ branches/cparm/i386/libsaio/bootstruct.c (revision 1119) @@ -156,11 +156,17 @@ if (memoryMapCount == 0) { // XXX could make a two-part map here - stop("Unable to convert memory map into proper format\n"); + stop("No memory map found\n"); } + + // convert memory map to boot_args memory map memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount); + if (memoryMap == NULL) { + + stop("Unable to allocate kernel space for the memory map\n"); + } bootArgs->MemoryMap = (uint32_t)memoryMap; bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount; bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange); @@ -212,11 +218,19 @@ */ sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT); break; + default: + break; } } - + if (sane_size == 0) { + + // I Guess that if sane_size == 0 we've got a big problem here, + // and it means that the memory map was not converted properly + stop("Unable to convert memory map into proper format\n"); + } + #define MEG (1024*1024) /* @@ -227,10 +241,7 @@ sane_size = (sane_size + 128 * MEG - 1) & ~((uint64_t)(128 * MEG - 1)); bootArgs->PhysicalMemorySize = sane_size; bootArgs->FSBFrequency = Platform->CPU.FSBFrequency; - - // copy bootFile into device tree - // XXX - + // add PCI info somehow into device tree // XXX @@ -243,5 +254,6 @@ DT__FlattenDeviceTree((void **)&addr, &size); bootArgs->deviceTreeP = (uint32_t)addr; - bootArgs->deviceTreeLength = size; + bootArgs->deviceTreeLength = size; + } Index: branches/cparm/i386/libsaio/cpuid.h =================================================================== --- branches/cparm/i386/libsaio/cpuid.h (revision 0) +++ branches/cparm/i386/libsaio/cpuid.h (revision 1119) @@ -0,0 +1,322 @@ +/* + * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + */ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * x86 CPU identification + * + */ + +#ifndef _MACHINE_CPUID_H_ +#define _MACHINE_CPUID_H_ + +#include + +#define CPUID_VID_INTEL "GenuineIntel" +#define CPUID_VID_AMD "AuthenticAMD" + +#define CPUID_STRING_UNKNOWN "Unknown CPU Typ" + +#define _Bit(n) (1ULL << n) +#define _HBit(n) (1ULL << ((n)+32)) + +/* + * The CPUID_FEATURE_XXX values define 64-bit values + * returned in %ecx:%edx to a CPUID request with %eax of 1: + */ +#define CPUID_FEATURE_FPU _Bit(0) /* Floating point unit on-chip */ +#define CPUID_FEATURE_VME _Bit(1) /* Virtual Mode Extension */ +#define CPUID_FEATURE_DE _Bit(2) /* Debugging Extension */ +#define CPUID_FEATURE_PSE _Bit(3) /* Page Size Extension */ +#define CPUID_FEATURE_TSC _Bit(4) /* Time Stamp Counter */ +#define CPUID_FEATURE_MSR _Bit(5) /* Model Specific Registers */ +#define CPUID_FEATURE_PAE _Bit(6) /* Physical Address Extension */ +#define CPUID_FEATURE_MCE _Bit(7) /* Machine Check Exception */ +#define CPUID_FEATURE_CX8 _Bit(8) /* CMPXCHG8B */ +#define CPUID_FEATURE_APIC _Bit(9) /* On-chip APIC */ +#define CPUID_FEATURE_SEP _Bit(11) /* Fast System Call */ +#define CPUID_FEATURE_MTRR _Bit(12) /* Memory Type Range Register */ +#define CPUID_FEATURE_PGE _Bit(13) /* Page Global Enable */ +#define CPUID_FEATURE_MCA _Bit(14) /* Machine Check Architecture */ +#define CPUID_FEATURE_CMOV _Bit(15) /* Conditional Move Instruction */ +#define CPUID_FEATURE_PAT _Bit(16) /* Page Attribute Table */ +#define CPUID_FEATURE_PSE36 _Bit(17) /* 36-bit Page Size Extension */ +#define CPUID_FEATURE_PSN _Bit(18) /* Processor Serial Number */ +#define CPUID_FEATURE_CLFSH _Bit(19) /* CLFLUSH Instruction supported */ +#define CPUID_FEATURE_DS _Bit(21) /* Debug Store */ +#define CPUID_FEATURE_ACPI _Bit(22) /* Thermal monitor and Clock Ctrl */ +#define CPUID_FEATURE_MMX _Bit(23) /* MMX supported */ +#define CPUID_FEATURE_FXSR _Bit(24) /* Fast floating pt save/restore */ +#define CPUID_FEATURE_SSE _Bit(25) /* Streaming SIMD extensions */ +#define CPUID_FEATURE_SSE2 _Bit(26) /* Streaming SIMD extensions 2 */ +#define CPUID_FEATURE_SS _Bit(27) /* Self-Snoop */ +#define CPUID_FEATURE_HTT _Bit(28) /* Hyper-Threading Technology */ +#define CPUID_FEATURE_TM _Bit(29) /* Thermal Monitor (TM1) */ +#define CPUID_FEATURE_PBE _Bit(31) /* Pend Break Enable */ + +#define CPUID_FEATURE_SSE3 _HBit(0) /* Streaming SIMD extensions 3 */ +#define CPUID_FEATURE_PCLMULQDQ _HBit(1) /* PCLMULQDQ instruction */ +#define CPUID_FEATURE_DTES64 _HBit(2) /* 64-bit DS layout */ +#define CPUID_FEATURE_MONITOR _HBit(3) /* Monitor/mwait */ +#define CPUID_FEATURE_DSCPL _HBit(4) /* Debug Store CPL */ +#define CPUID_FEATURE_VMX _HBit(5) /* VMX */ +#define CPUID_FEATURE_SMX _HBit(6) /* SMX */ +#define CPUID_FEATURE_EST _HBit(7) /* Enhanced SpeedsTep (GV3) */ +#define CPUID_FEATURE_TM2 _HBit(8) /* Thermal Monitor 2 */ +#define CPUID_FEATURE_SSSE3 _HBit(9) /* Supplemental SSE3 instructions */ +#define CPUID_FEATURE_CID _HBit(10) /* L1 Context ID */ +#define CPUID_FEATURE_CX16 _HBit(13) /* CmpXchg16b instruction */ +#define CPUID_FEATURE_xTPR _HBit(14) /* Send Task PRiority msgs */ +#define CPUID_FEATURE_PDCM _HBit(15) /* Perf/Debug Capability MSR */ + +#define CPUID_FEATURE_DCA _HBit(18) /* Direct Cache Access */ +#define CPUID_FEATURE_SSE4_1 _HBit(19) /* Streaming SIMD extensions 4.1 */ +#define CPUID_FEATURE_SSE4_2 _HBit(20) /* Streaming SIMD extensions 4.2 */ +#define CPUID_FEATURE_xAPIC _HBit(21) /* Extended APIC Mode */ +#define CPUID_FEATURE_MOVBE _HBit(22) /* MOVBE instruction */ +#define CPUID_FEATURE_POPCNT _HBit(23) /* POPCNT instruction */ +#define CPUID_FEATURE_AES _HBit(25) /* AES instructions */ +#define CPUID_FEATURE_XSAVE _HBit(26) /* XSAVE instructions */ +#define CPUID_FEATURE_OSXSAVE _HBit(27) /* XGETBV/XSETBV instructions */ +#define CPUID_FEATURE_VMM _HBit(31) /* VMM (Hypervisor) present */ +#define CPUID_FEATURE_SEGLIM64 _HBit(11) /* 64-bit segment limit checking */ +#define CPUID_FEATURE_PCID _HBit(17) /* ASID-PCID support */ +#define CPUID_FEATURE_TSCTMR _HBit(24) /* TSC deadline timer */ +#define CPUID_FEATURE_AVX1_0 _HBit(28) /* AVX 1.0 instructions */ + +/* + * The CPUID_EXTFEATURE_XXX values define 64-bit values + * returned in %ecx:%edx to a CPUID request with %eax of 0x80000001: + */ +#define CPUID_EXTFEATURE_SYSCALL _Bit(11) /* SYSCALL/sysret */ +#define CPUID_EXTFEATURE_XD _Bit(20) /* eXecute Disable */ + +#define CPUID_EXTFEATURE_1GBPAGE _Bit(26) /* 1GB pages */ +#define CPUID_EXTFEATURE_RDTSCP _Bit(27) /* RDTSCP */ +#define CPUID_EXTFEATURE_EM64T _Bit(29) /* Extended Mem 64 Technology */ + +#define CPUID_EXTFEATURE_LAHF _HBit(0) /* LAFH/SAHF instructions */ + +/* + * The CPUID_EXTFEATURE_XXX values define 64-bit values + * returned in %ecx:%edx to a CPUID request with %eax of 0x80000007: + */ +#define CPUID_EXTFEATURE_TSCI _Bit(8) /* TSC Invariant */ + +#define CPUID_CACHE_SIZE 16 /* Number of descriptor values */ + +#define CPUID_MWAIT_EXTENSION _Bit(0) /* enumeration of WMAIT extensions */ +#define CPUID_MWAIT_BREAK _Bit(1) /* interrupts are break events */ + +#define CPUID_MODEL_YONAH 0x0E +#define CPUID_MODEL_MEROM 0x0F +#define CPUID_MODEL_PENRYN 0x17 +#define CPUID_MODEL_NEHALEM 0x1A +#define CPUID_MODEL_FIELDS 0x1E /* Lynnfield, Clarksfield, Jasper */ +#define CPUID_MODEL_DALES 0x1F /* Havendale, Auburndale */ +#define CPUID_MODEL_NEHALEM_EX 0x2E +#define CPUID_MODEL_DALES_32NM 0x25 /* Clarkdale, Arrandale */ +#define CPUID_MODEL_WESTMERE 0x2C /* Gulftown, Westmere-EP, Westmere-WS */ +#define CPUID_MODEL_WESTMERE_EX 0x2F +/* Additional internal models go here */ +#define CPUID_MODEL_SANDYBRIDGE 0x2A +#define CPUID_MODEL_JAKETOWN 0x2D + +typedef enum { eax, ebx, ecx, edx } cpuid_register_t; + +#if UNUSED +static inline void +cpuid(uint32_t *data) +{ + asm("cpuid" + : "=a" (data[eax]), + "=b" (data[ebx]), + "=c" (data[ecx]), + "=d" (data[edx]) + : "a" (data[eax]), + "b" (data[ebx]), + "c" (data[ecx]), + "d" (data[edx])); +} +#endif + +static inline void +do_cpuid(uint32_t selector, uint32_t *data) +{ + asm("cpuid" + : "=a" (data[0]), + "=b" (data[1]), + "=c" (data[2]), + "=d" (data[3]) + : "a"(selector), + "b" (0), + "c" (0), + "d" (0)); +} + +/* + * Cache ID descriptor structure, used to parse CPUID leaf 2. + * Note: not used in kernel. + */ +typedef enum { Lnone, L1I, L1D, L2U, L3U, LCACHE_MAX } cache_type_t ; +typedef struct { + unsigned char value; /* Descriptor value */ + cache_type_t type; /* Cache type */ + unsigned int size; /* Cache size */ + unsigned int linesize; /* Cache line size */ +#ifdef KERNEL + const char *description; /* Cache description */ +#endif /* KERNEL */ +} cpuid_cache_desc_t; + +#ifdef KERNEL +#define CACHE_DESC(value,type,size,linesize,text) \ + { value, type, size, linesize, text } +#else +#define CACHE_DESC(value,type,size,linesize,text) \ + { value, type, size, linesize } +#endif /* KERNEL */ + +/* Monitor/mwait Leaf: */ +typedef struct { + uint32_t linesize_min; + uint32_t linesize_max; + uint32_t extensions; + uint32_t sub_Cstates; +} cpuid_mwait_leaf_t; + +/* Thermal and Power Management Leaf: */ +typedef struct { + boolean_t sensor; + boolean_t dynamic_acceleration; + boolean_t invariant_APIC_timer; + boolean_t core_power_limits; + boolean_t fine_grain_clock_mod; + boolean_t package_thermal_intr; + uint32_t thresholds; + boolean_t ACNT_MCNT; + boolean_t hardware_feedback; + boolean_t energy_policy; +} cpuid_thermal_leaf_t; + + +/* XSAVE Feature Leaf: */ +typedef struct { + uint32_t extended_state[4]; /* eax .. edx */ +} cpuid_xsave_leaf_t; + + +/* Architectural Performance Monitoring Leaf: */ +typedef struct { + uint8_t version; + uint8_t number; + uint8_t width; + uint8_t events_number; + uint32_t events; + uint8_t fixed_number; + uint8_t fixed_width; +} cpuid_arch_perf_leaf_t; + +/* Physical CPU info - this is exported out of the kernel (kexts), so be wary of changes */ +typedef struct { + char cpuid_vendor[16]; + char cpuid_brand_string[48]; + const char *cpuid_model_string; + + cpu_type_t cpuid_type; /* this is *not* a cpu_type_t in our */ + uint8_t cpuid_family; + uint8_t cpuid_model; + uint8_t cpuid_extmodel; + uint8_t cpuid_extfamily; + uint8_t cpuid_stepping; + uint64_t cpuid_features; + uint64_t cpuid_extfeatures; + uint32_t cpuid_signature; + uint8_t cpuid_brand; + + uint32_t cache_size[LCACHE_MAX]; + uint32_t cache_linesize; + + uint8_t cache_info[64]; /* list of cache descriptors */ + + uint32_t cpuid_cores_per_package; + uint32_t cpuid_logical_per_package; + uint32_t cache_sharing[LCACHE_MAX]; + uint32_t cache_partitions[LCACHE_MAX]; + + cpu_type_t cpuid_cpu_type; /* */ + cpu_subtype_t cpuid_cpu_subtype; /* */ + + /* Per-vendor info */ + cpuid_mwait_leaf_t cpuid_mwait_leaf; +#define cpuid_mwait_linesize_max cpuid_mwait_leaf.linesize_max +#define cpuid_mwait_linesize_min cpuid_mwait_leaf.linesize_min +#define cpuid_mwait_extensions cpuid_mwait_leaf.extensions +#define cpuid_mwait_sub_Cstates cpuid_mwait_leaf.sub_Cstates + cpuid_thermal_leaf_t cpuid_thermal_leaf; + cpuid_arch_perf_leaf_t cpuid_arch_perf_leaf; + cpuid_xsave_leaf_t cpuid_xsave_leaf; + + /* Cache details: */ + uint32_t cpuid_cache_linesize; + uint32_t cpuid_cache_L2_associativity; + uint32_t cpuid_cache_size; + + /* Virtual and physical address aize: */ + uint32_t cpuid_address_bits_physical; + uint32_t cpuid_address_bits_virtual; + + uint32_t cpuid_microcode_version; + + /* Numbers of tlbs per processor [i|d, small|large, level0|level1] */ + uint32_t cpuid_tlb[2][2][2]; + #define TLB_INST 0 + #define TLB_DATA 1 + #define TLB_SMALL 0 + #define TLB_LARGE 1 + uint32_t cpuid_stlb; + + uint32_t core_count; + uint32_t thread_count; + + /* Max leaf ids available from CPUID */ + uint32_t cpuid_max_basic; + uint32_t cpuid_max_ext; + + /* Family-specific info links */ + uint32_t cpuid_cpufamily; + cpuid_mwait_leaf_t *cpuid_mwait_leafp; + cpuid_thermal_leaf_t *cpuid_thermal_leafp; + cpuid_arch_perf_leaf_t *cpuid_arch_perf_leafp; + cpuid_xsave_leaf_t *cpuid_xsave_leafp; +} i386_cpu_info_t; + + +#endif /* _MACHINE_CPUID_H_ */ Index: branches/cparm/i386/libsaio/io_inline.h =================================================================== --- branches/cparm/i386/libsaio/io_inline.h (revision 1118) +++ branches/cparm/i386/libsaio/io_inline.h (revision 1119) @@ -35,6 +35,7 @@ #ifndef __LIBSAIO_IO_INLINE_H #define __LIBSAIO_IO_INLINE_H + /* *############################################################################ * @@ -80,4 +81,26 @@ __OUT(l, long) /* outl() */ +static inline void cmos_write_byte (int loc, int val) +{ + outb (0x70, loc); + outb (0x71, val); +} + +static inline unsigned cmos_read_byte (int loc) +{ + outb (0x70, loc); + return inb (0x71); +} + +#define CMOS_WRITE_BYTE(x, y) cmos_write_byte(x, y) +#define CMOS_READ_BYTE(x) cmos_read_byte(x) + +static inline void cli() { + asm("cli"); +} +static inline void sti() { + asm("sti"); +} + #endif /* !__LIBSAIO_IO_INLINE_H */ Index: branches/cparm/i386/libsaio/vbe.c =================================================================== --- branches/cparm/i386/libsaio/vbe.c (revision 1118) +++ branches/cparm/i386/libsaio/vbe.c (revision 1119) @@ -96,13 +96,13 @@ /* * Default GTF parameter values. */ -#define kCellGranularity 8.0 // character cell granularity -#define kMinVSyncPlusBP 550.0 // min VSync + BP interval (us) -#define kMinFrontPorch 1.0 // minimum front porch in lines(V)/cells(H) -#define kVSyncLines 3.0 // width of VSync in lines -#define kHSyncWidth 8.0 // HSync as a percent of total line width -#define kC 30.0 // C = (C'-J) * (K/256) + J -#define kM 300.0 // M = K/256 * M' +//#define kCellGranularity 8.0 // character cell granularity +//#define kMinVSyncPlusBP 550.0 // min VSync + BP interval (us) +//#define kMinFrontPorch 1.0 // minimum front porch in lines(V)/cells(H) +//#define kVSyncLines 3.0 // width of VSync in lines +//#define kHSyncWidth 8.0 // HSync as a percent of total line width +//#define kC 30.0 // C = (C'-J) * (K/256) + J +//#define kM 300.0 // M = K/256 * M' int Round(double f) { Index: branches/cparm/i386/libsaio/bootstruct.h =================================================================== --- branches/cparm/i386/libsaio/bootstruct.h (revision 1118) +++ branches/cparm/i386/libsaio/bootstruct.h (revision 1119) @@ -25,12 +25,10 @@ #ifndef __BOOTSTRUCT_H #define __BOOTSTRUCT_H -//#include #include "bootLion.h" #include "saio_types.h" #include "bios.h" #include "device_tree.h" -#include "efi.h" /*! Kernel boot args global also used by booter for its own data. */ @@ -136,7 +134,6 @@ unsigned long adler32; char uuidStr[64+1]; //boot device uuid - EFI_CHAR8 sysid[16]; } PrivateBootInfo_t; extern PrivateBootInfo_t *bootInfo; Index: branches/cparm/i386/libsaio/device_tree.c =================================================================== --- branches/cparm/i386/libsaio/device_tree.c (revision 1118) +++ branches/cparm/i386/libsaio/device_tree.c (revision 1119) @@ -80,7 +80,7 @@ allocedProperties = prop; prop->value = buf; prop++; - for (i=1; i<(kAllocSize / sizeof(Property)); i++) { + for (i=1; (unsigned)i<(kAllocSize / sizeof(Property)); i++) { prop->next = freeProperties; freeProperties = prop; prop++; @@ -129,7 +129,7 @@ allocedNodes = node; node->children = (Node *)buf; node++; - for (i=1; i<(kAllocSize / sizeof(Node)); i++) { + for (i=1; (unsigned)i<(kAllocSize / sizeof(Node)); i++) { node->next = freeNodes; freeNodes = node; node++; Index: branches/cparm/i386/libsaio/hfs.c =================================================================== --- branches/cparm/i386/libsaio/hfs.c (revision 1118) +++ branches/cparm/i386/libsaio/hfs.c (revision 1119) @@ -516,6 +516,8 @@ *flags = kFileTypeUnknown; tmpTime = 0; break; + default: + break; } if (time != 0) { @@ -788,6 +790,7 @@ case kHFSPlusFileRecord : entrySize = 248; break; case kHFSPlusFolderThreadRecord : entrySize = 264; break; case kHFSPlusFileThreadRecord : entrySize = 264; break; + default : break; } } else { if (gIsHFSPlus) entrySize = sizeof(HFSPlusExtentRecord); @@ -892,7 +895,7 @@ // MacWen: fix overflow in multiplication by forcing 64bit multiplication readSize = (long long)GetExtentSize(currentExtent, 0) * gBlockSize - readOffset; - if (readSize > (size - sizeRead)) readSize = size - sizeRead; + if (readSize > (long long)(size - sizeRead)) readSize = size - sizeRead; readOffset += (long long)GetExtentStart(currentExtent, 0) * gBlockSize; Index: branches/cparm/i386/libsaio/allocate.c =================================================================== --- branches/cparm/i386/libsaio/allocate.c (revision 1118) +++ branches/cparm/i386/libsaio/allocate.c (revision 1119) @@ -32,9 +32,13 @@ #define kPageSize 4096 #define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1)) - +#if UNUSED long AllocateMemoryRange(char * rangeName, long start, long length, long type) +#else +long +AllocateMemoryRange(char * rangeName, long start, long length) +#endif { char *nameBuf; uint32_t *buffer; Index: branches/cparm/i386/libsaio/Makefile =================================================================== --- branches/cparm/i386/libsaio/Makefile (revision 1118) +++ branches/cparm/i386/libsaio/Makefile (revision 1119) @@ -16,7 +16,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float + -march=pentium4 -msse2 -mfpmath=sse -msoft-float DEFINES= CONFIG = hd @@ -41,7 +41,7 @@ cpu.o platform.o \ fake_efi.o \ device_inject.o pci_root.o \ - convert.o + convert.o acpi_tools.o smbios.o smp.o # Options enabled by default: #CFLAGS += -DNO_WIN_SUPPORT # -7200 bytes @@ -92,6 +92,13 @@ # ar q $(SYMROOT)/$@ $(SAIO_OBJS) # ranlib $(SYMROOT)/$@ +fake_efi.o: vers.h +vers.h: + @echo "#define I386BOOT_VERSION \"5.0.132\"" > $(SYMROOT)/vers.h + @echo "#define I386BOOT_BUILDDATE \"`date \"+%Y-%m-%d %H:%M:%S\"`\"" >> $(SYMROOT)/vers.h + @echo "#define I386BOOT_CHAMELEONVERSION \"`cat ../../version`\"" >> $(SYMROOT)/vers.h + @echo "#define I386BOOT_CHAMELEONREVISION \"`svnversion -n | tr -d [:alpha:]`\"" >> $(SYMROOT)/vers.h + libsaio.a: $(SAIO_EXTERN_OBJS) $(SAIO_OBJS) rm -f $(SYMROOT)/$(@F) ar q $(SYMROOT)/$(@F) $^ Index: branches/cparm/i386/libsaio/bios.h =================================================================== --- branches/cparm/i386/libsaio/bios.h (revision 1118) +++ branches/cparm/i386/libsaio/bios.h (revision 1119) @@ -29,7 +29,6 @@ #ifndef __LIBSAIO_BIOS_H #define __LIBSAIO_BIOS_H -//#include #include "bootLion.h" typedef union { Index: branches/cparm/i386/libsaio/SMBIOS.h =================================================================== --- branches/cparm/i386/libsaio/SMBIOS.h (revision 1118) +++ branches/cparm/i386/libsaio/SMBIOS.h (revision 1119) @@ -28,6 +28,53 @@ #ifndef _LIBSAIO_SMBIOS_H #define _LIBSAIO_SMBIOS_H +#include "libsaio.h" + +#define kIsServer "IsServer" +extern struct SMBEntryPoint *getSmbiosOriginal(); + +#define theUUID 0 +#define thePlatformName 1 +#define theProducBoard 2 +extern int readSMBIOS(int value); // value copied into the platform structure + +#define SMBIOS_RANGE_START 0x000F0000 +#define SMBIOS_RANGE_END 0x000FFFFF + +/* '_SM_' in little endian: */ +//#define SMBIOS_ANCHOR_UINT32_LE 0x5f4d535f + +// getting smbios addr with fast compare ops, late checksum testing ... +#define COMPARE_DWORD(a,b) ( *((u_int32_t *) a) == *((u_int32_t *) b) ) + + +// +// SMBIOS structure types. +// + +enum { + kSMBTypeBIOSInformation = 0, + kSMBTypeSystemInformation = 1, + kSMBTypeBaseBoard = 2, + kSMBTypeSystemEnclosure = 3, + kSMBTypeProcessorInformation = 4, + kSMBTypeMemoryModule = 6, + kSMBTypeCacheInformation = 7, + kSMBTypeSystemSlot = 9, + kSMBTypePhysicalMemoryArray = 16, + kSMBTypeMemoryDevice = 17, + kSMBType32BitMemoryErrorInfo = 18, + kSMBType64BitMemoryErrorInfo = 33, + + kSMBTypeEndOfTable = 127, + + /* Apple Specific Structures */ + kSMBTypeFirmwareVolume = 128, + kSMBTypeMemorySPD = 130, + kSMBTypeOemProcessorType = 131, + kSMBTypeOemProcessorBusSpeed = 132 +}; + /* * Based on System Management BIOS Reference Specification v2.5 */ @@ -140,4 +187,25 @@ SMBString family; }__attribute__((packed)) SMBSystemInformation; +// +// Base Board (Type 2) +// +typedef struct SMBBaseBoard { + SMB_STRUCT_HEADER // Type 2 + SMBString manufacturer; + SMBString product; + SMBString version; + SMBString serialNumber; + SMBString assetTagNumber; + SMBByte featureFlags; + SMBString locationInChassis; + SMBWord chassisHandle; + SMBByte boardType; + SMBByte numberOfContainedHandles; + // 0 - 255 contained handles go here but we do not include + // them in our structure. Be careful to use numberOfContainedHandles + // times sizeof(SMBWord) when computing the actual record size, + // if you need it. +} __attribute__((packed)) SMBBaseBoard; + #endif /* !_LIBSAIO_SMBIOS_H */ Index: branches/cparm/i386/libsaio/pci_root.c =================================================================== --- branches/cparm/i386/libsaio/pci_root.c (revision 1118) +++ branches/cparm/i386/libsaio/pci_root.c (revision 1119) @@ -5,6 +5,7 @@ #include "libsaio.h" #include "boot.h" #include "bootstruct.h" +#include "Platform.h" #ifndef DEBUG_PCIROOT #define DEBUG_PCIROOT 1 @@ -18,6 +19,7 @@ static int rootuid = 10; //value means function wasnt ran yet + int getPciRootUID(void) { const char *val; @@ -28,19 +30,21 @@ if (getValueForKey(kPCIRootUID, &val, &len, &bootInfo->bootConfig)) { if (isdigit(val[0])) rootuid = val[0] - '0'; - } - /* Chameleon compatibility */ - else if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) { - if (isdigit(val[0])) rootuid = val[0] - '0'; - } + + if ( (rootuid >= 0) && (rootuid < 10) ) + goto out; + else + rootuid = 0; + } + /* PCEFI compatibility */ - else if (getValueForKey("-pci0", &val, &len, &bootInfo->bootConfig)) { + if (getValueForKey("-pci0", &val, &len, &bootInfo->bootConfig)) { rootuid = 0; } else if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) { rootuid = 1; } - +out: verbose("Using PCI-Root-UID value: %d\n", rootuid); return rootuid; } Index: branches/cparm/i386/libsaio/datatype.h =================================================================== --- branches/cparm/i386/libsaio/datatype.h (revision 0) +++ branches/cparm/i386/libsaio/datatype.h (revision 1119) @@ -0,0 +1,54 @@ +/* +Copyright (c) 2010, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DATATYPE_H +#define DATATYPE_H + +#include "libsa.h" + +typedef uint8_t U8; +typedef uint16_t U16; +typedef uint32_t U32; +typedef uint64_t U64; + +/* +//typedef uint32_t bool; +#ifndef false +#define true 1 +#endif + +#ifndef false +#define false 0 +#endif + +#ifndef NULL +#define NULL ((void *) 0) +#endif +*/ + +#endif /* DATATYPE_H */ Property changes on: branches/cparm/i386/libsaio/datatype.h ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/libsaio/pci_root.h =================================================================== --- branches/cparm/i386/libsaio/pci_root.h (revision 1118) +++ branches/cparm/i386/libsaio/pci_root.h (revision 1119) @@ -9,6 +9,5 @@ extern int getPciRootUID(void); -unsigned int findpciroot(unsigned char * dsdt,int len); #endif /* !__LIBSAIO_DSDT_PATCHER_H */ Index: branches/cparm/i386/libsaio/device_inject.c =================================================================== --- branches/cparm/i386/libsaio/device_inject.c (revision 1118) +++ branches/cparm/i386/libsaio/device_inject.c (revision 1119) @@ -317,7 +317,7 @@ buffer += 8; uint8_t *dataptr = string->entries[i]->data; - for(x = 0; x < (string->entries[i]->length) - (24 + (6 * string->entries[i]->num_pci_devpaths)) ; x++) + for(x = 0; (uint32_t)x < (string->entries[i]->length) - (24 + (6 * string->entries[i]->num_pci_devpaths)) ; x++) { sprintf(buffer, "%02x", *dataptr++); buffer += 2; Index: branches/cparm/i386/libsaio/ntfs.c =================================================================== --- branches/cparm/i386/libsaio/ntfs.c (revision 1118) +++ branches/cparm/i386/libsaio/ntfs.c (revision 1119) @@ -25,22 +25,22 @@ #include "libsaio.h" #include "sl.h" -#define BYTE_ORDER_MARK 0xFEFF +//#define BYTE_ORDER_MARK 0xFEFF #include "ntfs_private.h" -#define FS_TYPE "ntfs" -#define FS_NAME_FILE "NTFS" +//#define FS_TYPE "ntfs" +//#define FS_NAME_FILE "NTFS" #define MAX_BLOCK_SIZE 2048 #define MAX_CLUSTER_SIZE 32768 -#define LABEL_LENGTH 1024 -#define UNKNOWN_LABEL "Untitled NTFS" +//#define LABEL_LENGTH 1024 +//#define UNKNOWN_LABEL "Untitled NTFS" -#define FSUR_IO_FAIL -1 -#define FSUR_UNRECOGNIZED -1 -#define FSUR_RECOGNIZED 0 +//#define FSUR_IO_FAIL -1 +//#define FSUR_UNRECOGNIZED -1 +//#define FSUR_RECOGNIZED 0 #define ERROR -1 Index: branches/cparm/i386/libsaio/sys.c =================================================================== --- branches/cparm/i386/libsaio/sys.c (revision 1118) +++ branches/cparm/i386/libsaio/sys.c (revision 1119) @@ -182,8 +182,9 @@ const char *filePath; FSReadFile readFile; BVRef bvr; - unsigned long length, length2; - + unsigned long length/*, length2*/; + long length2; + // Resolve the boot volume from the file spec. if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) @@ -212,8 +213,10 @@ } else { // Not a fat binary; read the rest of the file length2 = readFile(bvr, (char *)filePath, (void *)(kLoadAddr + length), length, 0); - if (length2 == -1) return -1; - length += length2; + //if (length2 == -1) return -1; + if (length2 < 0) return -1; + + length += (unsigned long)length2; } } } else { @@ -378,8 +381,11 @@ //========================================================================== // open() - Open the file specified by 'path' for reading. - +#if UNUSED static int open_bvr(BVRef bvr, const char *filePath, int flags) +#else +static int open_bvr(BVRef bvr, const char *filePath) +#endif { struct iob *io; int fdesc; @@ -415,19 +421,31 @@ return fdesc; } +#if UNUSED int open(const char *path, int flags) +#else +int open(const char *path) +#endif { const char *filepath; BVRef bvr; // Resolve the boot volume from the file spec. if ((bvr = getBootVolumeRef(path, &filepath)) != NULL) { +#if UNUSED return open_bvr(bvr, filepath, flags); +#else + return open_bvr(bvr, filepath); +#endif } return -1; } +#if UNUSED int open_bvdev(const char *bvd, const char *path, int flags) +#else +int open_bvdev(const char *bvd, const char *path) +#endif { const struct devsw *dp; const char *cp; @@ -437,7 +455,7 @@ int unit; int partition; - if ((i = open(path, flags)) >= 0) { + if ((i = open(path)) >= 0) { return i; } @@ -466,7 +484,11 @@ } } bvr = newBootVolumeRef(dp->biosdev + unit, partition); - return open_bvr(bvr, path, flags); +#if UNUSED + return open_bvr(bvr, path, flags); +#else + return open_bvr(bvr, path); +#endif } } return -1; @@ -785,8 +807,11 @@ } //========================================================================== - +#if UNUSED void scanDisks(int biosdev, int *count) +#else +void scanDisks(void) +#endif { #define MAX_HDD_COUNT 32 int bvCount; Index: branches/cparm/i386/libsaio/load.c =================================================================== --- branches/cparm/i386/libsaio/load.c (revision 1118) +++ branches/cparm/i386/libsaio/load.c (revision 1119) @@ -327,8 +327,11 @@ gSymbolTableSize = totalSize + sizeof(struct symtab_command); gSymbolTableAddr = AllocateKernelMemory(gSymbolTableSize); // Add the SymTab to the memory-map. - AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize, -1); - +#if UNUSED + AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize, -1); +#else + AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize); +#endif symTableSave = (struct symtab_command *)gSymbolTableAddr; tmpAddr = gSymbolTableAddr + sizeof(struct symtab_command); Index: branches/cparm/i386/libsaio/acpi.h =================================================================== --- branches/cparm/i386/libsaio/acpi.h (revision 1118) +++ branches/cparm/i386/libsaio/acpi.h (revision 1119) @@ -1,27 +1,12 @@ #ifndef __LIBSAIO_ACPI_H #define __LIBSAIO_ACPI_H +#include "acpi_tools.h" + #define ACPI_RANGE_START (0x0E0000) #define ACPI_RANGE_END (0x0FFFFF) -/* - * SIGNATURE_16, SIGNATURE_32, SIGNATURE_64 are extracted from the edk2 project (Base.h), and are under the following license: - * - * Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. - * Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved. - * This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php. - * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - */ -#define SIGNATURE_16(A, B) ((A) | (B << 8)) - -#define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16)) - -#define SIGNATURE_64(A, B, C, D, E, F, G, H) \ -(SIGNATURE_32 (A, B, C, D) | ((uint64_t) (SIGNATURE_32 (E, F, G, H)) << 32)) - -#define ACPI_SIGNATURE_UINT64_LE SIGNATURE_64('R','S','D',' ','P','T','R',' ') - #define Unspecified 0 #define Desktop 1 #define Mobile 2 @@ -29,147 +14,8 @@ #define EnterpriseServer 4 #define SOHOServer 5 #define AppliancePC 6 - -#define MaxSupportedPMProfile AppliancePC // max profile currently supported + +#define MaxSupportedPMProfile AppliancePC // currently max profile supported #define PMProfileError MaxSupportedPMProfile + 1 -/* Per ACPI 3.0a spec */ - -// TODO Migrate -struct acpi_2_rsdp { - char Signature[8]; - uint8_t Checksum; - char OEMID[6]; - uint8_t Revision; - uint32_t RsdtAddress; - uint32_t Length; - uint64_t XsdtAddress; - uint8_t ExtendedChecksum; - char Reserved[3]; -} __attribute__((packed)); - - -#define ACPI_HEADER_CORE \ - 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; - -struct acpi_common_header { - ACPI_HEADER_CORE -} __attribute__((packed)); - -// TODO Migrate -struct acpi_2_rsdt { - ACPI_HEADER_CORE -} __attribute__((packed)); - -// TODO Migrate -struct acpi_2_xsdt { - ACPI_HEADER_CORE -} __attribute__((packed)); - -// TODO Migrate -struct acpi_2_gas { - uint8_t Address_Space_ID; - uint8_t Register_Bit_Width; - uint8_t Register_Bit_Offset; - uint8_t Access_Size; - uint64_t Address; -} __attribute__((packed)); - -// TODO Migrate -struct acpi_2_ssdt { - ACPI_HEADER_CORE -} __attribute__((packed)); - -// TODO Migrate -struct acpi_2_dsdt { - ACPI_HEADER_CORE -} __attribute__((packed)); - -// TODO Migrate -struct acpi_2_fadt { - ACPI_HEADER_CORE - uint32_t FIRMWARE_CTRL; - uint32_t DSDT; - uint8_t Model; // JrCs - uint8_t PM_Profile; // JrCs - uint16_t SCI_Interrupt; - uint32_t SMI_Command_Port; - uint8_t ACPI_Enable; - uint8_t ACPI_Disable; - uint8_t S4BIOS_Command; - uint8_t PState_Control; - uint32_t PM1A_Event_Block_Address; - uint32_t PM1B_Event_Block_Address; - uint32_t PM1A_Control_Block_Address; - uint32_t PM1B_Control_Block_Address; - uint32_t PM2_Control_Block_Address; - uint32_t PM_Timer_Block_Address; - uint32_t GPE0_Block_Address; - uint32_t GPE1_Block_Address; - uint8_t PM1_Event_Block_Length; - uint8_t PM1_Control_Block_Length; - uint8_t PM2_Control_Block_Length; - uint8_t PM_Timer_Block_Length; - uint8_t GPE0_Block_Length; - uint8_t GPE1_Block_Length; - uint8_t GPE1_Base_Offset; - uint8_t CST_Support; - uint16_t C2_Latency; - uint16_t C3_Latency; - uint16_t CPU_Cache_Size; - uint16_t Cache_Flush_Stride; - uint8_t Duty_Cycle_Offset; - uint8_t Duty_Cycle_Width; - uint8_t RTC_Day_Alarm_Index; - uint8_t RTC_Month_Alarm_Index; - uint8_t RTC_Century_Index; - uint16_t Boot_Flags; - uint8_t Reserved0; -/* Begin Asere */ - //Reset Fix - uint32_t Flags; - struct acpi_2_gas RESET_REG; - uint8_t Reset_Value; - uint8_t Reserved[3]; - - uint64_t X_FIRMWARE_CTRL; - uint64_t X_DSDT; - -#if UNUSED - /* End Asere */ - /*We absolutely don't care about theese fields*/ - uint8_t notimp2[96]; -#else - struct acpi_2_gas X_PM1a_EVT_BLK; - struct acpi_2_gas X_PM1b_EVT_BLK; - struct acpi_2_gas X_PM1a_CNT_BLK; - struct acpi_2_gas X_PM1b_CNT_BLK; - struct acpi_2_gas X_PM2_CNT_BLK; - struct acpi_2_gas X_PM_TMR_BLK; - struct acpi_2_gas X_GPE0_BLK; - struct acpi_2_gas X_GPE1_BLK; -#endif - -} __attribute__((packed)); - -struct acpi_2_facs { - char Signature[4]; - uint32_t Length; - uint32_t hardware_signature; - uint32_t firmware_waking_vector; - uint32_t global_lock; - uint32_t flags; - uint64_t x_firmware_waking_vector; - uint8_t version; - uint8_t Reserved[31]; -} __attribute__ ((packed)); - #endif /* !__LIBSAIO_ACPI_H */ Index: branches/cparm/i386/libsaio/platform.c =================================================================== --- branches/cparm/i386/libsaio/platform.c (revision 1118) +++ branches/cparm/i386/libsaio/platform.c (revision 1119) @@ -29,6 +29,12 @@ return (Platform->CPU.Features & feature); } +/** Return if a CPU Extended feature specified by feature is activated (true) or not (false) */ +inline bool platformCPUExtFeature(uint32_t feature) +{ + return (Platform->CPU.ExtFeatures & feature); +} + /** Scan platform hardware information, called by the main entry point (common_boot() ) _before_ bootConfig xml parsing settings are loaded Index: branches/cparm/i386/libsaio/cpu_data.h =================================================================== --- branches/cparm/i386/libsaio/cpu_data.h (revision 0) +++ branches/cparm/i386/libsaio/cpu_data.h (revision 1119) @@ -0,0 +1,344 @@ +/* + * Copyright (c) 2000-2008 Apple Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + */ +/* + * @OSF_COPYRIGHT@ + * + */ + +#ifndef I386_CPU_DATA +#define I386_CPU_DATA + +#include +#include + + +/* + * Data structures referenced (anonymously) from per-cpu data: + */ +struct cpu_cons_buffer; +struct cpu_desc_table; +struct mca_state; + + + +#if defined(__i386__) + +typedef struct { + struct i386_tss *cdi_ktss; +#if MACH_KDB + struct i386_tss *cdi_dbtss; +#endif /* MACH_KDB */ + struct __attribute__((packed)) { + uint16_t size; + struct fake_descriptor *ptr; + } cdi_gdt, cdi_idt; + struct fake_descriptor *cdi_ldt; + vm_offset_t cdi_sstk; +} cpu_desc_index_t; + +typedef enum { + TASK_MAP_32BIT, /* 32-bit, compatibility mode */ + TASK_MAP_64BIT, /* 64-bit, separate address space */ + TASK_MAP_64BIT_SHARED /* 64-bit, kernel-shared addr space */ +} task_map_t; + +#elif defined(__x86_64__) + + +typedef struct { + struct x86_64_tss *cdi_ktss; +#if MACH_KDB + struct x86_64_tss *cdi_dbtss; +#endif /* MACH_KDB */ + struct __attribute__((packed)) { + uint16_t size; + void *ptr; + } cdi_gdt, cdi_idt; + struct fake_descriptor *cdi_ldt; + vm_offset_t cdi_sstk; +} cpu_desc_index_t; + +typedef enum { + TASK_MAP_32BIT, /* 32-bit user, compatibility mode */ + TASK_MAP_64BIT, /* 64-bit user thread, shared space */ +} task_map_t; + +#else +#error Unsupported architecture +#endif + +/* + * This structure is used on entry into the (uber-)kernel on syscall from + * a 64-bit user. It contains the address of the machine state save area + * for the current thread and a temporary place to save the user's rsp + * before loading this address into rsp. + */ +typedef struct { + addr64_t cu_isf; /* thread->pcb->iss.isf */ + uint64_t cu_tmp; /* temporary scratch */ + addr64_t cu_user_gs_base; +} cpu_uber_t; + +/* + * Per-cpu data. + * + * Each processor has a per-cpu data area which is dereferenced through the + * current_cpu_datap() macro. For speed, the %gs segment is based here, and + * using this, inlines provides single-instruction access to frequently used + * members - such as get_cpu_number()/cpu_number(), and get_active_thread()/ + * current_thread(). + * + * Cpu data owned by another processor can be accessed using the + * cpu_datap(cpu_number) macro which uses the cpu_data_ptr[] array of per-cpu + * pointers. + */ +typedef struct cpu_data +{ + struct cpu_data *cpu_this; /* pointer to myself */ + thread_t cpu_active_thread; + void *cpu_int_state; /* interrupt state */ + vm_offset_t cpu_active_stack; /* kernel stack base */ + vm_offset_t cpu_kernel_stack; /* kernel stack top */ + vm_offset_t cpu_int_stack_top; + int cpu_preemption_level; + int cpu_simple_lock_count; + int cpu_interrupt_level; + int cpu_number; /* Logical CPU */ + int cpu_phys_number; /* Physical CPU */ + uint32_t cpu_id; /* Platform Expert */ + int cpu_signals; /* IPI events */ + int cpu_prior_signals; /* Last set of events, + * debugging + */ + int cpu_mcount_off; /* mcount recursion */ + uint32_t cpu_pending_ast; + int cpu_type; + int cpu_subtype; + int cpu_threadtype; + int cpu_running; + uint32_t rtclock_timer; + boolean_t cpu_is64bit; + task_map_t cpu_task_map; + volatile addr64_t cpu_task_cr3; + volatile addr64_t cpu_active_cr3; + addr64_t cpu_kernel_cr3; + cpu_uber_t cpu_uber; + void *cpu_chud; + void *cpu_console_buf; + uint32_t lcpu; + struct processor *cpu_processor; +#if NCOPY_WINDOWS > 0 + struct cpu_pmap *cpu_pmap; +#endif + struct cpu_desc_table *cpu_desc_tablep; + struct fake_descriptor *cpu_ldtp; + cpu_desc_index_t cpu_desc_index; + int cpu_ldt; +#ifdef MACH_KDB + /* XXX Untested: */ + int cpu_db_pass_thru; + vm_offset_t cpu_db_stacks; + void *cpu_kdb_saved_state; + spl_t cpu_kdb_saved_ipl; + int cpu_kdb_is_slave; + int cpu_kdb_active; +#endif /* MACH_KDB */ + boolean_t cpu_iflag; + boolean_t cpu_boot_complete; + int cpu_hibernate; + +#if NCOPY_WINDOWS > 0 + vm_offset_t cpu_copywindow_base; + uint64_t *cpu_copywindow_pdp; + + vm_offset_t cpu_physwindow_base; + uint64_t *cpu_physwindow_ptep; + void *cpu_hi_iss; +#endif + + + + volatile boolean_t cpu_tlb_invalid; + uint32_t cpu_hwIntCnt[256]; /* Interrupt counts */ + uint64_t cpu_dr7; /* debug control register */ + uint64_t cpu_int_event_time; /* intr entry/exit time */ +#if CONFIG_VMX + vmx_cpu_t cpu_vmx; /* wonderful world of virtualization */ +#endif +#if CONFIG_MCA + struct mca_state *cpu_mca_state; /* State at MC fault */ +#endif + uint64_t cpu_uber_arg_store; /* Double mapped address + * of current thread's + * uu_arg array. + */ + uint64_t cpu_uber_arg_store_valid; /* Double mapped + * address of pcb + * arg store + * validity flag. + */ + void *cpu_nanotime; /* Nanotime info */ + thread_t csw_old_thread; + thread_t csw_new_thread; + uint64_t cpu_max_observed_int_latency; + int cpu_max_observed_int_latency_vector; + uint64_t debugger_entry_time; + volatile boolean_t cpu_NMI_acknowledged; + /* A separate nested interrupt stack flag, to account + * for non-nested interrupts arriving while on the interrupt stack + * Currently only occurs when AICPM enables interrupts on the + * interrupt stack during processor offlining. + */ + uint32_t cpu_nested_istack; + uint32_t cpu_nested_istack_events; +} cpu_data_t; + +/* Macro to generate inline bodies to retrieve per-cpu data fields. */ +#ifndef offsetof +#define offsetof(TYPE,MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif /* offsetof */ +#define CPU_DATA_GET(member,type) \ + type ret; \ + __asm__ volatile ("mov %%gs:%P1,%0" \ + : "=r" (ret) \ + : "i" (offsetof(cpu_data_t,member))); \ + return ret; + +/* + * Everyone within the osfmk part of the kernel can use the fast + * inline versions of these routines. Everyone outside, must call + * the real thing, + */ +static inline thread_t +get_active_thread(void) +{ + CPU_DATA_GET(cpu_active_thread,thread_t) +} +#define current_thread_fast() get_active_thread() +#define current_thread() current_thread_fast() + +#if defined(__i386__) +static inline boolean_t +get_is64bit(void) +{ + CPU_DATA_GET(cpu_is64bit, boolean_t) +} +#define cpu_mode_is64bit() get_is64bit() +#elif defined(__x86_64__) +#define cpu_mode_is64bit() TRUE +#endif + +static inline int +get_preemption_level(void) +{ + CPU_DATA_GET(cpu_preemption_level,int) +} +static inline int +get_simple_lock_count(void) +{ + CPU_DATA_GET(cpu_simple_lock_count,int) +} +static inline int +get_interrupt_level(void) +{ + CPU_DATA_GET(cpu_interrupt_level,int) +} +static inline int +get_cpu_number(void) +{ + CPU_DATA_GET(cpu_number,int) +} +static inline int +get_cpu_phys_number(void) +{ + CPU_DATA_GET(cpu_phys_number,int) +} + +static inline void +disable_preemption(void) +{ + __asm__ volatile ("incl %%gs:%P0" + : + : "i" (offsetof(cpu_data_t, cpu_preemption_level))); +} +#if UNUSED +static inline void +enable_preemption(void) +{ + //assert(get_preemption_level() > 0); + + if (get_preemption_level() > 0){ + __asm__ volatile ("decl %%gs:%P0 \n\t" + "jne 1f \n\t" + "call _kernel_preempt_check \n\t" + "1:" + : /* no outputs */ + : "i" (offsetof(cpu_data_t, cpu_preemption_level)) + : "eax", "ecx", "edx", "cc", "memory"); + } +} +#endif +static inline void +enable_preemption_no_check(void) +{ + //assert(get_preemption_level() > 0); + + if (get_preemption_level() > 0){ + __asm__ volatile ("decl %%gs:%P0" + : /* no outputs */ + : "i" (offsetof(cpu_data_t, cpu_preemption_level)) + : "cc", "memory"); + } +} + +static inline void +mp_disable_preemption(void) +{ + disable_preemption(); +} +#if UNUSED +static inline void +mp_enable_preemption(void) +{ + enable_preemption(); +} +#endif +static inline void +mp_enable_preemption_no_check(void) +{ + enable_preemption_no_check(); +} + +static inline cpu_data_t * +current_cpu_datap(void) +{ + CPU_DATA_GET(cpu_this, cpu_data_t *); +} + + +#endif /* I386_CPU_DATA */ Index: branches/cparm/i386/libsaio/cpu.c =================================================================== --- branches/cparm/i386/libsaio/cpu.c (revision 1118) +++ branches/cparm/i386/libsaio/cpu.c (revision 1119) @@ -92,51 +92,28 @@ void scan_cpu(PlatformInfo_t *p) { - int i = 0; uint64_t tscFrequency, fsbFrequency, cpuFrequency; - uint64_t msr, flex_ratio; + uint64_t msr; uint8_t maxcoef, maxdiv, currcoef, currdiv; - + uint32_t reg[4]; + uint32_t CPUID[CPUID_MAX][4]; // CPUID 0..4, 80..81 Raw Values + uint32_t cores_per_package; + uint32_t logical_per_package; maxcoef = maxdiv = currcoef = currdiv = 0; - - /* get cpuid values */ - for( ; i <= 3; i++) - { - do_cpuid(i, p->CPU.CPUID[i]); - } - - do_cpuid2(0x00000004, 0, p->CPU.CPUID[CPUID_4]); - do_cpuid(0x80000000, p->CPU.CPUID[CPUID_80]); - if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) { - do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]); - } -#if DEBUG_CPU - { - int i; - printf("CPUID Raw Values:\n"); - for (i=0; iCPU.CPUID[i][0], p->CPU.CPUID[i][1], - p->CPU.CPUID[i][2], p->CPU.CPUID[i][3]); - } - } -#endif - p->CPU.Vendor = p->CPU.CPUID[CPUID_0][1]; - p->CPU.Signature = p->CPU.CPUID[CPUID_1][0]; - p->CPU.Stepping = bitfield(p->CPU.CPUID[CPUID_1][0], 3, 0); - p->CPU.Model = bitfield(p->CPU.CPUID[CPUID_1][0], 7, 4); - p->CPU.Family = bitfield(p->CPU.CPUID[CPUID_1][0], 11, 8); - p->CPU.ExtModel = bitfield(p->CPU.CPUID[CPUID_1][0], 19, 16); - p->CPU.ExtFamily = bitfield(p->CPU.CPUID[CPUID_1][0], 27, 20); - p->CPU.NoThreads = bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16); - p->CPU.NoCores = bitfield(p->CPU.CPUID[CPUID_4][0], 31, 26) + 1; - - p->CPU.Model += (p->CPU.ExtModel << 4); - - /* get brand string (if supported) */ + + do_cpuid(0, CPUID[0]); + p->CPU.Vendor = CPUID[CPUID_0][1]; + + do_cpuid2(0x00000004, 0, CPUID[CPUID_4]); + cores_per_package = bitfield(CPUID[CPUID_4][0], 31, 26) + 1; + + /* get extended cpuid results */ + do_cpuid(0x80000000, reg); + uint32_t cpuid_max_ext = reg[eax]; + + /* get brand string (if supported) */ /* Copyright: from Apple's XNU cpuid.c */ - if (p->CPU.CPUID[CPUID_80][0] > 0x80000004) { - uint32_t reg[4]; + if (cpuid_max_ext > 0x80000004) { char str[128], *s; /* * The brand string 48 bytes (max), guaranteed to @@ -154,27 +131,100 @@ strlcpy(p->CPU.BrandString, s, sizeof(p->CPU.BrandString)); - if (!strncmp(p->CPU.BrandString, CPU_STRING_UNKNOWN, min(sizeof(p->CPU.BrandString), strlen(CPU_STRING_UNKNOWN) + 1))) { - /* - * This string means we have a firmware-programmable brand string, - * and the firmware couldn't figure out what sort of CPU we have. - */ - p->CPU.BrandString[0] = '\0'; - } + if (!strncmp(p->CPU.BrandString, CPUID_STRING_UNKNOWN, min(sizeof(p->CPU.BrandString), (unsigned)strlen(CPUID_STRING_UNKNOWN) + 1))) { + /* + * This string means we have a firmware-programmable brand string, + * and the firmware couldn't figure out what sort of CPU we have. + */ + p->CPU.BrandString[0] = '\0'; + } + } + + /* get processor signature and decode */ + do_cpuid(1, reg); + p->CPU.Signature = reg[eax]; + p->CPU.Stepping = bitfield(reg[eax], 3, 0); + p->CPU.Model = bitfield(reg[eax], 7, 4); + p->CPU.Family = bitfield(reg[eax], 11, 8); + p->CPU.ExtModel = bitfield(reg[eax], 19, 16); + p->CPU.ExtFamily = bitfield(reg[eax], 27, 20); + p->CPU.Brand = bitfield(reg[ebx], 7, 0); + p->CPU.Features = quad(reg[ecx], reg[edx]); + //p->CPU.Type = bitfield(reg[eax], 13, 12); + + /* Fold extensions into family/model */ + if (p->CPU.Family == 0x0f) + p->CPU.Family += p->CPU.ExtFamily; + if (p->CPU.Family == 0x0f || p->CPU.Family == 0x06) + p->CPU.Model += (p->CPU.ExtModel << 4); + + if (p->CPU.Features & CPUID_FEATURE_HTT) + logical_per_package = + bitfield(reg[ebx], 23, 16); + else + logical_per_package = 1; + + if (cpuid_max_ext >= 0x80000001) { + do_cpuid(0x80000001, reg); + p->CPU.ExtFeatures = + quad(reg[ecx], reg[edx]); + } - - /* setup features */ - p->CPU.Features |= (CPU_FEATURE_MMX | CPU_FEATURE_SSE | CPU_FEATURE_SSE2 | CPU_FEATURE_MSR) & p->CPU.CPUID[CPUID_1][3]; - p->CPU.Features |= (CPU_FEATURE_SSE3 | CPU_FEATURE_SSE41 | CPU_FEATURE_SSE42) & p->CPU.CPUID[CPUID_1][2]; - p->CPU.Features |= (CPU_FEATURE_EM64T) & p->CPU.CPUID[CPUID_81][3]; - - - //if ((CPU_FEATURE_HTT & p->CPU.CPUID[CPUID_1][3]) != 0) { - if (p->CPU.NoThreads > p->CPU.NoCores) { - p->CPU.Features |= CPU_FEATURE_HTT; + + /* Fold in the Invariant TSC feature bit, if present */ + if (cpuid_max_ext >= 0x80000007) { + do_cpuid(0x80000007, reg); + p->CPU.ExtFeatures |= + reg[edx] & (uint32_t)CPUID_EXTFEATURE_TSCI; } - - + + /* Find the microcode version number a.k.a. signature a.k.a. BIOS ID */ + p->CPU.MicrocodeVersion = + (uint32_t) (rdmsr64(MSR_IA32_BIOS_SIGN_ID) >> 32); + + if ((p->CPU.Vendor == 0x756E6547 /* Intel */) && + (p->CPU.Family == 0x06)) { + /* + * Find the number of enabled cores and threads + * (which determines whether SMT/Hyperthreading is active). + */ + switch (p->CPU.Model) { + /* + * This should be the same as Nehalem but an A0 silicon bug returns + * invalid data in the top 12 bits. Hence, we use only bits [19..16] + * rather than [31..16] for core count - which actually can't exceed 8. + */ + case CPUID_MODEL_DALES_32NM: + case CPUID_MODEL_WESTMERE: + case CPUID_MODEL_WESTMERE_EX: + { + msr = rdmsr64(MSR_CORE_THREAD_COUNT); + p->CPU.NoThreads = bitfield((uint32_t)msr, 15, 0); + p->CPU.NoCores = bitfield((uint32_t)msr, 19, 16); + break; + } + + case CPUID_MODEL_NEHALEM: + case CPUID_MODEL_FIELDS: + case CPUID_MODEL_DALES: + case CPUID_MODEL_NEHALEM_EX: + case CPUID_MODEL_SANDYBRIDGE: + case CPUID_MODEL_JAKETOWN: + { + msr = rdmsr64(MSR_CORE_THREAD_COUNT); + p->CPU.NoThreads = bitfield((uint32_t)msr, 15, 0); + p->CPU.NoCores = bitfield((uint32_t)msr, 31, 16); + break; + } + } + } + + if (p->CPU.NoCores == 0) { + p->CPU.NoThreads = cores_per_package; + p->CPU.NoCores = logical_per_package; + } + + tscFrequency = measure_tsc_frequency(); fsbFrequency = 0; cpuFrequency = 0; @@ -188,33 +238,76 @@ (p->CPU.Family == 0x0f && p->CPU.Model >= 0x03)) { /* Nehalem CPU model */ - if (p->CPU.Family == 0x06 && (p->CPU.Model == 0x1a || p->CPU.Model == 0x1e || - p->CPU.Model == 0x1f || p->CPU.Model == 0x25 || - p->CPU.Model == 0x2c)) + if (p->CPU.Family == 0x06 && (p->CPU.Model == CPUID_MODEL_NEHALEM || + p->CPU.Model == CPUID_MODEL_FIELDS || + p->CPU.Model == CPUID_MODEL_DALES || + p->CPU.Model == CPUID_MODEL_DALES_32NM || + p->CPU.Model == CPUID_MODEL_WESTMERE || + p->CPU.Model == CPUID_MODEL_NEHALEM_EX || + p->CPU.Model == CPUID_MODEL_WESTMERE_EX || + p->CPU.Model == CPUID_MODEL_SANDYBRIDGE || + p->CPU.Model == CPUID_MODEL_JAKETOWN)) { + uint8_t bus_ratio_max = 0, bus_ratio_min = 0; + uint32_t max_ratio = 0; + uint64_t flex_ratio = 0; msr = rdmsr64(MSR_PLATFORM_INFO); +#if DEBUG_CPU DBG("msr(%d): platform_info %08x\n", __LINE__, msr & 0xffffffff); - currcoef = (msr >> 8) & 0xff; +#endif + bus_ratio_max = (msr >> 8) & 0xff; + bus_ratio_min = (msr >> 40) & 0xff; //valv: not sure about this one (Remarq.1) msr = rdmsr64(MSR_FLEX_RATIO); +#if DEBUG_CPU DBG("msr(%d): flex_ratio %08x\n", __LINE__, msr & 0xffffffff); - if ((msr >> 16) & 0x01) - { +#endif + if ((msr >> 16) & 0x01) { flex_ratio = (msr >> 8) & 0xff; - if (currcoef > flex_ratio) - { - currcoef = flex_ratio; + /* bcc9: at least on the gigabyte h67ma-ud2h, + where the cpu multipler can't be changed to + allow overclocking, the flex_ratio msr has unexpected (to OSX) + contents. These contents cause mach_kernel to + fail to compute the bus ratio correctly, instead + causing the system to crash since tscGranularity + is inadvertently set to 0. + */ + if (flex_ratio == 0) { + /* Clear bit 16 (evidently the + presence bit) */ + wrmsr64(MSR_FLEX_RATIO, (msr & 0xFFFFFFFFFFFEFFFFULL)); + msr = rdmsr64(MSR_FLEX_RATIO); +#if DEBUG_CPU + DBG("Unusable flex ratio detected. MSR Patched to %08x\n", msr & 0xffffffff); +#endif + } else { + if (bus_ratio_max > flex_ratio) { + bus_ratio_max = flex_ratio; + } } } - - if (currcoef) { - fsbFrequency = (tscFrequency / currcoef); + + if (bus_ratio_max) { + fsbFrequency = (tscFrequency / bus_ratio_max); } - cpuFrequency = tscFrequency; + //valv: Turbo Ratio Limit + if ((p->CPU.Model != 0x2e) && (p->CPU.Model != 0x2f)) { + msr = rdmsr64(MSR_TURBO_RATIO_LIMIT); + cpuFrequency = bus_ratio_max * fsbFrequency; + max_ratio = bus_ratio_max * 10; + } else { + cpuFrequency = tscFrequency; + } +#if DEBUG_CPU + DBG("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", fsbFrequency / 1000000, max_ratio); +#endif + currcoef = bus_ratio_max; } else { msr = rdmsr64(MSR_IA32_PERF_STATUS); +#if DEBUG_CPU DBG("msr(%d): ia32_perf_stat 0x%08x\n", __LINE__, msr & 0xffffffff); +#endif currcoef = (msr >> 8) & 0x1f; /* Non-integer bus ratio for the max-multi*/ maxdiv = (msr >> 46) & 0x01; @@ -253,43 +346,46 @@ { cpuFrequency = (fsbFrequency * currcoef); } +#if DEBUG_CPU DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : ""); +#endif } } } - - /* Mobile CPU ? */ + /* Mobile CPU ? */ //Slice - bool isMobile = false; + p->CPU.isMobile = false; switch (p->CPU.Model) { case 0x0D: - isMobile = true; // CPU_FEATURE_MOBILE; + p->CPU.isMobile = true; break; case 0x02: case 0x03: case 0x04: case 0x06: - isMobile = (rdmsr64(0x2C) & (1 << 21)); + p->CPU.isMobile = (rdmsr64(0x2C) & (1 << 21)); break; default: - isMobile = (rdmsr64(0x17) & (1 << 28)); + p->CPU.isMobile = (rdmsr64(0x17) & (1 << 28)); break; } - - if (isMobile) { - p->CPU.Features |= CPU_FEATURE_MOBILE; - } - - DBG("%s platform found.\n", isMobile?"Mobile":"Desktop"); + + DBG("%s platform found.\n", p->CPU.isMobile?"Mobile":"Desktop"); } p->CPU.MaxCoef = maxcoef; p->CPU.MaxDiv = maxdiv; p->CPU.CurrCoef = currcoef; p->CPU.CurrDiv = currdiv; + p->CPU.TSCFrequency = (tscFrequency / 1000000) * 1000000; p->CPU.FSBFrequency = (fsbFrequency / 1000000) * 1000000; p->CPU.CPUFrequency = (cpuFrequency / 1000000) * 1000000; + + //p->CPU.TSCFrequency = tscFrequency ; + //p->CPU.FSBFrequency = fsbFrequency ; + //p->CPU.CPUFrequency = cpuFrequency ; + DBG("CPU: Vendor/Model/ExtModel: 0x%x/0x%x/0x%x\n", p->CPU.Vendor, p->CPU.Model, p->CPU.ExtModel); DBG("CPU: Family/ExtFamily: 0x%x/0x%x\n", p->CPU.Family, p->CPU.ExtFamily); DBG("CPU: TSCFreq: %dMHz\n", p->CPU.TSCFrequency / 1000000); @@ -303,6 +399,8 @@ DBG("CPU: NoCores/NoThreads: %d/%d\n", p->CPU.NoCores, p->CPU.NoThreads); DBG("CPU: Features: 0x%08x\n", p->CPU.Features); + DBG("CPU: ExtFeatures: 0x%08x\n", p->CPU.ExtFeatures); // where is SYSCALL ?? + DBG("CPU: MicrocodeVersion: %d\n", p->CPU.MicrocodeVersion); #if DEBUG_CPU pause(); #endif Index: branches/cparm/i386/libsaio/platform.h =================================================================== --- branches/cparm/i386/libsaio/platform.h (revision 1118) +++ branches/cparm/i386/libsaio/platform.h (revision 1119) @@ -8,15 +8,19 @@ #define __LIBSAIO_PLATFORM_H #include "libsaio.h" +#include "cpuid.h" +#include "cpu_data.h" +extern bool platformCPUExtFeature(uint32_t); extern bool platformCPUFeature(uint32_t); extern void scan_platform(void); -#define bit(n) (1UL << (n)) -#define bitmask(h,l) ((bit(h)|(bit(h)-1)) & ~(bit(l)-1)) +#define bitmask(h,l) ((_Bit(h)|(_Bit(h)-1)) & ~(_Bit(l)-1)) #define bitfield(x,h,l) (((x) & bitmask(h,l)) >> l) +#define quad(hi,lo) (((uint64_t)(hi)) << 32 | (lo)) + /* CPUID index into cpuid_raw */ #define CPUID_0 0 #define CPUID_1 1 @@ -27,34 +31,11 @@ #define CPUID_81 6 #define CPUID_MAX 7 -#define CPU_MODEL_YONAH 0x0E -#define CPU_MODEL_MEROM 0x0F -#define CPU_MODEL_PENRYN 0x17 -#define CPU_MODEL_NEHALEM 0x1A -#define CPU_MODEL_ATOM 0x1C -#define CPU_MODEL_FIELDS 0x1E /* Lynnfield, Clarksfield, Jasper */ -#define CPU_MODEL_DALES 0x1F /* Havendale, Auburndale */ -#define CPU_MODEL_DALES_32NM 0x25 /* Clarkdale, Arrandale */ -#define CPU_MODEL_WESTMERE 0x2C /* Gulftown, Westmere-EP, Westmere-WS */ -#define CPU_MODEL_NEHALEM_EX 0x2E -#define CPU_MODEL_WESTMERE_EX 0x2F +/* Additional models supported by Chameleon (NOT SUPPORTED BY THE APPLE'S ORIGINAL KERNEL) */ +#define CPUID_MODEL_BANIAS 0x09 +#define CPUID_MODEL_DOTHAN 0x0D +#define CPUID_MODEL_ATOM 0x1C -/* CPU Features */ -// NOTE: Theses are currently mapped to the actual bit in the cpuid value -#define CPU_FEATURE_MMX bit(23) // MMX Instruction Set -#define CPU_FEATURE_SSE bit(25) // SSE Instruction Set -#define CPU_FEATURE_SSE2 bit(26) // SSE2 Instruction Set -#define CPU_FEATURE_SSE3 bit(0) // SSE3 Instruction Set -#define CPU_FEATURE_SSE41 bit(19) // SSE41 Instruction Set -#define CPU_FEATURE_SSE42 bit(20) // SSE42 Instruction Set -#define CPU_FEATURE_EM64T bit(29) // 64Bit Support -#define CPU_FEATURE_HTT bit(28) // HyperThreading -#define CPU_FEATURE_MSR bit(5) // MSR Support - -// NOTE: Determine correct bit for bellow (28 is already in use) -#define CPU_FEATURE_MOBILE bit(1) // Mobile CPU - - /* SMBIOS Memory Types */ #define SMB_MEM_TYPE_UNDEFINED 0 #define SMB_MEM_TYPE_OTHER 1 @@ -111,14 +92,15 @@ typedef struct _PlatformInfo_t { struct CPU { - uint32_t Features; // CPU Features like MMX, SSE2, VT, MobileCPU + uint64_t Features; // CPU Features like MMX, SSE2, VT ... + uint64_t ExtFeatures; // CPU Extended Features like SYSCALL, XD, EM64T, LAHF ... uint32_t Vendor; // Vendor uint32_t Signature; // Signature - uint32_t Stepping; // Stepping - uint32_t Model; // Model - uint32_t ExtModel; // Extended Model - uint32_t Family; // Family - uint32_t ExtFamily; // Extended Family + uint8_t Stepping; // Stepping + uint8_t Model; // Model + uint8_t ExtModel; // Extended Model + uint8_t Family; // Family + uint8_t ExtFamily; // Extended Family uint32_t NoCores; // No Cores per Package uint32_t NoThreads; // Threads per Package uint8_t MaxCoef; // Max Multiplier @@ -129,7 +111,10 @@ uint64_t FSBFrequency; // FSB Frequency Hz uint64_t CPUFrequency; // CPU Frequency Hz char BrandString[48]; // 48 Byte Branding String - uint32_t CPUID[CPUID_MAX][4]; // CPUID 0..4, 80..81 Raw Values + uint8_t Brand; + uint32_t MicrocodeVersion; // The microcode version number a.k.a. signature a.k.a. BIOS ID + bool isMobile; + bool isServer; // Unlike isMobile, if this value is set it will disable all kind of detection and enforce "Server" as platform (must be set by user) } CPU; struct RAM { @@ -151,10 +136,10 @@ int MemoryModules; // number of memory modules installed int DIMM[MAX_RAM_SLOTS]; // Information and SPD mapping for each slot } DMI; - uint8_t Type; // System Type: 1=Desktop, 2=Portable... according ACPI2.0 (FACP: PM_Profile) + uint8_t Type; // System Type: 1=Desktop, 2=Portable... according ACPI2.0 (FACP: PreferredProfile) uint8_t *UUID; // SMBios UUID - //char *Name; // the Platorm/Product name uint32_t hardware_signature; + int8_t sysid[16]; } PlatformInfo_t; extern PlatformInfo_t *Platform; Index: branches/cparm/i386/libsaio/disk.c =================================================================== --- branches/cparm/i386/libsaio/disk.c (revision 1118) +++ branches/cparm/i386/libsaio/disk.c (revision 1119) @@ -118,8 +118,10 @@ #define IORound(value,multiple) \ ((((value) + (multiple) - 1) / (multiple)) * (multiple)) +/* #define IOTrunc(value,multiple) \ (((value) / (multiple)) * (multiple)); +*/ /* * trackbuf points to the start of the track cache. Biosread() @@ -159,7 +161,7 @@ // Real BIOS devices are 8-bit, so anything above that is for internal use. // Don't cache ramdisk drive info since it doesn't require several BIOS // calls and is thus not worth it. - if(biosdev >= 0x100 && is_module_loaded("RamDiskLoader")) + if(biosdev >= 0x100 && execute_hook("isRamDiskRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { int ret = 0; execute_hook("p_get_ramdisk_info", &biosdev, (void *)dip, &ret, NULL, NULL, NULL); @@ -370,7 +372,7 @@ // ramdisks require completely different code for reading. - if(biosdev >= 0x100 && is_module_loaded("RamDiskLoader")){ + if(biosdev >= 0x100 && (execute_hook("isRamDiskRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS)){ int ret = -1; execute_hook("p_ramdiskReadBytes", &biosdev, &blkno, &byteoff, &byteCount, buffer, &ret); @@ -1158,7 +1160,7 @@ #ifndef NO_WIN_SUPPORT else if (NTFSProbe(probeBuffer)) result = FDISK_NTFS; - else if (fatbits=MSDOSProbe(probeBuffer)) + else if ((fatbits=MSDOSProbe(probeBuffer))) { switch (fatbits) { @@ -1197,13 +1199,13 @@ static BVRef diskScanGPTBootVolumes( int biosdev, int * countPtr ) { - if (biosdev >= 0x100 && (is_module_loaded("RamDiskLoader") == 0)) + if (biosdev >= 0x100 && (execute_hook("isRamDiskRegistred", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)) return NULL; struct DiskBVMap * map = NULL; void *buffer = malloc(BPS); int error; - if ( error = readBytes( biosdev, /*secno*/0, 0, BPS, buffer ) != 0) { + if ( (error = readBytes( biosdev, /*secno*/0, 0, BPS, buffer )) != 0) { DBG("Failed to read boot sector from BIOS device %02xh. Error=%d\n", biosdev, error); goto scanErr; } @@ -1232,7 +1234,7 @@ } if ( fdiskID == 0 ) goto scanErr; - verbose("Attempting to read GPT\n"); + DBG("Attempting to read GPT\n"); if(readBytes(biosdev, 1, 0, BPS, buffer) != 0) goto scanErr; @@ -1301,7 +1303,7 @@ if(readBytes(biosdev, gptBlock, 0, bufferSize, buffer) != 0) goto scanErr; - verbose("Read GPT\n"); + DBG("Read GPT\n"); // Allocate a new map for this BIOS device and insert it into the chain map = malloc(sizeof(*map)); @@ -1407,8 +1409,7 @@ 0, kBIOSDevTypeHardDrive, kBVFlagEFISystem); } break; -#ifndef NO_WIN_SUPPORT - +#ifndef NO_WIN_SUPPORT case FDISK_FAT32: if (testFAT32EFIBootSector( biosdev, gptMap->ent_lba_start, (void *)0x7e00 ) == 0) { @@ -1425,9 +1426,10 @@ } break; #endif - + default: if (biosdev == gBIOSDev) gBIOSBootVolume = bvr; + break; } } @@ -1487,7 +1489,7 @@ ret = GetFileInfo(dirSpec, fileSpec, &flags, &time); if (!ret) { - fh = open(strcat(dirSpec, fileSpec), 0); + fh = open(strcat(dirSpec, fileSpec)); fileSize = file_size(fh); if (fileSize > 0 && fileSize < BVSTRLEN) { Index: branches/cparm/i386/libsaio/smbios.c =================================================================== --- branches/cparm/i386/libsaio/smbios.c (revision 0) +++ branches/cparm/i386/libsaio/smbios.c (revision 1119) @@ -0,0 +1,128 @@ + + +#include "SMBIOS.h" +#include "Platform.h" +#include "boot.h" + +static const char * const SMTAG = "_SM_"; +static const char* const DMITAG= "_DMI_"; + +static struct SMBEntryPoint *getAddressOfSmbiosTable(void) +{ + struct SMBEntryPoint *smbios; + /* + * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking + * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_"). + */ + smbios = (struct SMBEntryPoint*) SMBIOS_RANGE_START; + while (smbios <= (struct SMBEntryPoint *)SMBIOS_RANGE_END) { + if (COMPARE_DWORD(smbios->anchor, SMTAG) && + COMPARE_DWORD(smbios->dmi.anchor, DMITAG) && + smbios->dmi.anchor[4]==DMITAG[4] && + checksum8(smbios, sizeof(struct SMBEntryPoint)) == 0) + { + return ((void*)smbios); + } + smbios = (struct SMBEntryPoint*) ( ((char*) smbios) + 16 ); + } + printf("Error: Could not find original SMBIOS !!\n"); + pause(); + return NULL; +} + +struct SMBEntryPoint *getSmbiosOriginal() +{ + static struct SMBEntryPoint *orig = NULL; // cached + + if (orig == NULL) { + orig = getAddressOfSmbiosTable(); + + if (orig) { + verbose("Found System Management BIOS (SMBIOS) table\n"); + } + + } + return orig; +} + +/* get UUID or product Name from original SMBIOS, stripped version of kabyl's readSMBIOSInfo */ +int readSMBIOS(int value) +{ + + SMBEntryPoint *eps = getSmbiosOriginal(); + if (eps == NULL) return 0; + + uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress; + SMBStructHeader *structHeader = (SMBStructHeader *)structPtr; + + for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));) + { + switch (structHeader->type) + { + case kSMBTypeSystemInformation: + { + switch (value) { + case theUUID: + Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid; + return 1; + break; + case thePlatformName: + { + uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length; + uint8_t field = ((SMBSystemInformation *)structHeader)->productName; + + if (!field) + return 0; + + for (field--; field != 0 && strlen((char *)stringPtr) > 0; + field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1)); + + //DBG("original SMBIOS Product name: %s\n",(char *)stringPtr); + gPlatformName = (char *)stringPtr; + if (gPlatformName) return 1; + break; + } + default: + break; + } + + break; + } + case kSMBTypeBaseBoard: + { + switch (value) { + case theProducBoard: + { + uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length; + uint8_t field = ((SMBBaseBoard *)structHeader)->product; + + if (!field) + return 0; + + for (field--; field != 0 && strlen((char *)stringPtr) > 0; + field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1)); + + gboardproduct = (char *)stringPtr; + if (gboardproduct) return 1; + break; + } + default: + break; + } + break; + } + default: + break; + + } + + structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length); + for (; ((uint16_t *)structPtr)[0] != 0; structPtr++); + + if (((uint16_t *)structPtr)[0] == 0) + structPtr += 2; + + structHeader = (SMBStructHeader *)structPtr; + } + return 0; +} \ No newline at end of file Index: branches/cparm/i386/libsaio/cpu.h =================================================================== --- branches/cparm/i386/libsaio/cpu.h (revision 1118) +++ branches/cparm/i386/libsaio/cpu.h (revision 1119) @@ -10,17 +10,14 @@ extern void scan_cpu(PlatformInfo_t *); -#define bit(n) (1UL << (n)) -#define bitmask(h,l) ((bit(h)|(bit(h)-1)) & ~(bit(l)-1)) -#define bitfield(x,h,l) (((x) & bitmask(h,l)) >> l) - -#define CPU_STRING_UNKNOWN "Unknown CPU Typ" - #define MSR_IA32_PERF_STATUS 0x198 #define MSR_IA32_PERF_CONTROL 0x199 #define MSR_IA32_EXT_CONFIG 0x00EE #define MSR_FLEX_RATIO 0x194 #define MSR_PLATFORM_INFO 0xCE +#define MSR_TURBO_RATIO_LIMIT 0x1AD +#define MSR_IA32_BIOS_SIGN_ID 0x08B +#define MSR_CORE_THREAD_COUNT 0x035 #define K8_FIDVID_STATUS 0xC0010042 #define K10_COFVID_STATUS 0xC0010071 @@ -57,16 +54,6 @@ while (rdmsr64(MSR_IA32_PERF_STATUS) & (1 << 21)) { if (!inline_timeout--) break; } } -static inline void do_cpuid(uint32_t selector, uint32_t *data) -{ - asm volatile ("cpuid" - : "=a" (data[0]), - "=b" (data[1]), - "=c" (data[2]), - "=d" (data[3]) - : "a" (selector)); -} - static inline void do_cpuid2(uint32_t selector, uint32_t selector2, uint32_t *data) { asm volatile ("cpuid" @@ -74,7 +61,9 @@ "=b" (data[1]), "=c" (data[2]), "=d" (data[3]) - : "a" (selector), "c" (selector2)); + : "a" (selector), "c" (selector2), + "b" (0), + "d" (0)); } // DFE: enable_PIT2 and disable_PIT2 come from older xnu Index: branches/cparm/i386/libsaio/acpi_tools.c =================================================================== --- branches/cparm/i386/libsaio/acpi_tools.c (revision 0) +++ branches/cparm/i386/libsaio/acpi_tools.c (revision 1119) @@ -0,0 +1,277 @@ +/* + Copyright (c) 2010, Intel Corporation + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "datatype.h" +#include "intel_acpi.h" +#include "ppm.h" +#include "acpi_tools.h" + +static U32 GetRsdtPointer(void *mem_addr, U32 mem_size, ACPI_TABLES * acpi_tables); +static U32 GetXsdtPointer(ACPI_TABLES * acpi_tables); +static ACPI_TABLE_HEADER *GetTablePtr(ACPI_TABLE_RSDT * rsdt, U32 signature); +static ACPI_TABLE_HEADER *GetTablePtr64(ACPI_TABLE_XSDT * xsdt, U32 signature); + +//------------------------------------------------------------------------------- +// +// Procedure: FindAcpiTables - Collects addresses for RSDP, RSDT, FADT, & DSDT. +// +// Description: Finds the differentiated system description table pointer +// by scanning and checking ACPI tables. This function will +// get and store the following ACPI Table Pointers: +// 1) RSD Pointer in RsdPointer Variable +// 2) RSDT Pointer in RsdtPointer Variable (RSDP->RSDT) +// 3) FACP Pointer in FacpPointer Variable (RSDP->RSDT->FACP) +// 4) DSDT Pointer in DsdtPointer Variable (RSDP->RSDT->FACP->DSDT) +// 5) FACS Pointer in FacsPointer Variable (RSDP->RSDT->FACP->FACS) +// 6) FACP Pointer in Facp64Pointer Variable (RSDP->XSDT->FACP) +// +//------------------------------------------------------------------------------- +U32 FindAcpiTables(ACPI_TABLES * acpi_tables) +{ + U32 success = 0ul; + + // Perform init of ACPI table pointers + { + void *null = 0ul; + acpi_tables->DsdtPointer = null; + acpi_tables->DsdtPointer64 = null; + acpi_tables->FacpPointer = null; + acpi_tables->FacsPointer = null; + acpi_tables->FacsPointer64 = null; + acpi_tables->RsdPointer = null; + acpi_tables->RsdtPointer = null; + acpi_tables->MadtPointer = null; + acpi_tables->SsdtPointer = null; + acpi_tables->XsdtPointer = null; + acpi_tables->FacpPointer64 = null; + acpi_tables->RsdRevision = 0; + } + + // Find the RSDT pointer by scanning EBDA/E000/F000 segments. + + // Init memory address as EBDA and scan 1KB region + success = GetRsdtPointer((void *)(((U32) * (U16 *) 0x40E) << 4), 0x400, acpi_tables); + + // Init memory address as E000 segment and scan 64KB region + if (!success) + success = GetRsdtPointer((void *)0x0E0000, 0x10000, acpi_tables); + + // Init memory address as F000 segment and scan 64KB region + if (!success) + success = GetRsdtPointer((void *)0x0F0000, 0x10000, acpi_tables); + + if (!success) + return (0ul); + + GetXsdtPointer(acpi_tables); + + // Find FACP table pointer which is one of table pointers in the RDST + acpi_tables->FacpPointer = (ACPI_TABLE_FADT *) + GetTablePtr(acpi_tables->RsdtPointer, NAMESEG("FACP")); + if (acpi_tables->FacpPointer == 0ul) + return (0ul); + + // Find FACP(64) table pointer which is one of table pointers in the XDST + acpi_tables->FacpPointer64 = (ACPI_TABLE_FADT *) + GetTablePtr64(acpi_tables->XsdtPointer, NAMESEG("FACP")); + + // Find the DSDT which is included in the FACP table + acpi_tables->DsdtPointer = (ACPI_TABLE_DSDT *) acpi_tables->FacpPointer->Dsdt; + if ((*(U32 *) (acpi_tables->DsdtPointer->Header.Signature) != NAMESEG("DSDT")) || + (GetChecksum(acpi_tables->DsdtPointer, acpi_tables->DsdtPointer->Header.Length) != 0)) + return (0ul); + + // Find the XDSDT which is included in the FACP(64) table + ACPI_TABLE_DSDT *DsdtPointer64 = (ACPI_TABLE_DSDT *)((U32)acpi_tables->FacpPointer64->XDsdt); + if ((*(U32*) (DsdtPointer64->Header.Signature) == NAMESEG("DSDT")) && + (GetChecksum(DsdtPointer64, DsdtPointer64->Header.Length) == 0)) + acpi_tables->DsdtPointer64 = (ACPI_TABLE_DSDT *) DsdtPointer64; + + // Find the FACS which is included in the FACP table + acpi_tables->FacsPointer = (ACPI_TABLE_FACS *) acpi_tables->FacpPointer->Facs; + if (*(U32 *) (acpi_tables->FacsPointer->Signature) != NAMESEG("FACS")) + return (0ul); + + // Find the XFACS which is included in the FACP(64) table + ACPI_TABLE_FACS *FacsPointer64 = (ACPI_TABLE_FACS *)((U32)acpi_tables->FacpPointer64->XFacs); + if (*(U32*) (FacsPointer64->Signature) == NAMESEG("FACS")) + acpi_tables->FacsPointer64 = (ACPI_TABLE_FACS *) FacsPointer64; + + // Find the MADT table which is one of the table pointers in the RSDT + acpi_tables->MadtPointer = (ACPI_TABLE_MADT *) GetTablePtr(acpi_tables->RsdtPointer, NAMESEG("APIC")); + if (acpi_tables->MadtPointer == 0ul) + return (0ul); + + return (1ul); +} + +//----------------------------------------------------------------------------- +U32 get_num_tables(ACPI_TABLE_RSDT * rsdt) +{ + // Compute number of table pointers included in RSDT + return ((rsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) + / sizeof(ACPI_TABLE_HEADER *)); +} + +//----------------------------------------------------------------------------- +U32 get_num_tables64(ACPI_TABLE_XSDT * xsdt) +{ + { + void *null = 0ul; + if (xsdt == null) + return 0ul; + } + + // Compute number of table pointers included in XSDT + return ((xsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) + / sizeof(U64)); +} + +//------------------------------------------------------------------------------- +// +// Procedure: GetTablePtr - Find ACPI table with input signature. +// +//------------------------------------------------------------------------------- +static ACPI_TABLE_HEADER *GetTablePtr(ACPI_TABLE_RSDT * rsdt, U32 signature) +{ + U32 index; + U32 num_tables; + ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) rsdt->TableOffsetEntry; + + // Compute number of table pointers included in RSDT + num_tables = get_num_tables(rsdt); + + for (index = 0; index < num_tables; index++) { + if ((*(U32 *) (table_array[index]->Signature) == signature) && + (GetChecksum(table_array[index], table_array[index]->Length) == 0)) { + return (table_array[index]); + } + } + return (0); +} + +//------------------------------------------------------------------------------- +// +// Procedure: GetTablePtr - Find ACPI table with input signature. +// +//------------------------------------------------------------------------------- +static ACPI_TABLE_HEADER *GetTablePtr64(ACPI_TABLE_XSDT * xsdt, U32 signature) +{ + U32 index; + U32 num_tables; + ACPI_TABLE_HEADER *table = (ACPI_TABLE_HEADER *) xsdt->TableOffsetEntry; + + // Compute number of table pointers included in XSDT + num_tables = get_num_tables64(xsdt); + + for (index = 0; index < num_tables; index++) { + if (((U32) (table->Signature) == signature) && + (GetChecksum(table, table->Length) == 0)) { + return (table); + } + // Move array pointer to next 64-bit pointer + table = (ACPI_TABLE_HEADER *) ((U32) table + sizeof(U64)); + } + return (0); +} + +//------------------------------------------------------------------------------- +// +// Procedure: GetChecksum - Performs byte checksum +// +//------------------------------------------------------------------------------- +U8 GetChecksum(void *mem_addr, U32 mem_size) +{ + U8 *current = mem_addr; + U8 *end = current + mem_size; + U8 checksum = 0; + + for (; current < end; current++) + checksum = checksum + *current; + + return (checksum); +} + +/*========================================================================== + * Function to map 32 bit physical address to 64 bit virtual address + */ + + +//------------------------------------------------------------------------------- +// +// Procedure: GetRsdtPointer - Scans given segment for RSDT pointer +// +// Description: Scans for root system description table pointer signature +// ('RSD PTR ') , verifies checksum, and returns pointer to +// RSDT table if found. +// +//------------------------------------------------------------------------------- +static U32 GetRsdtPointer(void *mem_addr, U32 mem_size, ACPI_TABLES * acpi_tables) +{ + U8 *current = mem_addr; + U8 *end = current + mem_size; + + // Quick sanity check for a valid start address + if (current == 0ul) + return (0ul); + + for (; current < end; current += 16) { + if (*(volatile U64 *)current == NAMESEG64("RSD PTR ")) { + if (GetChecksum(current, ACPI_RSDP_REV0_SIZE) == 0) { + // RSD pointer structure checksum okay, lookup the RSDT pointer. + acpi_tables->RsdRevision = ((ACPI_TABLE_RSDP *)current)->Revision; + acpi_tables->RsdPointer = (ACPI_TABLE_RSDP *)current; + acpi_tables->RsdtPointer = (ACPI_TABLE_RSDT *) acpi_tables->RsdPointer->RsdtPhysicalAddress; + if ((acpi_tables->RsdPointer != 0) && (acpi_tables->RsdtPointer != 0)) + return (1ul); + else + return (0ul); + } + } + } + + return (0); +} + +//------------------------------------------------------------------------------- +// +// Procedure: GetXsdtPointer +// +//------------------------------------------------------------------------------- +static U32 GetXsdtPointer(ACPI_TABLES * acpi_tables) +{ + if ((GetChecksum(acpi_tables->RsdPointer, sizeof(ACPI_TABLE_RSDP)) == 0) && + (acpi_tables->RsdPointer->Revision == 2) && + (acpi_tables->RsdPointer->Length == sizeof(ACPI_TABLE_RSDP))) { + // RSD pointer structure checksum okay, lookup the XSDT pointer. + acpi_tables->XsdtPointer = (ACPI_TABLE_XSDT *) (U32) acpi_tables->RsdPointer->XsdtPhysicalAddress; + return (1ul); + } + + return (0ul); +} Property changes on: branches/cparm/i386/libsaio/acpi_tools.c ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/libsaio/acpi_tools.h =================================================================== --- branches/cparm/i386/libsaio/acpi_tools.h (revision 0) +++ branches/cparm/i386/libsaio/acpi_tools.h (revision 1119) @@ -0,0 +1,41 @@ +/* +Copyright (c) 2010, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef acpi_tools_h +#define acpi_tools_h + +#include "datatype.h" +#include "intel_acpi.h" +#include "ppm.h" + +U32 get_num_tables(ACPI_TABLE_RSDT * rsdt); +U32 get_num_tables64(ACPI_TABLE_XSDT * xsdt); +U32 FindAcpiTables(ACPI_TABLES * acpi_tables); +U8 GetChecksum(void *mem_addr, U32 mem_size); + +#endif // acpi_tools_h Property changes on: branches/cparm/i386/libsaio/acpi_tools.h ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/libsaio/ppm.h =================================================================== --- branches/cparm/i386/libsaio/ppm.h (revision 0) +++ branches/cparm/i386/libsaio/ppm.h (revision 1119) @@ -0,0 +1,282 @@ +/* +Copyright (c) 2010, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef ppm_h +#define ppm_h + +#include "datatype.h" + +#define PROFILE_ALL +//#define PROFILE_NEHALEM_EP_DP +//#define PROFILE_WESTMERE_EP_UP_DP +//#define PROFILE_NEHALEM_EX_MP +//#define PROFILE_WESTMERE_EX_MP +//#define PROFILE_SANDYBRIDGE_UP + +#if defined(PROFILE_ALL) || defined(PROFILE_WESTMERE_EX_MP) + +#define MAX_CPU_SOCKETS 8 // max count of cpu packages (any range of APIC IDs is ok) +#define MAX_LOGICAL_CPU 256 // max count of cpu found in MADT +#define MAX_CORES 32 // Based on full range of Core APID ID values (max of 5 bits for core APIC ID mask) + +#elif defined(PROFILE_NEHALEM_EX_MP) + +#define MAX_CPU_SOCKETS 8 // max count of cpu packages (any range of APIC IDs is ok) +#define MAX_LOGICAL_CPU 128 // max count of cpu found in MADT +#define MAX_CORES 16 // Based on full range of Core APID ID values (max of 4 bits for core APIC ID mask) + +#elif defined(PROFILE_WESTMERE_EP_UP_DP) + +#define MAX_CPU_SOCKETS 2 // max count of cpu packages (any range of APIC IDs is ok) +#define MAX_LOGICAL_CPU 64 // max count of cpu found in MADT +#define MAX_CORES 16 // Based on full range of Core APID ID values (max of 4 bits for core APIC ID mask) + +#elif defined(PROFILE_NEHALEM_EP_UP_DP) + +#define MAX_CPU_SOCKETS 2 // max count of cpu packages (any range of APIC IDs is ok) +#define MAX_LOGICAL_CPU 32 // max count of cpu found in MADT +#define MAX_CORES 8 // Based on full range of Core APID ID values (max of 3 bits for core APIC ID mask) + +#elif defined(PROFILE_SANDY_BRIDGE_UP) + +#define MAX_CPU_SOCKETS 1 // max count of cpu packages (any range of APIC IDs is ok) +#define MAX_LOGICAL_CPU 8 // max count of cpu found in MADT +#define MAX_CORES 4 + +#endif + +#define MAX_PSTATES 16 +#define MAX_CSTATES 4 +#define MAX_TSTATES 15 + +//Define ACPI_CSD to force building ACPI _CSD +//#define BUILD_ACPI_CSD + +#ifndef DWORD_REGS_TYPEDEF +#define DWORD_REGS_TYPEDEF +typedef struct dword_regs { + U32 _eax; + U32 _ebx; + U32 _ecx; + U32 _edx; +} DWORD_REGS; +#endif + +typedef struct acpi_tables { + // Define the Storage Locations for all the ACPI Table Pointers. + ACPI_TABLE_DSDT *DsdtPointer; // Differentiated System Description Table (RSDP->RSDT->FACP->DSDT) + ACPI_TABLE_DSDT *DsdtPointer64; // Differentiated System Description Table (RSDP->XSDT->FACP->XDSDT) + ACPI_TABLE_FADT *FacpPointer; // Fixed ACPI Description Table (RSDP->RSDT->FACP) + ACPI_TABLE_FACS *FacsPointer; // Firmware ACPI Control Structure (RSDP->RSDT->FACP->FACS) + ACPI_TABLE_FACS *FacsPointer64; // Firmware ACPI Control Structure (RSDP->XSDT->FACP->XFACS) + ACPI_TABLE_RSDP *RsdPointer; // Root System Description Pointer Structure (RSDP) + ACPI_TABLE_RSDT *RsdtPointer; // Root System Description Table (RSDP->RSDT) + ACPI_TABLE_MADT *MadtPointer; // Multiple APIC Description Table (RSDP->RSDT->APIC) + ACPI_TABLE_SSDT *SsdtPointer; // Secondary System Description Table (RSDP->RSDT->SSDT) + ACPI_TABLE_XSDT *XsdtPointer; // Extended Root System Description Table (RSDP->XSDT) + ACPI_TABLE_FADT *FacpPointer64; // Fixed ACPI Description Table (RSDP->XSDT->FACP) + U8 RsdRevision; // Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ +} ACPI_TABLES; + +typedef struct pstate { + U32 frequency; + U32 power; + U32 ratio; +} PSTATE; + +typedef struct pkg_pstates { + U32 num_pstates; + PSTATE pstate[MAX_PSTATES]; +} PKG_PSTATES; + +typedef struct tstate { + U32 freqpercent; + U32 power; + U32 latency; + U32 control; + U32 status; +} TSTATE; + +typedef struct pkg_tstates { + U32 num_tstates; + TSTATE tstate[MAX_TSTATES]; +} PKG_TSTATES; + +typedef enum cstate_encoding { + IO_REDIRECTION = 0, + NATIVE_MWAIT = 1, +} CSTATE_ENCODING; + +typedef enum cpu_cstate { + CPU_C1 = 1, + CPU_C3_ACPI_C2 = 3, + CPU_C3_ACPI_C3 = 4, + CPU_C6 = 6, + CPU_C7 = 7, +} CPU_CSTATE; + +typedef struct cstate { + U8 type; + U16 latency; + U32 power; +} CSTATE; + +typedef struct pkg_cstates { + U32 num_cstates; + CSTATE cstate[MAX_CSTATES]; + ACPI_GENERIC_ADDRESS gas[MAX_CSTATES]; +} PKG_CSTATES; + +typedef struct cpu_details { + U32 present; + U32 x2apic_id; + U32 socket_id; + U32 intra_package_mask_width; + U32 intra_package_mask; + U32 smt_mask_width; + U32 smt_select_mask; + U32 core_select_mask; + DWORD_REGS cpuid1; + DWORD_REGS cpuid5; + DWORD_REGS cpuid6; + DWORD_REGS cpuidB_0; + DWORD_REGS cpuidB_1; + U32 eist_cpuid_feature_flag; + U32 turbo_cpuid_feature_flag; + U32 turbo_misc_enables_feature_flag; + U32 invariant_apic_timer_flag; + U32 tdc_limit; + U32 tdp_limit; + U32 turbo_available; + U32 max_ratio_as_mfg; + U32 max_ratio_as_cfg; + U32 min_ratio; + U32 tdc_tdp_limits_for_turbo_flag; + U32 ratio_limits_for_turbo_flag; + U32 xe_available; + U32 logical_processor_count_from_madt; + U32 core_logical_processor_count_from_madt[MAX_CORES]; + + PKG_PSTATES pkg_pstates; + + PKG_CSTATES pkg_mwait_cstates; + PKG_CSTATES pkg_io_cstates; + + PKG_TSTATES pkg_tstates; + + U32 package_cstate_limit; + U32 core_c1_supported; + U32 core_c3_supported; + U32 core_c6_supported; + U32 core_c7_supported; + U32 mwait_supported; + U32 acpi_support_cpuid_feature_flag; + U32 energy_perf_bias_supported; + + U64 package_power_limit; + U64 package_power_sku_unit; +} CPU_DETAILS; + +typedef struct socket_info { + U32 signature; + U32 socket_count; + CPU_DETAILS cpu[MAX_CPU_SOCKETS]; +} SOCKET_INFO; + +typedef struct lapic_info { + U32 processorId; + U32 apicId; + U32 pkg_index; + U32 core_apic_id; + U32 core_index; + PROCESSOR_NUMBER_TO_NAMESEG *namepath; + U32 madt_type; + U32 uid; +} LAPIC_INFO; + +typedef struct proc_info { + U32 processorId; + U32 apicId; +} PROC_INFO; + +typedef struct madt_info { + U32 lapic_count; + LAPIC_INFO lapic[MAX_LOGICAL_CPU]; +} MADT_INFO; + +typedef struct rsdt_info { + U32 proc_count; + PROC_INFO processor[MAX_LOGICAL_CPU]; +} RSDT_INFO; + +typedef struct smp_exit_state { + U32 signature; + + // Number of Failure or Informative codes included in the buffer + U32 error_code_count; + + // Buffer of Failure or Informative codes + U32 error_codes[10]; +} SMP_EXIT_STATE; + +typedef enum smp_exit_code { + // Generic successful + SMP_EXIT_CODE_OK = 1, + + // Generic failure + EXIT_CODE_FAILED = 2, + + // First logical processor for this socket unable to find available structure + EXIT_CODE_FAILED_SOCKET_PROXY_SAVE = 3, +} SMP_EXIT_CODE; + +typedef struct ppm_host { + U32 signature; + + U32 pstates_enabled; + U32 pstate_coordination; + U32 turbo_enabled; + U32 cstates_enabled; + U32 tstates_enabled; + U32 performance_per_watt; + + ACPI_TABLES acpi_tables; + + + RSDT_INFO rsdt_info; + MADT_INFO madt_info; + SOCKET_INFO skt_info; + + PPM_SETUP_OPTIONS *options; + + SMP_EXIT_STATE smp_exit_state; + + U32 detected_cpu_family; +} PPM_HOST; + +#endif // ppm_h Property changes on: branches/cparm/i386/libsaio/ppm.h ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/libsaio/pci.c =================================================================== --- branches/cparm/i386/libsaio/pci.c (revision 1118) +++ branches/cparm/i386/libsaio/pci.c (revision 1119) @@ -107,6 +107,8 @@ scan_pci_bus(new, secondary_bus); } break; + default: + break; } *current = new; current = &new->next; Index: branches/cparm/i386/libsaio/intel_acpi.h =================================================================== --- branches/cparm/i386/libsaio/intel_acpi.h (revision 0) +++ branches/cparm/i386/libsaio/intel_acpi.h (revision 1119) @@ -0,0 +1,692 @@ +/* Per ACPI 3.0a spec */ + +/* + Copyright (c) 2010, Intel Corporation + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __LIBSAIO_INTEL_ACPI_H +#define __LIBSAIO_INTEL_ACPI_H + +#include "datatype.h" +#include "ppmsetup.h" +// +// All tables and structures must be byte-packed to match the ACPI specification +#pragma pack(1) + +#define ACPI_SIG_DSDT "DSDT" // Differentiated System Description Table +#define ACPI_SIG_FADT "FACP" // Fixed ACPI Description Table +#define ACPI_SIG_FACS "FACS" // Firmware ACPI Control Structure +#define ACPI_SIG_PSDT "PSDT" // Persistent System Description Table +#define ACPI_SIG_RSDP "RSD PTR " // Root System Description Pointer +#define ACPI_SIG_RSDT "RSDT" // Root System Description Table +#define ACPI_SIG_XSDT "XSDT" // Extended System Description Table +#define ACPI_SIG_SSDT "SSDT" // Secondary System Description Table +#define ACPI_RSDP_NAME "RSDP" // Short name for RSDP, not signature +#define ACPI_SIG_MADT "APIC" // Multiple APIC Description Table +#define ACPI_SIG_SBST "SBST" // Smart Battery Specification Table +#define ACPI_SIG_ECDT "ECDT" // Embedded Controller Boot Resources Table +#define ACPI_SIG_ASF "ASF!" // Alert Standard Format table +#define ACPI_SIG_DMAR "DMAR" // DMA Remapping table +#define ACPI_SIG_HPET "HPET" // High Precision Event Timer table +#define ACPI_SIG_MCFG "MCFG" // PCI Memory Mapped Configuration table +#define ACPI_SIG_UEFI "UEFI" // Uefi Boot Optimization Table + + +#ifndef nameseg_defined +#define nameseg_defined +#define NAMESEG(s) (((U32)(s[0]) << 0) \ +|((U32)(s[1]) << 8) \ +|((U32)(s[2]) << 16) \ +|((U32)(s[3]) << 24)) +#endif + +#define NAMESEG64(s) (((U64)(s[0]) << 0) \ +|((U64)(s[1]) << 8) \ +|((U64)(s[2]) << 16) \ +|((U64)(s[3]) << 24) \ +|((U64)(s[4]) << 32) \ +|((U64)(s[5]) << 40) \ +|((U64)(s[6]) << 48) \ +|((U64)(s[7]) << 56)) \ + + +// Data Objects Encoding values. +#define AML_EXT_OP_PREFIX 0x5B + +// Name Space Modifier Objects Encoding values. +#define AML_NAME_OP 0x08 // Name operator. +#define AML_SCOPE_OP 0x10 // Scope operator. + +// Named Objects Encoding values. +#define AML_MUTEX_OP 0x01 +#define AML_METHOD_OP 0x14 // Method operator. +#define AML_OPREGION_OP 0x80 // Operation Region operator. +#define AML_FIELD_OP 0x81 +#define AML_DEVICE_OP 0x82 +#define AML_PROCESSOR_OP 0x83 // Processor operator. + +// Type2 Opcodes Encoding values. +#define AML_NULL_NAME 0x00 +#define AML_ZERO_OP 0x00 +#define AML_ALIAS_OP 0x06 +#define AML_ONE_OP 0x01 +#define AML_BYTE_OP 0x0a +#define AML_WORD_OP 0x0b +#define AML_DWORD_OP 0x0c +#define AML_STRING_OP 0x0d +#define AML_QWORD_OP 0x0e +#define AML_BUFFER_OP 0x11 +#define AML_PACKAGE_OP 0x12 +#define AML_COND_REF_OF_OP 0x12 // Requires AML_EXT_OP_PREFIX +#define AML_CREATE_FIELD_OP 0x13 // Requires AML_EXT_OP_PREFIX +#define AML_DUAL_NAME_PREFIX 0x2e +#define AML_MULTI_NAME_PREFIX 0x2f +#define AML_REVISION_OP 0x30 // Requires AML_EXT_OP_PREFIX +#define AML_DEBUG_OP 0x31 +#define AML_ROOT_PREFIX 0x5c +#define AML_PARENT_PREFIX 0x5e +#define AML_LOCAL0_OP 0x60 +#define AML_LOCAL1_OP 0x61 +#define AML_LOCAL2_OP 0x62 +#define AML_LOCAL3_OP 0x63 +#define AML_LOCAL4_OP 0x64 +#define AML_LOCAL5_OP 0x65 +#define AML_LOCAL6_OP 0x66 +#define AML_LOCAL7_OP 0x67 +#define AML_ARG0_OP 0x68 +#define AML_ARG1_OP 0x69 +#define AML_ARG2_OP 0x6A +#define AML_ARG3_OP 0x6B +#define AML_ARG4_OP 0x6C +#define AML_ARG5_OP 0x6D +#define AML_ARG6_OP 0x6E +#define AML_STORE_OP 0x70 +#define AML_CONCAT_OP 0x73 +#define AML_SUBTRACT_OP 0x74 +#define AML_MULTIPLY_OP 0x77 +#define AML_AND_OP 0x7B +#define AML_END_TAG_OP 0x79 +#define AML_GEN_REG_FIELD 0x82 +#define AML_PROCESSOR_OP 0x83 +#define AML_INDEXFIELD_OP 0x86 // Requires AML_EXT_OP_PREFIX +#define AML_SIZEOF_OP 0x87 +#define AML_INDEX_OP 0x88 +#define AML_CREATE_DWORD_FIELD_OP 0x8A +#define AML_LAND_OP 0x90 +#define AML_LOR_OP 0x91 +#define AML_LNOT_OP 0x92 +#define AML_LEQUAL_OP 0x93 +#define AML_LGREATER_OP 0x94 +#define AML_LLESS_OP 0x95 +#define AML_IF_OP 0xA0 +#define AML_ELSE_OP 0xA1 +#define AML_RETURN_OP 0xA4 +#define AML_ONES_OP 0xFF + +#define GAS_TYPE_FFH 0x7f +#define GAS_TYPE_SYSTEM_IO 0x01 +#define GAS_VENDOR_INTEL 0x01 +#define GAS_CLASS_CODE_NATIVE 0x02 + +// Define the Generic System Description Table Structure. +// This common header is used by all tables except the RSDP and FACS. +// The define is used for direct inclusion of header into other ACPI tables +typedef struct acpi_table_header { + U8 Signature[4]; // ASCII table signature + U32 Length; // Length of table in bytes, including this header + U8 Revision; // ACPI Specification minor version # + U8 Checksum; // To make checksum of entire table == 0 + U8 OemId[6]; // ASCII OEM identification + U8 OemTableId[8]; // ASCII OEM table identification + U32 OemRevision; // OEM revision number + U8 AslCompilerId[4]; // ASCII ASL compiler vendor ID + U32 AslCompilerRevision; // ASL compiler version +} ACPI_TABLE_HEADER; + +// GAS - Generic Address Structure (ACPI 2.0+) +typedef struct acpi_generic_address { + U8 SpaceId; // Address space where struct or register exists + U8 BitWidth; // Size in bits of given register + U8 BitOffset; // Bit offset within the register + U8 AccessWidth; // Minimum Access size (ACPI 3.0) + U64 Address; // 64-bit address of struct or register +} ACPI_GENERIC_ADDRESS; + +// RSDP - Root System Description Pointer (Signature is "RSD PTR ") +typedef struct acpi_table_rsdp { + U8 Signature[8]; // ACPI signature, contains "RSD PTR " + U8 Checksum; // ACPI 1.0 checksum + U8 OemId[6]; // OEM identification + U8 Revision; // Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ + U32 RsdtPhysicalAddress; // 32-bit physical address of the RSDT + U32 Length; // Table length in bytes, including header (ACPI 2.0+) + U64 XsdtPhysicalAddress; // 64-bit physical address of the XSDT (ACPI 2.0+) + U8 ExtendedChecksum; // Checksum of entire table (ACPI 2.0+) + U8 Reserved[3]; // Reserved, must be zero +} ACPI_TABLE_RSDP; + +#define ACPI_RSDP_REV0_SIZE 20 // Size of original ACPI 1.0 RSDP + +// RSDT - Root System Description Table +typedef struct acpi_table_rsdt { + ACPI_TABLE_HEADER Header; // Common ACPI table header + U32 TableOffsetEntry[1]; // Array of pointers to ACPI tables +} ACPI_TABLE_RSDT; + + +// XSDT - Root System Description Table +typedef struct acpi_table_xsdt { + ACPI_TABLE_HEADER Header; // Common ACPI table header + U64 TableOffsetEntry[1]; // Array of pointers to ACPI tables +} ACPI_TABLE_XSDT; + +// DSDT - Differentiated System Description Table +typedef struct acpi_table_dsdt { + ACPI_TABLE_HEADER Header; // Common ACPI table header + U32 EntryStart; +} ACPI_TABLE_DSDT; + +// FACS - Firmware ACPI Control Structure (FACS) +typedef struct acpi_table_facs { + U8 Signature[4]; // ASCII table signature + U32 Length; // Length of structure, in bytes + U32 HardwareSignature; // Hardware configuration signature + U32 FirmwareWakingVector; // 32-bit physical address of the Firmware Waking Vector + U32 GlobalLock; // Global Lock for shared hardware resources + U32 Flags; + U64 XFirmwareWakingVector; // 64-bit version of the Firmware Waking Vector (ACPI 2.0+) + U8 Version; // Version of this table (ACPI 2.0+) + U8 Reserved[31]; // Reserved, must be zero +} ACPI_TABLE_FACS; + +// SBST - Smart Battery Specification Table - Version 1 +typedef struct acpi_table_sbst +{ + ACPI_TABLE_HEADER Header; /* Common ACPI table header */ + U32 WarningLevel; + U32 LowLevel; + U32 CriticalLevel; + +} ACPI_TABLE_SBST; + +// ASF - Alert Standard Format table (Signature "ASF!") +typedef struct acpi_table_asf +{ + ACPI_TABLE_HEADER Header; /* Common ACPI table header */ + +} ACPI_TABLE_ASF; + +// DMAR - DMA Remapping table - Version 1 +typedef struct acpi_table_dmar +{ + ACPI_TABLE_HEADER Header; /* Common ACPI table header */ + U8 Width; /* Host Address Width */ + U8 Flags; + U8 Reserved[10]; + +} ACPI_TABLE_DMAR; + +// HPET - High Precision Event Timer table - Version 1 +typedef struct acpi_table_hpet +{ + ACPI_TABLE_HEADER Header; /* Common ACPI table header */ + U32 Id; /* Hardware ID of event timer block */ + ACPI_GENERIC_ADDRESS Address; /* Address of event timer block */ + U8 Sequence; /* HPET sequence number */ + U16 MinimumTick; /* Main counter min tick, periodic mode */ + U8 Flags; + +} ACPI_TABLE_HPET; + +//MCFG - PCI Memory Mapped Configuration table and sub-table - Version 1 +typedef struct acpi_table_mcfg +{ + ACPI_TABLE_HEADER Header; /* Common ACPI table header */ + U8 Reserved[8]; + +} ACPI_TABLE_MCFG; + +//UEFI - UEFI Boot optimization Table - Version 1 +typedef struct acpi_table_uefi +{ + ACPI_TABLE_HEADER Header; /* Common ACPI table header */ + U8 Identifier[16]; /* UUID identifier */ + U16 DataOffset; /* Offset of remaining data in table */ + +} ACPI_TABLE_UEFI; + +// ECDT - Embedded Controller Boot Resources Table - Version 1 +typedef struct acpi_table_ecdt +{ + ACPI_TABLE_HEADER Header; /* Common ACPI table header */ + ACPI_GENERIC_ADDRESS Control; /* Address of EC command/status register */ + ACPI_GENERIC_ADDRESS Data; /* Address of EC data register */ + U32 Uid; /* Unique ID - must be same as the EC _UID method */ + U8 Gpe; /* The GPE for the EC */ + U8 Id[1]; /* Full namepath of the EC in the ACPI namespace */ + +} ACPI_TABLE_ECDT; + +// FADT - Fixed ACPI Description Table (Signature "FACP") +typedef struct acpi_table_fadt { + ACPI_TABLE_HEADER Header; // Common ACPI table header + U32 Facs; // 32-bit physical address of FACS + U32 Dsdt; // 32-bit physical address of DSDT + U8 Model; // System Interrupt Model (ACPI 1.0) - not used in ACPI 2.0+ + U8 PreferredProfile; // Conveys preferred power management profile to OSPM. + U16 SciInterrupt; // System vector of SCI interrupt + U32 SmiCommand; // 32-bit Port address of SMI command port + U8 AcpiEnable; // Value to write to smi_cmd to enable ACPI + U8 AcpiDisable; // Value to write to smi_cmd to disable ACPI + U8 S4BiosRequest; // Value to write to SMI CMD to enter S4BIOS state + U8 PstateControl; // Processor performance state control + U32 Pm1aEventBlock; // 32-bit Port address of Power Mgt 1a Event Reg Blk + U32 Pm1bEventBlock; // 32-bit Port address of Power Mgt 1b Event Reg Blk + U32 Pm1aControlBlock; // 32-bit Port address of Power Mgt 1a Control Reg Blk + U32 Pm1bControlBlock; // 32-bit Port address of Power Mgt 1b Control Reg Blk + U32 Pm2ControlBlock; // 32-bit Port address of Power Mgt 2 Control Reg Blk + U32 PmTimerBlock; // 32-bit Port address of Power Mgt Timer Ctrl Reg Blk + U32 Gpe0Block; // 32-bit Port address of General Purpose Event 0 Reg Blk + U32 Gpe1Block; // 32-bit Port address of General Purpose Event 1 Reg Blk + U8 Pm1EventLength; // Byte Length of ports at Pm1xEventBlock + U8 Pm1ControlLength; // Byte Length of ports at Pm1xControlBlock + U8 Pm2ControlLength; // Byte Length of ports at Pm2ControlBlock + U8 PmTimerLength; // Byte Length of ports at PmTimerBlock + U8 Gpe0BlockLength; // Byte Length of ports at Gpe0Block + U8 Gpe1BlockLength; // Byte Length of ports at Gpe1Block + U8 Gpe1Base; // Offset in GPE number space where GPE1 events start + U8 CstControl; // Support for the _CST object and C States change notification + U16 C2Latency; // Worst case HW latency to enter/exit C2 state + U16 C3Latency; // Worst case HW latency to enter/exit C3 state + U16 FlushSize; // Processor's memory cache line width, in bytes + U16 FlushStride; // Number of flush strides that need to be read + U8 DutyOffset; // Processor duty cycle index in processor's P_CNT reg + U8 DutyWidth; // Processor duty cycle value bit width in P_CNT register. + U8 DayAlarm; // Index to day-of-month alarm in RTC CMOS RAM + U8 MonthAlarm; // Index to month-of-year alarm in RTC CMOS RAM + U8 Century; // Index to century in RTC CMOS RAM + U16 BootFlags; // IA-PC Boot Architecture Flags. See Table 5-10 for description + U8 Reserved; // Reserved, must be zero + U32 Flags; // Miscellaneous flag bits (see below for individual flags) + ACPI_GENERIC_ADDRESS ResetRegister; // 64-bit address of the Reset register + U8 ResetValue; // Value to write to the ResetRegister port to reset the system + U8 Reserved4[3]; // Reserved, must be zero + U64 XFacs; // 64-bit physical address of FACS + U64 XDsdt; // 64-bit physical address of DSDT + ACPI_GENERIC_ADDRESS XPm1aEventBlock; // 64-bit Extended Power Mgt 1a Event Reg Blk address + ACPI_GENERIC_ADDRESS XPm1bEventBlock; // 64-bit Extended Power Mgt 1b Event Reg Blk address + ACPI_GENERIC_ADDRESS XPm1aControlBlock; // 64-bit Extended Power Mgt 1a Control Reg Blk address + ACPI_GENERIC_ADDRESS XPm1bControlBlock; // 64-bit Extended Power Mgt 1b Control Reg Blk address + ACPI_GENERIC_ADDRESS XPm2ControlBlock; // 64-bit Extended Power Mgt 2 Control Reg Blk address + ACPI_GENERIC_ADDRESS XPmTimerBlock; // 64-bit Extended Power Mgt Timer Ctrl Reg Blk address + ACPI_GENERIC_ADDRESS XGpe0Block; // 64-bit Extended General Purpose Event 0 Reg Blk address + ACPI_GENERIC_ADDRESS XGpe1Block; // 64-bit Extended General Purpose Event 1 Reg Blk address +} ACPI_TABLE_FADT; + +// SSDT - Secondary System Description Table +typedef struct acpi_table_ssdt { + ACPI_TABLE_HEADER Header; // Common ACPI table header +} ACPI_TABLE_SSDT; + +//MADT - Multiple APIC Description Table +typedef struct acpi_table_madt { + ACPI_TABLE_HEADER Header; // Common ACPI table header + U32 Address; // Physical address of local APIC + U32 Flags; +} ACPI_TABLE_MADT; + + +// Values for subtable type in ACPI_SUBTABLE_HEADER +enum AcpiMadtType { + ACPI_MADT_TYPE_LOCAL_APIC = 0, + ACPI_MADT_TYPE_IO_APIC = 1, + ACPI_MADT_TYPE_INTERRUPT_OVERRIDE = 2, + ACPI_MADT_TYPE_NMI_SOURCE = 3, + ACPI_MADT_TYPE_LOCAL_APIC_NMI = 4, + ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE = 5, + ACPI_MADT_TYPE_IO_SAPIC = 6, + ACPI_MADT_TYPE_LOCAL_SAPIC = 7, + ACPI_MADT_TYPE_INTERRUPT_SOURCE = 8, + ACPI_MADT_TYPE_X2APIC = 9, + ACPI_MADT_TYPE_RESERVED = 10 // 10 and greater are reserved +}; + +// Common Sub-table header (used in MADT, SRAT, etc.) +typedef struct acpi_subtable_header { + U8 Type; + U8 Length; +} ACPI_SUBTABLE_HEADER; + +// MADT Sub-tables, correspond to Type in ACPI_SUBTABLE_HEADER + +// 0: Processor Local APIC +typedef struct acpi_madt_local_apic { + ACPI_SUBTABLE_HEADER Header; + U8 ProcessorId; // ACPI processor id + U8 Id; // Processor's local APIC id + U32 LapicFlags; +} ACPI_MADT_LOCAL_APIC; + +// 1: IO APIC +typedef struct acpi_madt_io_apic { + ACPI_SUBTABLE_HEADER Header; + U8 Id; // I/O APIC ID + U8 Reserved; // Reserved - must be zero + U32 Address; // APIC physical address + U32 GlobalIrqBase; // Global system interrupt where INTI lines start +} ACPI_MADT_IO_APIC; + +// 2: Interrupt Override +typedef struct acpi_madt_interrupt_override { + ACPI_SUBTABLE_HEADER Header; + U8 Bus; // 0 - ISA + U8 SourceIrq; // Interrupt source (IRQ) + U32 GlobalIrq; // Global system interrupt + U16 IntiFlags; +} ACPI_MADT_INTERRUPT_OVERRIDE; + +// 3: NMI Source +typedef struct acpi_madt_nmi_source { + ACPI_SUBTABLE_HEADER Header; + U16 IntiFlags; + U32 GlobalIrq; // Global system interrupt +} ACPI_MADT_NMI_SOURCE; + +// 4: Local APIC NMI +typedef struct acpi_madt_local_apic_nmi { + ACPI_SUBTABLE_HEADER Header; + U8 ProcessorId; // ACPI processor id + U16 IntiFlags; + U8 Lint; // LINTn to which NMI is connected +} ACPI_MADT_LOCAL_APIC_NMI; + +// 5: Address Override +typedef struct acpi_madt_local_apic_override { + ACPI_SUBTABLE_HEADER Header; + U16 Reserved; // Reserved, must be zero + U64 Address; // APIC physical address +} ACPI_MADT_LOCAL_APIC_OVERRIDE; + +// 6: I/O Sapic +typedef struct acpi_madt_io_sapic { + ACPI_SUBTABLE_HEADER Header; + U8 Id; // I/O SAPIC ID + U8 Reserved; // Reserved, must be zero + U32 GlobalIrqBase; // Global interrupt for SAPIC start + U64 Address; // SAPIC physical address +} ACPI_MADT_IO_SAPIC; + +// 7: Local Sapic +typedef struct acpi_madt_local_sapic { + ACPI_SUBTABLE_HEADER Header; + U8 ProcessorId; // ACPI processor id + U8 Id; // SAPIC ID + U8 Eid; // SAPIC EID + U8 Reserved[3]; // Reserved, must be zero + U32 LapicFlags; + U32 Uid; // Numeric UID - ACPI 3.0 + char UidString[1]; // String UID - ACPI 3.0 +} ACPI_MADT_LOCAL_SAPIC; + +// 8: Platform Interrupt Source +typedef struct acpi_madt_interrupt_source { + ACPI_SUBTABLE_HEADER Header; + U16 IntiFlags; + U8 Type; // 1=PMI, 2=INIT, 3=corrected + U8 Id; // Processor ID + U8 Eid; // Processor EID + U8 IoSapicVector; // Vector value for PMI interrupts + U32 GlobalIrq; // Global system interrupt + U32 Flags; // Interrupt Source Flags +} ACPI_MADT_INTERRUPT_SOURCE; + +// 9: Processor X2APIC +typedef struct acpi_madt_x2apic { + ACPI_SUBTABLE_HEADER Header; + U16 Reserved; // Must be zero + U32 x2apicId; // Processor's X2APIC ID + U32 x2apicFlags; + U32 UID; +} ACPI_MADT_X2APIC; + +// Common flags fields for MADT subtables + +// MADT Local APIC flags (LapicFlags) +#define ACPI_MADT_ENABLED (1) // 00: Processor is usable if set + +// MADT MPS INTI flags (IntiFlags) +#define ACPI_MADT_POLARITY_MASK (3) // 00-01: Polarity of APIC I/O input signals +#define ACPI_MADT_TRIGGER_MASK (3<<2) // 02-03: Trigger mode of APIC input signals + +// Values for MPS INTI flags +#define ACPI_MADT_POLARITY_CONFORMS 0 +#define ACPI_MADT_POLARITY_ACTIVE_HIGH 1 +#define ACPI_MADT_POLARITY_RESERVED 2 +#define ACPI_MADT_POLARITY_ACTIVE_LOW 3 + +#define ACPI_MADT_TRIGGER_CONFORMS (0) +#define ACPI_MADT_TRIGGER_EDGE (1<<2) +#define ACPI_MADT_TRIGGER_RESERVED (2<<2) +#define ACPI_MADT_TRIGGER_LEVEL (3<<2) + +#define ACPI_COORD_TYPE_SW_ALL 0xFC +#define ACPI_COORD_TYPE_SW_ANY 0xFD +#define ACPI_COORD_TYPE_HW_ALL 0xFE + +typedef struct packageLength { + U8 packageLength0; + U8 packageLength1; +} ACPI_PACKAGE_LENGTH; + +typedef struct acpi_scope { + U8 scopeOpcode; + ACPI_PACKAGE_LENGTH pkgLength; + U8 rootChar; +} ACPI_SCOPE; + +typedef struct dual_name_path { + U8 prefix; + U32 nameseg[2]; +} DUAL_NAME_PATH; + +typedef struct multi_name_path { + U8 prefix; + U8 segCount; + U32 nameseg[MAX_SUPPORTED_CPU_NAMESEGS]; +} MULTI_NAME_PATH; + +typedef struct generic_register { + U8 genericRegisterField; + ACPI_PACKAGE_LENGTH pkgLength; + ACPI_GENERIC_ADDRESS gas; +} ACPI_GENERIC_REGISTER; + +typedef struct package { + U8 packageOpcode; + ACPI_PACKAGE_LENGTH pkgLength; + U8 numElements; +} ACPI_PACKAGE; + +typedef struct small_package { + U8 packageOpcode; + U8 packageLength; + U8 numElements; +} ACPI_SMALL_PACKAGE; + +typedef struct small_buffer { + U8 bufferOpcode; + U8 packageLength; +} ACPI_SMALL_BUFFER; + +typedef struct end_tag { + U8 endTagField; + U8 checksum; +} ACPI_END_TAG; + +typedef struct return_name_seg { + U8 returnOpcode; + U32 name; +} ACPI_RETURN_NAME_SEG; + +typedef struct return_package { + U8 returnOpcode; + ACPI_PACKAGE package; +} ACPI_RETURN_PACKAGE; + +typedef struct return_zero { + U8 returnOpcode; + U8 zeroOpcode; +} ACPI_RETURN_ZERO; + +typedef struct return_opcode { + U8 returnOpcode; + U8 opcodeToReturn; +} ACPI_RETURN_OPCODE; + +typedef struct byteConst { + U8 byteOpcode; + U8 byteData; +} ACPI_BYTE_CONST; + +typedef struct wordConst { + U8 wordOpcode; + U16 wordData; +} ACPI_WORD_CONST; + +typedef struct dwordConst { + U8 dwordOpcode; + U32 dwordData; +} ACPI_DWORD_CONST; + +typedef struct small_method { + U8 methodOpcode; + U8 packageLength; + U32 name; + U8 methodFlags; +} ACPI_SMALL_METHOD; + +typedef struct method { + U8 methodOpcode; + ACPI_PACKAGE_LENGTH pkgLength; + U32 name; + U8 methodFlags; +} ACPI_METHOD; + +typedef struct namePath { + U8 nameOpcode; + U32 name; +} ACPI_NAME_PATH; + +typedef struct named_dword { + ACPI_NAME_PATH namePath; + ACPI_DWORD_CONST dword; +} ACPI_NAMED_DWORD; + +typedef struct rootNamePath { + U8 nameOpcode; + U8 rootPrefix; + U32 name; +} ACPI_ROOT_NAME_PATH; + +typedef struct root_named_dword { + ACPI_ROOT_NAME_PATH rootNamePath; + ACPI_DWORD_CONST dword; +} ACPI_ROOT_NAMED_DWORD; + +typedef struct named_object { + ACPI_NAME_PATH namePath; + ACPI_PACKAGE package; +} ACPI_NAMED_OBJECT; + +typedef struct small_named_object { + ACPI_NAME_PATH namePath; + ACPI_SMALL_PACKAGE package; +} ACPI_SMALL_NAMED_OBJECT; + +typedef struct create_dword_field { + ACPI_NAME_PATH namePath; + ACPI_SMALL_PACKAGE package; +} ACPI_CREATE_DWORD_FIELD; + +typedef struct tstate_package { + ACPI_SMALL_PACKAGE package; + ACPI_DWORD_CONST FreqPercent; + ACPI_DWORD_CONST Power; + ACPI_DWORD_CONST TransLatency; + ACPI_DWORD_CONST Control; + ACPI_DWORD_CONST Status; +} ACPI_TSTATE_PACKAGE; + +typedef struct pstate_package { + ACPI_SMALL_PACKAGE package; + ACPI_DWORD_CONST CoreFreq; + ACPI_DWORD_CONST Power; + ACPI_DWORD_CONST TransLatency; + ACPI_DWORD_CONST BMLatency; + ACPI_DWORD_CONST Control; + ACPI_DWORD_CONST Status; +} ACPI_PSTATE_PACKAGE; + +typedef struct psd_package { + ACPI_SMALL_PACKAGE package; + ACPI_BYTE_CONST NumberOfEntries; + ACPI_BYTE_CONST Revision; + ACPI_DWORD_CONST Domain; + ACPI_DWORD_CONST CoordType; + ACPI_DWORD_CONST NumProcessors; +} ACPI_PSD_PACKAGE; + +typedef struct csd_package { + ACPI_SMALL_PACKAGE package; + ACPI_BYTE_CONST NumberOfEntries; + ACPI_BYTE_CONST Revision; + ACPI_DWORD_CONST Domain; + ACPI_DWORD_CONST CoordType; + ACPI_DWORD_CONST NumProcessors; + ACPI_DWORD_CONST Index; +} ACPI_CSD_PACKAGE; + +typedef struct tsd_package { + ACPI_SMALL_PACKAGE package; + ACPI_BYTE_CONST NumberOfEntries; + ACPI_BYTE_CONST Revision; + ACPI_DWORD_CONST Domain; + ACPI_DWORD_CONST CoordType; + ACPI_DWORD_CONST NumProcessors; +} ACPI_TSD_PACKAGE; + +typedef struct processor { + U8 processorOpCode; + U8 packageLength; + U8 numElements; + ACPI_BYTE_CONST ProcID; + ACPI_DWORD_CONST PblkAddr; + ACPI_BYTE_CONST PblkLen; +} ACPI_PROCESSOR; + +#pragma pack() + +#endif /* !__LIBSAIO_INTEL_ACPI_H */ Property changes on: branches/cparm/i386/libsaio/intel_acpi.h ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/libsaio/stringTable.c =================================================================== --- branches/cparm/i386/libsaio/stringTable.c (revision 1118) +++ branches/cparm/i386/libsaio/stringTable.c (revision 1119) @@ -581,22 +581,17 @@ int loadConfigFile (const char *configFile, config_file_t *config) { int fd, count; - - /*if ((fd = open_bvdev("bt(0,0)", configFile, 0)) < 0) { + + if ((fd = open(configFile)) < 0) { return -1; - }*/ - - if ((fd = open(configFile, 0)) < 0) { - return -1; } // read file count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); close(fd); - // build xml dictionary - ParseXMLFile(config->plist, &config->dictionary); - return 0; + // build xml dictionary + return ParseXMLFile(config->plist, &config->dictionary); } @@ -612,12 +607,11 @@ "bt(0,0)/Extra/com.apple.Boot.plist", "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist", }; + int i,fd, count, ret=-1; - int i, fd, count, ret=-1; - - for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) + for(i = 0; (unsigned)i< sizeof(dirspec)/sizeof(dirspec[0]); i++) { - if ((fd = open(dirspec[i], 0)) >= 0) + if ((fd = open(dirspec[i])) >= 0) { // read file count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); @@ -657,11 +651,11 @@ "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist", }; - int i, fd, count, ret=-1; + int i,fd, count, ret=-1; - for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) + for(i = 0; (unsigned)i< sizeof(dirspec)/sizeof(dirspec[0]); i++) { - if ((fd = open(dirspec[i], 0)) >= 0) + if ((fd = open(dirspec[i])) >= 0) { // read file count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); @@ -704,10 +698,10 @@ // This is a simple rock - paper scissors algo. R beats S, P beats R, S beats P // If all three, S is used for now. This should be change dto something else (say, timestamp?) - pfd = open(dirspec[0], 0); + pfd = open(dirspec[0]); if(pfd >= 0) // com.apple.boot.P exists { - sfd = open(dirspec[2], 0); // com.apple.boot.S takes precidence if it also exists + sfd = open(dirspec[2]); // com.apple.boot.S takes precidence if it also exists if(sfd >= 0) { // Use sfd @@ -736,10 +730,10 @@ } else { - rfd = open(dirspec[1], 0); // com.apple.boot.R exists + rfd = open(dirspec[1]); // com.apple.boot.R exists if(rfd >= 0) { - pfd = open(dirspec[2], 0); // com.apple.boot.P takes recidence if it exists + pfd = open(dirspec[2]); // com.apple.boot.P takes recidence if it exists if(pfd >= 0) { // use sfd @@ -769,7 +763,7 @@ } else { - sfd = open(dirspec[2], 0); // com.apple.boot.S exists, but nothing else does + sfd = open(dirspec[2]); // com.apple.boot.S exists, but nothing else does if(sfd >= 0) { // use sfd Index: branches/cparm/i386/libsaio/pci.h =================================================================== --- branches/cparm/i386/libsaio/pci.h (revision 1118) +++ branches/cparm/i386/libsaio/pci.h (revision 1119) @@ -43,6 +43,12 @@ struct pci_dt_t *next; } pci_dt_t; +struct pciList +{ + pci_dt_t* pciDev; + struct pciList* next; +}; + #define PCIADDR(bus, dev, func) (1 << 31) | (bus << 16) | (dev << 11) | (func << 8) #define PCI_ADDR_REG 0xcf8 #define PCI_DATA_REG 0xcfc @@ -772,6 +778,7 @@ #define PCI_CLASS_STORAGE_RAID 0x0104 #define PCI_CLASS_STORAGE_ATA 0x0105 #define PCI_CLASS_STORAGE_SATA 0x0106 +#define PCI_CLASS_STORAGE_SATA_AHCI 0x010601 #define PCI_CLASS_STORAGE_SAS 0x0107 #define PCI_CLASS_STORAGE_OTHER 0x0180 @@ -805,7 +812,7 @@ #define PCI_CLASS_BRIDGE_HOST 0x0600 #define PCI_CLASS_BRIDGE_ISA 0x0601 #define PCI_CLASS_BRIDGE_EISA 0x0602 -#define PCI_CLASS_BRIDGE_MC 0x0603 +#define PCI_CLASS_BRIDGE_MC 0x0603 #define PCI_CLASS_BRIDGE_PCI 0x0604 #define PCI_CLASS_BRIDGE_PCMCIA 0x0605 #define PCI_CLASS_BRIDGE_NUBUS 0x0606 @@ -828,6 +835,7 @@ #define PCI_CLASS_SYSTEM_TIMER 0x0802 #define PCI_CLASS_SYSTEM_RTC 0x0803 #define PCI_CLASS_SYSTEM_PCI_HOTPLUG 0x0804 +#define PCI_CLASS_SYSTEM_SDHCI 0x0805 #define PCI_CLASS_SYSTEM_OTHER 0x0880 #define PCI_BASE_CLASS_INPUT 0x09 @@ -856,6 +864,10 @@ #define PCI_CLASS_SERIAL_ACCESS 0x0c01 #define PCI_CLASS_SERIAL_SSA 0x0c02 #define PCI_CLASS_SERIAL_USB 0x0c03 +#define PCI_CLASS_SERIAL_USB_UHCI 0x0c0300 +#define PCI_CLASS_SERIAL_USB_OHCI 0x0c0310 +#define PCI_CLASS_SERIAL_USB_EHCI 0x0c0320 +#define PCI_CLASS_SERIAL_USB_XHCI 0x0c0330 #define PCI_CLASS_SERIAL_FIBER 0x0c04 #define PCI_CLASS_SERIAL_SMBUS 0x0c05 #define PCI_CLASS_SERIAL_INFINIBAND 0x0c06 @@ -864,6 +876,7 @@ #define PCI_CLASS_WIRELESS_IRDA 0x0d00 #define PCI_CLASS_WIRELESS_CONSUMER_IR 0x0d01 #define PCI_CLASS_WIRELESS_RF 0x0d10 +#define PCI_CLASS_WIRELESS_WHCI 0x0d1010 #define PCI_CLASS_WIRELESS_OTHER 0x0d80 #define PCI_BASE_CLASS_INTELLIGENT 0x0e @@ -891,7 +904,7 @@ /* Several ID's we need in the library */ #define PCI_VENDOR_ID_APPLE 0x106b -#define PCI_VENDOR_ID_AMD 0x1002 +#define PCI_VENDOR_ID_AMD 0x1022 #define PCI_VENDOR_ID_ATI 0x1002 #define PCI_VENDOR_ID_INTEL 0x8086 #define PCI_VENDOR_ID_NVIDIA 0x10de Index: branches/cparm/i386/libsaio/biosfn.c =================================================================== --- branches/cparm/i386/libsaio/biosfn.c (revision 1118) +++ branches/cparm/i386/libsaio/biosfn.c (revision 1119) @@ -42,7 +42,7 @@ #include "bootstruct.h" #include "libsaio.h" -#define MAX_DRIVES 8 +//#define MAX_DRIVES 8 static biosBuf_t bb; Index: branches/cparm/i386/libsaio/convert.c =================================================================== --- branches/cparm/i386/libsaio/convert.c (revision 1118) +++ branches/cparm/i386/libsaio/convert.c (revision 1119) @@ -57,7 +57,7 @@ uint32_t ascii_hex_to_int(char *buff) { uint32_t value = 0, i, digit; - for(i = 0; i < strlen(buff); i++) + for(i = 0; i < (uint32_t)strlen(buff); i++) { if (buff[i] >= 48 && buff[i] <= 57) // '0' through '9' digit = buff[i] - 48; @@ -94,9 +94,9 @@ hexNibble = hexStr[hexStrIdx]; // ignore all chars except valid hex numbers - if (hexNibble >= '0' && hexNibble <= '9' - || hexNibble >= 'A' && hexNibble <= 'F' - || hexNibble >= 'a' && hexNibble <= 'f') + if ((hexNibble >= '0' && hexNibble <= '9') + || (hexNibble >= 'A' && hexNibble <= 'F') + || (hexNibble >= 'a' && hexNibble <= 'f')) { hexByte[hexNibbleIdx++] = hexNibble; @@ -105,7 +105,7 @@ { binChar = 0; - for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) + for (hexNibbleIdx = 0; (unsigned)hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) { if (hexNibbleIdx > 0) binChar = binChar << 4; Index: branches/cparm/i386/libsaio/ppmsetup.h =================================================================== --- branches/cparm/i386/libsaio/ppmsetup.h (revision 0) +++ branches/cparm/i386/libsaio/ppmsetup.h (revision 1119) @@ -0,0 +1,378 @@ +/* +Copyright (c) 2010, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef ppmsetup_h +#define ppmsetup_h + +#include "datatype.h" + +//U32 ppm_init(void); + +#define CURRENT_PPM_RCM_INTERFACE_SPECIFICATION 11 + +#ifndef nameseg_defined +#define nameseg_defined +#define NAMESEG(s) (((U32)(s[0]) << 0) \ + |((U32)(s[1]) << 8) \ + |((U32)(s[2]) << 16) \ + |((U32)(s[3]) << 24)) +#endif + +typedef enum ssdt_loc_flag { + // Flag indicating the SSDT ACPI structure should be built in a stack-based + // buffer. If the SSDT is successfully created, then the following occurs: + // (1) the RSDT ACPI structure is moved lower in memory and updated to + // include a pointer to the new SSDT. + // (2) the SSDT APCI structure is copied into memory just above the moved + // RSDT structure + // (3) the RSD ACPI structure is updated to included the new location of + // the just moved RSDT ACPI structure + // Note: The XSDT is not updated! + // + // NOTE: THIS OPTION WILL DEPRECATED AND REMOVED + // IN A FUTURE VERSION OF THIS SPECIFICATION. + SSDT_LOC_FLAG_ACPI_RECLAIM = 0, + + // Flag indicating the SSDT should be built directly in the memory region + // provided by the ssdt_mem_addr option parameter. + // If the SSDT is successfully created, then the following occurs: + // (1) the RSDT ACPI structure is moved lower in memory and updated to + // include a pointer to the new SSDT. + // (2) the RSD ACPI structure is updated to include the new location of the + // RSDT ACPI structure. + // Note: The XSDT is not updated! + // + // NOTE: THIS OPTION WILL DEPRECATED AND REMOVED + // IN A FUTURE VERSION OF THIS SPECIFICATION. + SSDT_LOC_FLAG_ADDR_PROVIDED = 1, + + // Flag indicating the SSDT should be built directly in the memory region + // provided by the ssdt_mem_addr option parameter. + // After SSDT is successfully created, no further processing occurs. + SSDT_LOC_FLAG_ADDR_PROVIDED_NO_INSERT = 2, + + // Flag indicating the SSDT should be built directly in the memory region + // provided by the ssdt_mem_addr option parameter. + // After SSDT is successfully created, then the following occurs: + // (1) the RSDT ACPI structure is not moved but is updated to + // include a 32-bit pointer to the new SSDT. + // (2) If the XSDT exists, it is not moved but is updated to + // include a 64-bit pointer to the new SSDT. + SSDT_LOC_FLAG_ADDR_PROVIDED_INSERT = 3, +} SSDT_LOC_FLAG; + +typedef enum exit_code { + // PPM RCM completed all initialization successfully + EXIT_CODE_PPM_COMPLETED = 1, + + // Failed building P-state table + EXIT_CODE_FAILED_BUILD_PSTATES = 2, + + EXIT_CODE_PPM_EIST_DISABLED = 3, + + // Failed to find ACPI tables + EXIT_CODE_FAILED_FIND_ACPI_TABLES = 4, + + // Failed to process the ACPI MADT structure + EXIT_CODE_FAILED_PROCESS_MADT = 5, + + // Failed to resolve ACPI MADT structure against available logical + // processors + EXIT_CODE_FAILED_PROCESS_MADT_INFO = 6, + + // Failed to build ACPI SSDT structure + EXIT_CODE_FAILED_PROCESS_SSDT = 7, + + // Failed to build and intialize HOST structure + EXIT_CODE_FAILED_HOST_INIT = 8, + + // Failed during wake of all NBSP to gather processor information + EXIT_CODE_FAILED_COLLECT_SOCKET_INFO = 9, + + // Failed to resolve target configuration between desired options and + // processor features + EXIT_CODE_FAILED_DETERMINE_CONFIGURATION = 0x0a, + + // No SSDT ACPI struture was created + EXIT_CODE_NO_SSDT_CREATED = 0x0b, + + // Failed to build Cstates correctly + EXIT_CODE_FAILED_BUILD_CSTATES = 0x0c, + + // Failed to build Tstates correctly + EXIT_CODE_FAILED_BUILD_TSTATES = 0x0d, + + // Failed to find package index of logical processor listed in MADT ACPI table + EXIT_CODE_FAILED_FIND_PKG_INDEX_FROM_LAPIC = 0x0e, + + // Failed with invalid input provided for SSDT location flag + EXIT_CODE_FAILED_INVALID_SSDT_LOCATION_FLAG = 0x0f, + + // Failed with no logical processors found in MADT + EXIT_CODE_FAILED_NO_LAPIC_FOUND_IN_MADT = 0x10, + + // Failed with SSDT size exceeded during SSDT creation + EXIT_CODE_FAILED_SSDT_SIZE_EXCEEDED = 0x11, + + // Failed to build ACPI SSDT structure + EXIT_CODE_FAILED_BUILD_SSDT = 0x12, + + // Failed with core index of logical processor listed in MADT ACPI table exceeding max + EXIT_CODE_MAX_CORES_EXCEEDED = 0x13, + + // Failed to find CPU Scope from array of ACPI processor number to ACPI CPU NameSeg structures + EXIT_CODE_FAILED_FIND_CPU_SCOPE_NAME_SEG = 0x14, + + // Failed to update FADT + EXIT_CODE_FAILED_UPDATE_FADT = 0x15, + + // GPF detected + EXIT_CODE_GPF_DETECTED = 0x16, + + // Failed with invalid SSDT buffer address + EXIT_CODE_INVALID_SSDT_ADDR = 0x17, + + // Failed with invalid SSDT buffer length + EXIT_CODE_INVALID_SSDT_LEN = 0x18, +} EXIT_CODE; + +typedef struct exit_state { + // 1 = success, 0 = failure + U32 return_status; + + // Number of Failure or Informative codes included in the buffer + U32 error_code_count; + + // Buffer of Failure or Informative codes + U32 error_codes[10]; + + // This 32-bit physical memory address specifies the final location for the + // SSDT ACPI structure built by the PPM RC. + U32 ssdt_mem_addr; + + // This value specifies the final size of the SSDT ACPI structure for the + // SSDT ACPI structure built by the PPM RC. + U32 ssdt_mem_size; + + // The final state for the P-state initialization + // 1=enabled; 0=disabled + U32 pstates_enabled; + + // The final state for the Turbo feature initialization + // 1=enabled; 0=disabled + U32 turbo_enabled; + + // The final state for the C-state initialization + // 1=enabled; 0=disabled + U32 cstates_enabled; + + // The final state for the T-state initialization + // 1=enabled; 0=disabled + U32 tstates_enabled; +} EXIT_STATE; + +typedef enum cpu_namespace_flag { + // Flag indicating the SSDT ACPI structure should be built + // using ACPI 1.0 compliant processor namespace "_PR" + CPU_NAMESPACE_PR = 0, + + // Flag indicating the SSDT ACPI structure should be built + // using ACPI 2.0+ compliant processor namespace "_SB" + CPU_NAMESPACE_SB = 1, +} CPU_NAMESPACE_FLAG; + +// Define the total number of required NameSegs to reach the DSDT processor +// device or object declarations +#define MAX_SUPPORTED_CPU_NAMESEGS 3 + +typedef struct processor_number_to_nameseg { + // Contains one of the ACPI processor ID values used in a + // ACPI Declare Processor statement in the DSDT or XSDT + U32 acpi_processor_number; + + // Number of NameSpace segments in NamePath to processor devices/objects + U32 seg_count; + + // Contains the corresponding ACPI Name Scope in the form + // of a series of NameSegs constituting the NamePath to a + // processor device or object declaration + U32 nameseg[MAX_SUPPORTED_CPU_NAMESEGS]; +} PROCESSOR_NUMBER_TO_NAMESEG; + +typedef struct ppm_setup_options { + // This 32-bit physical memory address specifies a read-write memory region + // below 1MB. Minimum size is 8KB. This memory is used by the callback as + // the SIPI target and stack for each AP. This region is not required to be + // cacheable. + U32 mem_region_below_1M; + + // Number of CPU sockets which exist on the platform + U32 num_sockets; + + // Desired state for the P-state initialization + // 1=enabled; 0=disabled + U32 pstates_enabled; + + // Desired state for the P-state hardware coordination + // ACPI_PSD_COORD_TYPE_SW_ALL = 0xFC + // ACPI_PSD_COORD_TYPE_SW_ANY = 0xFD + // ACPI_PSD_COORD_TYPE_HW_ALL = 0xFE + U32 pstate_coordination; + + // Desired state for the Turbo state initialization + // 1=enabled; 0=disabled + U32 turbo_enabled; + + // Desired state for the C-state initialization + // 1=enabled; 0=disabled + U32 cstates_enabled; + + // Desired state for the C1E initialization + // 1=enabled; 0=disabled + U32 c1e_enabled; + + // Desired state for the processor core C3 state included in the _CST + // 0= processor core C3 cannot be used as an ACPI C state + // 2= processor core C3 can be used as an ACPI C2 state + // 3= processor core C3 can be used as an ACPI C3 state + // 4= processor core C3 can be used as an ACPI C2 state + // if Invariant APIC Timer detected, else not used as ACPI C state + // 5= processor core C3 can be used as an ACPI C2 state + // if Invariant APIC Timer detected, else APIC C3 state + U32 c3_enabled; + + // Desired state for the processor core C6 state included in the _CST as an + // ACPI C3 state. + // 1= processor core C6 can be used as an ACPI C3 state + // 0= processor core C6 cannot be used as an ACPI C3 state + U32 c6_enabled; + + // Desired state for the processor core C7 state included in the _CST as an + // ACPI C3 state. + // 1= processor core C7 can be used as an ACPI C7 state + // 0= processor core C7 cannot be used as an ACPI C7 state + U32 c7_enabled; + + // Desired state for providing alternate ACPI _CST structure using MWAIT + // extensions + // 1= Alternate _CST using MWAIT extension is enabled for OSPM use + // 0= Alternate _CST using MWAIT extension is disabled for OSPM use + U32 mwait_enabled; + + // Power management base address used for processors + U32 pmbase; + + // Desired state for the C-state package limit. + // Note: The C-state package limit may be further limited by the + // capabilities of the processor + // 000b = C0 (No package C-state support) + // 001b = C1 (Behavior is the same as 000b) + // 010b = C3 + // 011b = C6 + // 100b = C7 + // 111b = No package C-state limit + U32 package_cstate_limit; + + // Desired state for the T-state initialization + // 1=enabled; 0=disabled + U32 tstates_enabled; + + // This 32-bit physical memory address specifies a read-write memory region + // for the SSDT ACPI structure built by the PPM RC. Minimum size is 16KB. + U32 ssdt_mem_addr; + + // This value specifies the size of the SSDT memory region. Minimum size is + // 16KB. + U32 ssdt_mem_size; + + // This value specifies the PPM RCM behavior related to creation and + // incorporation of the new SSDT ACPI structure. See definition of the + // SSDT_LOC_FLAG for acceptable values. + U32 ssdt_loc_flag; + + // This value specifies the PPM RCM behavior related to creation and + // incorporation of the new SSDT ACPI structure. If all power management + // features are disabled by input options, the SSDT can still be created + // for debug review. + // 1 = Create SSDT even if all power management features are disabled + // 0 = Do not create SSDT if all power management features are disabled + U32 ssdt_force_creation; + + // Exit structure intended to convey state to the caller and/or subsequent + // init code + EXIT_STATE exit_state; + + // Flag indicating the processor namespace that should be used in the + // SSDT ACPI structure for each CPU. + // See definition of the CPU_NAMESPACE_FLAG for acceptable values. + U32 cpu_namespace_flag; + + // This version number identifies the PPM RCM specification. + // Specifically denotes the version of this structure definition is compliant + // with with file nehalem-ppm-rcm-vX.txt where X is the version number. + // PPMSETUP.C should always use the version definition from the top of + // this file called CURRENT_PPM_RCM_INTERFACE_SPECIFICATION. + U32 ppm_rcm_interface_specification; + + // This flag indicates whether or not after all AP Wakes are completed, + // that the AP should be forced to jump to the real mode address specified + // in the realmode_callback_address field below. + // realmode_callback = 0 means leave AP in INIT or Wait For SIPI (WFS) state + // realmode_callback = 1 means AP should jump to real mode address specified below + U32 realmode_callback_flag; + + // This file contains the real mode callback address which AP must jump to after + // INIT_SIPI_SIPI sequences used to force AP initalization for PPM. + // Upper 16-bits specify target real mode segment for a far 16-bit jump instruction + // Lower 16-bits specify target real mode offset for a far 16-bit jump instruction + U32 realmode_callback_address; + + // Number of ACPI processor number to ACPI CPU NameSeg structures + U32 cpu_map_count; + + // Array of ACPI processor number to ACPI CPU NameSeg structures + PROCESSOR_NUMBER_TO_NAMESEG *cpu_map; + + // This flag indicates whether or not PPM RC should update an existing ACPI FADT. + // modify_fadt_flag = 0 means do not modify existing ACPI FADT structure + // modify_fadt_flag = 1 means do check and if needed, modify existing ACPI FADT structure + U32 modify_fadt_flag; + + // Desired state for the performance_per_watt optimizations + // performance_per_watt = 2 means "Low Power" + // performance_per_watt = 1 means "Power Optimized or Power Balanced" + // performance_per_watt = 0 means "Traditional or Max Performance" + U32 performance_per_watt; +} PPM_SETUP_OPTIONS; + +#ifndef RCMSTART_TYPEDEF +#define RCMSTART_TYPEDEF +typedef U32 (*RCMSTART)(struct ppm_setup_options *); +#endif + +#endif // ppmsetup_h Property changes on: branches/cparm/i386/libsaio/ppmsetup.h ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/libsaio/saio_types.h =================================================================== --- branches/cparm/i386/libsaio/saio_types.h (revision 1118) +++ branches/cparm/i386/libsaio/saio_types.h (revision 1119) @@ -34,7 +34,6 @@ #else #include #endif -//#include #include "bootLion.h" #if DEBUG Index: branches/cparm/i386/libsaio/msdos.c =================================================================== --- branches/cparm/i386/libsaio/msdos.c (revision 1118) +++ branches/cparm/i386/libsaio/msdos.c (revision 1119) @@ -62,7 +62,7 @@ #define CLUST_RSRVD12 0xff8 /* reserved cluster range */ -#define false 0 +//#define false 0 #define true 1 static int msdosressector=0; @@ -386,14 +386,14 @@ st->vfatchecksum = 0; st->vfatnumber = 0; st->nument++; - if ((!st->root16 &&st->nument * sizeof (struct direntry)>=msdosclustersize) - || (st->root16 &&st->nument * sizeof (struct direntry)>=msdosbps)) + if (((int)(!st->root16 &&st->nument * sizeof (struct direntry))>=msdosclustersize) + || ((int)(st->root16 &&st->nument * sizeof (struct direntry))>=msdosbps)) st->nument = 0; return dirp; } st->nument++; - if ((!st->root16 &&st->nument * sizeof (struct direntry)>=msdosclustersize) - || (st->root16 &&st->nument * sizeof (struct direntry)>=msdosbps)) + if (((int)(!st->root16 &&st->nument * sizeof (struct direntry))>=msdosclustersize) + || ((int)(st->root16 &&st->nument * sizeof (struct direntry))>=msdosbps)) st->nument = 0; } } @@ -743,7 +743,7 @@ int toread, wastoread; char *ptr = (char *)base; struct direntry *dirp; - int i; + uint64_t i; char devStr[12]; if (MSDOSInitPartition (ih)<0) @@ -772,7 +772,7 @@ if (length==0 || length>size-offset) toread=size-offset; wastoread=toread; - bcopy (buf+(offset%msdosclustersize),ptr,min(msdosclustersize-(offset%msdosclustersize), toread)); + bcopy (buf+(offset%msdosclustersize),ptr,min((msdosclustersize-(offset%msdosclustersize)),(unsigned)toread)); ptr+=msdosclustersize-(offset%msdosclustersize); toread-=msdosclustersize-(offset%msdosclustersize); while (toread>0 && msdosreadcluster (ih, (uint8_t *)ptr, min(msdosclustersize,toread), &cluster)) Index: branches/cparm/i386/libsaio/fake_efi.c =================================================================== --- branches/cparm/i386/libsaio/fake_efi.c (revision 1118) +++ branches/cparm/i386/libsaio/fake_efi.c (revision 1119) @@ -20,7 +20,18 @@ #include "pci.h" #include "sl.h" #include "modules.h" +#include "vers.h" +#include "smp.h" +#ifndef DEBUG_EFI +#define DEBUG_EFI 0 +#endif + +#if DEBUG_EFI +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif /* * Modern Darwin kernels require some amount of EFI because Apple machines all * have EFI. Modifying the kernel source to not require EFI is of course @@ -73,8 +84,11 @@ */ /* Identify ourselves as the EFI firmware vendor */ -static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'J','a','r','o','d','_','1','.','2', 0}; -static EFI_UINT32 const FIRMWARE_REVISION = 0x0001000a; +static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'A','p','p','l','e', 0}; + +static EFI_CHAR16 const FIRMWARE_NAME[] = {'M','t','.','H','o','o','d', 0}; //a.k.a Galak. + +static EFI_UINT32 const FIRMWARE_REVISION = 0x00010400; //1.4 static EFI_UINT32 const DEVICE_SUPPORTED = 0x00000001; /* Default platform system_id (fix by IntVar) */ @@ -90,53 +104,180 @@ EFI_SYSTEM_TABLE_64 *gST64 = NULL; Node *gEfiConfigurationTableNode = NULL; +/* From Foundation/Efi/Guid/Smbios/SmBios.h */ +/* Modified to wrap Data4 array init with {} */ +#define EFI_SMBIOS_TABLE_GUID {0xeb9d2d31, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d}} + +#define EFI_ACPI_TABLE_GUID \ +{ \ +0xeb9d2d30, 0x2d88, 0x11d3, { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ +} + +#define EFI_ACPI_20_TABLE_GUID \ +{ \ +0x8868e871, 0xe4f1, 0x11d3, { 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \ +} + +#define EFI_MPS_TABLE_GUID \ +{ \ +0xeb9d2d2f,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d} \ +} +/* From Foundation/Efi/Guid/Smbios/SmBios.c */ +EFI_GUID const gEfiSmbiosTableGuid = EFI_SMBIOS_TABLE_GUID; + +EFI_GUID gEfiAcpiTableGuid = EFI_ACPI_TABLE_GUID; +EFI_GUID gEfiAcpi20TableGuid = EFI_ACPI_20_TABLE_GUID; +EFI_GUID gEfiMpsTableGuid = EFI_MPS_TABLE_GUID; + +EFI_UINT32 gNumTables32 = 0; +EFI_UINT64 gNumTables64 = 0; +EFI_CONFIGURATION_TABLE_32 gEfiConfigurationTable32[MAX_CONFIGURATION_TABLE_ENTRIES]; +EFI_CONFIGURATION_TABLE_64 gEfiConfigurationTable64[MAX_CONFIGURATION_TABLE_ENTRIES]; extern EFI_STATUS addConfigurationTable(EFI_GUID const *pGuid, void *table, char const *alias) { EFI_UINTN i = 0; + if (pGuid == NULL || table == NULL) + return EFI_INVALID_PARAMETER; + //Azi: as is, cpu's with em64t will use EFI64 on pre 10.6 systems, // wich seems to cause no problem. In case it does, force i386 arch. if (archCpuType == CPU_TYPE_I386) { - i = gST32->NumberOfTableEntries; + i = gNumTables32; } else { - i = gST64->NumberOfTableEntries; + i = (EFI_UINTN)gNumTables64; } // We only do adds, not modifications and deletes like InstallConfigurationTable - if (i >= MAX_CONFIGURATION_TABLE_ENTRIES) - stop("Ran out of space for configuration tables. Increase the reserved size in the code.\n"); + if (i >= MAX_CONFIGURATION_TABLE_ENTRIES){ + + + printf("Ran out of space for configuration tables (max = %d). Please, increase the reserved size in the code.\n", (int)MAX_CONFIGURATION_TABLE_ENTRIES); + return EFI_ABORTED; + } + + + + if (archCpuType == CPU_TYPE_I386) + { + + gEfiConfigurationTable32[i].VendorGuid = *pGuid; + gEfiConfigurationTable32[i].VendorTable = (EFI_PTR32)table; + + gNumTables32++; + } + else + { + gEfiConfigurationTable64[i].VendorGuid = *pGuid; + gEfiConfigurationTable64[i].VendorTable = (EFI_PTR32)table; + gNumTables64++ ; + } + + + Node *tableNode = DT__AddChild(gEfiConfigurationTableNode, mallocStringForGuid(pGuid)); + + // Use the pointer to the GUID we just stuffed into the system table + DT__AddProperty(tableNode, "guid", sizeof(EFI_GUID), (void*)pGuid); + + // The "table" property is the 32-bit (in our implementation) physical address of the table + DT__AddProperty(tableNode, "table", sizeof(void*) * 2, table); + + // Assume the alias pointer is a global or static piece of data + if (alias != NULL) + DT__AddProperty(tableNode, "alias", strlen(alias)+1, (char*)alias); + + return EFI_SUCCESS; - if (pGuid == NULL) - return EFI_INVALID_PARAMETER; - - if (table != NULL) +} + +static VOID EFI_ST_FIX_CRC32(void) +{ + if (archCpuType == CPU_TYPE_I386) { - // FIXME - //((EFI_CONFIGURATION_TABLE_64 *)gST->ConfigurationTable)[i].VendorGuid = *pGuid; - //((EFI_CONFIGURATION_TABLE_64 *)gST->ConfigurationTable)[i].VendorTable = (EFI_PTR64)table; - - //++gST->NumberOfTableEntries; - - Node *tableNode = DT__AddChild(gEfiConfigurationTableNode, mallocStringForGuid(pGuid)); - - // Use the pointer to the GUID we just stuffed into the system table - DT__AddProperty(tableNode, "guid", sizeof(EFI_GUID), (void*)pGuid); - - // The "table" property is the 32-bit (in our implementation) physical address of the table - DT__AddProperty(tableNode, "table", sizeof(void*) * 2, table); - - // Assume the alias pointer is a global or static piece of data - if (alias != NULL) - DT__AddProperty(tableNode, "alias", strlen(alias)+1, (char*)alias); - - return EFI_SUCCESS; + gST32->Hdr.CRC32 = 0; + gST32->Hdr.CRC32 = crc32(0L, gST32, gST32->Hdr.HeaderSize); } - return EFI_UNSUPPORTED; + else + { + gST64->Hdr.CRC32 = 0; + gST64->Hdr.CRC32 = crc32(0L, gST64, gST64->Hdr.HeaderSize); + } } +void finalizeEFIConfigTable(void ) { + + if (archCpuType == CPU_TYPE_I386) + { + EFI_SYSTEM_TABLE_32 *efiSystemTable = gST32; + + efiSystemTable->NumberOfTableEntries = gNumTables32; + efiSystemTable->ConfigurationTable = (EFI_PTR32)gEfiConfigurationTable32; + + } + else + { + EFI_SYSTEM_TABLE_64 *efiSystemTable = gST64; + + efiSystemTable->NumberOfTableEntries = gNumTables64; + efiSystemTable->ConfigurationTable = ptov64((EFI_PTR32)gEfiConfigurationTable64); + + + } + EFI_ST_FIX_CRC32(); + +#if DEBUG_EFI + EFI_UINTN i; + EFI_UINTN num = 0; + uint32_t table ; + EFI_GUID Guid; + + if (archCpuType == CPU_TYPE_I386) + { + num = gST32->NumberOfTableEntries; + + } + else + { + num = (EFI_UINTN)gST64->NumberOfTableEntries; + + } + msglog("EFI Configuration table :\n"); + for (i=0; ianchor, SMTAG) && - COMPARE_DWORD(smbios->dmi.anchor, DMITAG) && - smbios->dmi.anchor[4]==DMITAG[4] && - checksum8(smbios, sizeof(struct SMBEntryPoint)) == 0) - { - return smbios; - } - smbios = (struct SMBEntryPoint*) ( ((char*) smbios) + 16 ); - } - printf("Error: Could not find original SMBIOS !!\n"); - pause(); - return NULL; -} - -static struct SMBEntryPoint *orig = NULL; // cached - -struct SMBEntryPoint *getSmbiosOriginal() -{ - if (orig == NULL) { - orig = getAddressOfSmbiosTable(); - - if (orig) { - verbose("Found System Management BIOS (SMBIOS) table\n"); - } - - } - return orig; -} - - -#define theUUID 0 -#define thePlatformName 1 - -/* get UUID or product Name from original SMBIOS, stripped version of kabyl's readSMBIOSInfo */ -void local_readSMBIOS(int value) -{ - - SMBEntryPoint *eps = getSmbiosOriginal(); - if (eps == NULL) return; - - uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress; - SMBStructHeader *structHeader = (SMBStructHeader *)structPtr; - - for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));) - { - switch (structHeader->type) - { - case 1: //kSMBTypeSystemInformation - { - switch (value) { - case theUUID: - Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid; - break; - case thePlatformName: - { - uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length; - uint8_t field = ((SMBSystemInformation *)structHeader)->productName; - - if (!field) - return; - - for (field--; field != 0 && strlen((char *)stringPtr) > 0; - field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1)); - - DBG("original SMBIOS Product name: %s\n",(char *)stringPtr); - gPlatformName = (char *)stringPtr; - break; - } - default: - break; - } - - return; - - break; - } - - } - - structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length); - for (; ((uint16_t *)structPtr)[0] != 0; structPtr++); - - if (((uint16_t *)structPtr)[0] == 0) - structPtr += 2; - - structHeader = (SMBStructHeader *)structPtr; - } -} - /*========================================================================== * ACPI */ -#define EFI_ACPI_TABLE_GUID \ - { \ - 0xeb9d2d30, 0x2d88, 0x11d3, { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ - } +static uint64_t local_rsd_p; +static ACPI_TABLES acpi_tables; -#define EFI_ACPI_20_TABLE_GUID \ - { \ - 0x8868e871, 0xe4f1, 0x11d3, { 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \ - } - -EFI_GUID gEfiAcpiTableGuid = EFI_ACPI_TABLE_GUID; -EFI_GUID gEfiAcpi20TableGuid = EFI_ACPI_20_TABLE_GUID; - -uint64_t acpi10_p; -uint64_t acpi20_p; - -static uint64_t local_acpi10_p; -static uint64_t local_acpi20_p; - -#define tableSign(table, sgn) (table[0]==sgn[0] && table[1]==sgn[1] && table[2]==sgn[2] && table[3]==sgn[3]) - -static struct acpi_common_header * get_ACPI_TABLE(const char * table); -static struct acpi_2_fadt *gFADT = 0; - -#define EFI_MPS_TABLE_GUID \ -{ \ -0xeb9d2d2f,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d} \ -} -EFI_GUID gEfiMpsTableGuid = EFI_MPS_TABLE_GUID; - -#define MP_SIGL 0x5f504d5f -#define MP_SIGSTR "_MP_" -struct mp_t { - uint8_t sig[4]; - uint32_t config_ptr; - uint8_t len; - uint8_t ver; - uint8_t checksum; - uint8_t f1; - uint8_t f2; - uint8_t fr[3]; -}__attribute__((packed)) mp_t; - -/* - * THIS FILE USE SOME CODE FROM smp-imps - * - * - * - * Author: Erich Boleyn http://www.uruk.org/~erich/ - * - * Source file implementing Intel MultiProcessor Specification (MPS) - * version 1.1 and 1.4 SMP hardware control for Intel Architecture CPUs, - * with hooks for running correctly on a standard PC without the hardware. - * - * This file was created from information in the Intel MPS version 1.4 - * document, order number 242016-004, which can be ordered from the - * Intel literature center. - * - * General limitations of this code: - * - * (1) : This code has never been tested on an MPS-compatible system with - * 486 CPUs, but is expected to work. - * (2) : Presumes "int", "long", and "unsigned" are 32 bits in size, and - * that 32-bit pointers and memory addressing is used uniformly. - */ - -/* - * MP Configuration Table Header (cth) - * - * Look at page 4-5 of the MP spec for the starting definitions of - * this structure. - */ -struct imps_cth -{ - unsigned sig; - unsigned short base_length; - unsigned char spec_rev; - unsigned char checksum; - char oem_id[8]; - char prod_id[12]; - unsigned oem_table_ptr; - unsigned short oem_table_size; - unsigned short entry_count; - unsigned lapic_addr; - unsigned short extended_length; - unsigned char extended_checksum; - char reserved[1]; -}; - -static inline void -cmos_write_byte (int loc, int val) -{ - outb (0x70, loc); - outb (0x71, val); -} - -static inline unsigned -cmos_read_byte (int loc) -{ - outb (0x70, loc); - return inb (0x71); -} - -#define LAPIC_ID 0x20 - -static int lapic_dummy = 0; -unsigned imps_lapic_addr = ((unsigned)(&lapic_dummy)) - LAPIC_ID; - -#include "smp.h" - -#define CMOS_WRITE_BYTE(x, y) cmos_write_byte(x, y) -#define CMOS_READ_BYTE(x) cmos_read_byte(x) - -/* - * Defines that are here so as not to be in the global header file. - */ -#define EBDA_SEG_ADDR 0x40E -#define EBDA_SEG_LEN 0x400 -#define BIOS_RESET_VECTOR 0x467 -#define LAPIC_ADDR_DEFAULT 0xFEE00000uL -#define IOAPIC_ADDR_DEFAULT 0xFEC00000uL -#define CMOS_RESET_CODE 0xF -#define CMOS_RESET_JUMP 0xa -#define CMOS_BASE_MEMORY 0x15 - -static struct mp_t * -biosacpi_search_mp(char *base, int length); - -struct mp_t* getAddressOfMPSTable() -{ - struct mp_t *mp; - uint16_t *addr; - - /* EBDA is the 1 KB addressed by the 16 bit pointer at 0x40E. */ - addr = (uint16_t *)ptov(EBDA_SEG_ADDR); - if ((mp = biosacpi_search_mp((char *)(*addr << 4), EBDA_SEG_LEN)) != NULL) - return (mp); - - unsigned mem_lower = ((CMOS_READ_BYTE(CMOS_BASE_MEMORY+1) << 8) - | CMOS_READ_BYTE(CMOS_BASE_MEMORY)) << 10; - - if ((mp = biosacpi_search_mp((char *)mem_lower, EBDA_SEG_LEN)) != NULL) - return (mp); - - if ((mp = biosacpi_search_mp((char *)0x00F0000, ACPI_RANGE_END)) != NULL) - return (mp); - - return (NULL); - -} - -static struct mp_t * -biosacpi_search_mp(char *base, int length) -{ - /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */ - struct mp_t *mp; - int ofs; - - /* search on 16-byte boundaries */ - for (ofs = 0; ofs < length; ofs += 16) { - - mp = (struct mp_t*)ptov(base + ofs); - - /* compare signature, validate checksum */ - if (!strncmp((char*)mp->sig, MP_SIGSTR, strlen(MP_SIGSTR))) { - uint8_t csum = checksum8(mp, sizeof(struct mp_t)); - if(csum == 0) { - return mp; - } - - } - } - return NULL; -} - -#define ACPI_SIG_RSDP "RSD PTR " /* Root System Description Pointer */ -#define RSDP_CHECKSUM_LENGTH 20 - -/*- - * FOR biosacpi_search_rsdp AND biosacpi_find_rsdp - * - * Copyright (c) 2001 Michael Smith - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/sys/boot/i386/libi386/biosacpi.c,v 1.7 2003/08/25 23:28:31 obrien Exp $ - * $DragonFly: src/sys/boot/pc32/libi386/biosacpi.c,v 1.5 2007/01/17 17:31:19 y0netan1 Exp $ - */ - -static struct acpi_2_rsdp * -biosacpi_search_rsdp(char *base, int length, int rev); - -/* - * Find the RSDP in low memory. See section 5.2.2 of the ACPI spec. - */ -static struct acpi_2_rsdp * -biosacpi_find_rsdp(int rev) -{ - struct acpi_2_rsdp *rsdp; - uint16_t *addr; - - /* EBDA is the 1 KB addressed by the 16 bit pointer at 0x40E. */ - addr = (uint16_t *)ptov(EBDA_SEG_ADDR); - if ((rsdp = biosacpi_search_rsdp((char *)(*addr << 4), EBDA_SEG_LEN, rev)) != NULL) - return (rsdp); - - unsigned mem_lower = ((CMOS_READ_BYTE(CMOS_BASE_MEMORY+1) << 8) - | CMOS_READ_BYTE(CMOS_BASE_MEMORY)) << 10; - - if ((rsdp = biosacpi_search_rsdp((char *)mem_lower, EBDA_SEG_LEN, rev)) != NULL) - return (rsdp); - - - /* Check the upper memory BIOS space, 0xe0000 - 0xfffff. */ - if ((rsdp = biosacpi_search_rsdp((char *)0xe0000, 0x20000, rev)) != NULL) - return (rsdp); - - return (NULL); -} - -static struct acpi_2_rsdp * -biosacpi_search_rsdp(char *base, int length, int rev) -{ - struct acpi_2_rsdp *rsdp; - int ofs; - - /* search on 16-byte boundaries */ - for (ofs = 0; ofs < length; ofs += 16) { - rsdp = (struct acpi_2_rsdp*)ptov(base + ofs); - - /* compare signature, validate checksum */ - if (!strncmp(rsdp->Signature, ACPI_SIG_RSDP, strlen(ACPI_SIG_RSDP))) { - - uint8_t csum = checksum8(rsdp, RSDP_CHECKSUM_LENGTH); - if(csum == 0) - { - /* Only assume this is a 2.0 or better table if the revision is greater than 0 - * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1 - * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0. - */ - - if((rsdp->Revision > 0) && rev > 0) - { - uint8_t csum2 = checksum8(rsdp, sizeof(struct acpi_2_rsdp)); - if(csum2 == 0) - return(rsdp); - } - - // Only return the table if it is a true version 1.0 table (Revision 0) - if((rsdp->Revision == 0) && rev == 0) - return(rsdp); - } - - } - } - return(NULL); -} - /* Setup ACPI without any patch. */ -static int setupAcpiNoMod() -{ - int ret = 0; - if(local_acpi20_p) { - addConfigurationTable(&gEfiAcpi20TableGuid, &local_acpi20_p, "ACPI_20"); - ret = 1; - } else if (local_acpi10_p) { - addConfigurationTable(&gEfiAcpiTableGuid, &local_acpi10_p, "ACPI"); - ret = 1; +static EFI_STATUS setupAcpiNoMod() +{ + + EFI_STATUS ret = EFI_UNSUPPORTED; + + ACPI_TABLE_RSDP* rsdp = (ACPI_TABLE_RSDP*)((uint32_t)local_rsd_p); + if(rsdp->Revision > 0 && checksum8(rsdp, sizeof(ACPI_TABLE_RSDP))) { + ret = addConfigurationTable(&gEfiAcpi20TableGuid, &local_rsd_p, "ACPI_20"); + } else { + ret = addConfigurationTable(&gEfiAcpiTableGuid, &local_rsd_p, "ACPI"); } - return ret; } -int setup_acpi (void) +static EFI_STATUS setup_acpi (void) { - int ret = 0; + EFI_STATUS ret = EFI_UNSUPPORTED; - /* XXX aserebln why uint32 cast if pointer is uint64 ? */ - acpi10_p = local_acpi10_p = (uint32_t)biosacpi_find_rsdp(0); - acpi20_p = local_acpi20_p = (uint32_t)biosacpi_find_rsdp(2); - execute_hook("setupEfiConfigurationTable", &ret, NULL, NULL, NULL, NULL, NULL); - if (!ret) { - gFADT = (struct acpi_2_fadt *)get_ACPI_TABLE("FACP"); - uint8_t type = gFADT->PM_Profile; - if (type <= MaxSupportedPMProfile) { - Platform->Type = type; - } - ret = setupAcpiNoMod(); + if (ret != EFI_SUCCESS) { + + + if (!FindAcpiTables(&acpi_tables)){ + printf("Failed to detect ACPI tables.\n"); + return EFI_NOT_FOUND; + } + + local_rsd_p = ((uint64_t)((uint32_t)acpi_tables.RsdPointer)); + + ACPI_TABLE_FADT *FacpPointer = (acpi_tables.FacpPointer64 != (void*)0ul) ? (ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer; + + uint8_t type = FacpPointer->PreferredProfile; + if (type <= MaxSupportedPMProfile) + Platform->Type = type; + + ret = setupAcpiNoMod(); } return ret; @@ -732,6 +478,8 @@ static const char const FIRMWARE_REVISION_PROP[] = "firmware-revision"; static const char const FIRMWARE_ABI_PROP[] = "firmware-abi"; static const char const FIRMWARE_VENDOR_PROP[] = "firmware-vendor"; +static const char const FIRMWARE_NAME_PROP[] = "firmware-name"; +static const char const FIRMWARE_DATE_PROP[] = "firmware-date"; static const char const FIRMWARE_ABI_32_PROP_VALUE[] = "EFI32"; static const char const FIRMWARE_ABI_64_PROP_VALUE[] = "EFI64"; static const char const SYSTEM_ID_PROP[] = "system-id"; @@ -747,7 +495,7 @@ static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len) { if (!gPlatformName && strcmp(key, "SMproductname") == 0) - local_readSMBIOS(thePlatformName); + readSMBIOS(thePlatformName); const char *src = (strcmp(key, "SMproductname") == 0) ? gPlatformName : getStringForKey(key, &bootInfo->smbiosConfig); @@ -768,14 +516,22 @@ * Get the SystemID from the bios dmi info */ -static EFI_CHAR8* getSmbiosUUID() +static EFI_CHAR8* getSmbiosUUID() { static EFI_CHAR8 uuid[UUID_LEN]; int i, isZero, isOnes; SMBByte *p; - local_readSMBIOS(theUUID); - p = (SMBByte*)Platform->UUID; + p = (SMBByte*)Platform->UUID; + + if ( p == NULL ) { + DBG("No patched UUID found, fallback to original UUID (if exist) \n"); + + readSMBIOS(theUUID); + p = (SMBByte*)Platform->UUID; + + } + for (i=0, isZero=1, isOnes=1; ibootConfig)); if (!ret) // try bios dmi info UUID extraction @@ -825,10 +582,12 @@ } - if (ret) - memcpy(bootInfo->sysid, ret, UUID_LEN); + if (ret) { + memcpy(Platform->sysid, ret, UUID_LEN); + status = EFI_SUCCESS; + } - return ret; + return status; } /* @@ -836,7 +595,7 @@ * facp content to reflect in ioregs */ -void setupSystemType() +static VOID setupSystemType() { Node *node = DT__FindNode("/", false); if (node == 0) stop("Couldn't get root node"); @@ -854,40 +613,54 @@ }; typedef struct boot_progress_element boot_progress_element; -void setupEfiDeviceTree(void) +static VOID setupEfiDeviceTree(void) { EFI_CHAR16* serial = 0, *productname = 0; size_t len = 0; Node *node; + long size; extern char gMacOSVersion[]; node = DT__FindNode("/", false); if (node == 0) stop("Couldn't get root node"); #include "appleClut8.h" - long clut = AllocateKernelMemory(sizeof(appleClut8)); - bcopy(&appleClut8, (void*)clut, sizeof(appleClut8)); - AllocateMemoryRange( "BootCLUT", clut, sizeof(appleClut8),-1); - -#include "failedboot.h" - - long bootPict = AllocateKernelMemory(sizeof(boot_progress_element)); + size = sizeof(appleClut8); + long clut = AllocateKernelMemory(size); + bcopy(&appleClut8, (void*)clut, size); +#if UNUSED + AllocateMemoryRange( "BootCLUT", clut, size,-1); + +#else + AllocateMemoryRange( "BootCLUT", clut, size); + +#endif +#include "failedboot.h" + size = 32 + kFailedBootWidth * kFailedBootHeight; + long bootPict = AllocateKernelMemory(size); +#if UNUSED + AllocateMemoryRange( "Pict-FailedBoot", bootPict, size,-1); +#else + AllocateMemoryRange( "Pict-FailedBoot", bootPict, size); +#endif ((boot_progress_element *)bootPict)->width = kFailedBootWidth; ((boot_progress_element *)bootPict)->height = kFailedBootHeight; - ((boot_progress_element *)bootPict)->yOffset = kFailedBootOffset; + ((boot_progress_element *)bootPict)->yOffset = kFailedBootOffset; + bcopy((char *)gFailedBootPict, (char *)(bootPict + 32), size - 32); - long bootFail = AllocateKernelMemory(sizeof(gFailedBootPict)); - bcopy(&gFailedBootPict, (void*)bootFail, sizeof(gFailedBootPict)); - ((boot_progress_element *)bootPict)->data[0] = (uint8_t)bootFail;// ?? please verify + //Fix error message with Lion DP2+ installer + if (execute_hook("getboardproductPatched", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS) { + + gboardproduct = (char *)getStringForKey("SMboardproduct", &bootInfo->smbiosConfig); + + if (!gboardproduct) readSMBIOS(theProducBoard); + + } + if (gboardproduct) { + DT__AddProperty(node, "board-id", strlen(gboardproduct)+1, gboardproduct); + } - AllocateMemoryRange( "Pict-FailedBoot", bootPict, sizeof(boot_progress_element),-1); - //Fix error message with Lion DP2+ installer - const char *boardid = getStringForKey("SMboardproduct", &bootInfo->smbiosConfig); - if (boardid) - DT__AddProperty(node, "board-id", strlen(boardid)+1, (char*)boardid); - - Node *chosenNode = DT__FindNode("/chosen", true); if (chosenNode) { @@ -920,14 +693,14 @@ // We could also just do DT__FindNode("/efi/platform", true) // But I think eventually we want to fill stuff in the efi node // too so we might as well create it so we have a pointer for it too. - node = DT__AddChild(node, "efi"); + Node *efiNode = DT__AddChild(node, "efi"); // Set up the /efi/runtime-services table node similar to the way a child node of configuration-table // is set up. That is, name and table properties - Node *runtimeServicesNode = DT__AddChild(node, "runtime-services"); + Node *runtimeServicesNode = DT__AddChild(efiNode, "runtime-services"); - Node *kernelCompatibilityNode = 0; // ??? not sure that it should be used like that + Node *kernelCompatibilityNode = 0; // ??? not sure that it should be used like that (because it's maybe the kernel capability and not the cpu capability) if (gMacOSVersion[3] == '7'){ - kernelCompatibilityNode = DT__AddChild(node, "kernel-compatibility"); + kernelCompatibilityNode = DT__AddChild(efiNode, "kernel-compatibility"); DT__AddProperty(kernelCompatibilityNode, "i386", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED); } @@ -939,7 +712,7 @@ // the only thing to use a non-malloc'd pointer for something in the DT DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST32->RuntimeServices); - DT__AddProperty(node, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_32_PROP_VALUE), (char*)FIRMWARE_ABI_32_PROP_VALUE); + DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_32_PROP_VALUE), (char*)FIRMWARE_ABI_32_PROP_VALUE); } else { @@ -947,17 +720,19 @@ DT__AddProperty(kernelCompatibilityNode, "x86_64", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED); DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST64->RuntimeServices); - DT__AddProperty(node, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_64_PROP_VALUE), (char*)FIRMWARE_ABI_64_PROP_VALUE); + DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_64_PROP_VALUE), (char*)FIRMWARE_ABI_64_PROP_VALUE); } - DT__AddProperty(node, FIRMWARE_REVISION_PROP, sizeof(FIRMWARE_REVISION), (EFI_UINT32*)&FIRMWARE_REVISION); - DT__AddProperty(node, FIRMWARE_VENDOR_PROP, sizeof(FIRMWARE_VENDOR), (EFI_CHAR16*)FIRMWARE_VENDOR); + DT__AddProperty(efiNode, FIRMWARE_REVISION_PROP, sizeof(FIRMWARE_REVISION), (EFI_UINT32*)&FIRMWARE_REVISION); + DT__AddProperty(efiNode, FIRMWARE_VENDOR_PROP, sizeof(FIRMWARE_VENDOR), (EFI_CHAR16*)FIRMWARE_VENDOR); + DT__AddProperty(efiNode, FIRMWARE_NAME_PROP, sizeof(FIRMWARE_NAME), (EFI_CHAR16*)FIRMWARE_NAME); + DT__AddProperty(efiNode, FIRMWARE_DATE_PROP, strlen(I386BOOT_BUILDDATE)+1, I386BOOT_BUILDDATE); // Set up the /efi/configuration-table node which will eventually have several child nodes for // all of the configuration tables needed by various kernel extensions. - gEfiConfigurationTableNode = DT__AddChild(node, "configuration-table"); + gEfiConfigurationTableNode = DT__AddChild(efiNode, "configuration-table"); // Now fill in the /efi/platform Node - Node *efiPlatformNode = DT__AddChild(node, "platform"); + Node *efiPlatformNode = DT__AddChild(efiNode, "platform"); DT__AddProperty(efiPlatformNode, "DevicePathsSupported", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED); @@ -980,8 +755,8 @@ // Export system-id. Can be disabled with SystemId=No in com.apple.Boot.plist - if (getSystemID()) - DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) bootInfo->sysid); + if (getSystemID() == EFI_SUCCESS) + DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) Platform->sysid); // Export SystemSerialNumber if present if ((serial=getSmbiosChar16("SMserial", &len))) @@ -989,20 +764,20 @@ // Export Model if present if ((productname=getSmbiosChar16("SMproductname", &len))) - DT__AddProperty(efiPlatformNode, MODEL_PROP, len, productname); - - // Fill /efi/device-properties node. - setupDeviceProperties(node); + DT__AddProperty(efiPlatformNode, MODEL_PROP, len, productname); + + // Fill /efi/device-properties node. + setupDeviceProperties(efiNode); } /* * Load the smbios.plist override config file if any */ -static bool readSmbConfigFile = true; void setupSmbiosConfigFile(const char *filename) { - + static bool readSmbConfigFile = true; + if (readSmbConfigFile == true) { char dirSpecSMBIOS[128] = ""; @@ -1020,7 +795,7 @@ { // Check selected volume's Extra. sprintf(dirSpecSMBIOS, "/Extra/%s", filename); - if (err = loadConfigFile(dirSpecSMBIOS, &bootInfo->smbiosConfig)) + if ((err = loadConfigFile(dirSpecSMBIOS, &bootInfo->smbiosConfig))) { // Check booter volume/rdbt Extra. sprintf(dirSpecSMBIOS, "bt(0,0)/Extra/%s", filename); @@ -1036,109 +811,46 @@ } } -static void setup_Smbios() -{ - struct SMBEntryPoint *smbios_o = getSmbiosOriginal(); - smbios_p = (EFI_PTR32)smbios_o; - if (smbios_o != NULL) { - execute_hook("smbios_helper", (void *)smbios_o, NULL, NULL, NULL, NULL, NULL); - if (execute_hook("getSmbiosPatched",(void *)smbios_o, NULL, NULL, NULL, NULL, NULL) == 0) - verbose("Using the original SMBIOS !!\n"); - } - +static VOID setup_Smbios() +{ + if (execute_hook("getSmbiosPatched",NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS) { + DBG("Using the original SMBIOS !!\n"); + struct SMBEntryPoint *smbios_o = getSmbiosOriginal(); + smbios_p = ((uint64_t)((uint32_t)smbios_o)); + } } -struct acpi_common_header * get_ACPI_TABLE(const char * table) +static VOID setup_machine_signature() { - int version; - struct acpi_common_header *header = NULL; - for (version=0; version<2; version++) { - struct acpi_2_rsdp *rsdp=(struct acpi_2_rsdp *)(version?((struct acpi_2_rsdp *)(uint32_t)local_acpi20_p):((struct acpi_2_rsdp *)(uint32_t)local_acpi10_p)); - if (!rsdp) - { - DBG("No ACPI version %d found. Ignoring\n", version+1); - continue; - } - struct acpi_2_rsdt *rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress); - if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000) - { - int i; - int rsdt_entries_num=(rsdt->Length-sizeof(struct acpi_2_rsdt))/4; - uint32_t *rsdt_entries=(uint32_t *)(rsdt+1); - for (i=0;iSignature, table) == 0) - { - if ((uint32_t)header == 0xffffffff ) - { - printf("ACPI TABLE (%s) incorrect.\n", table); - header = NULL; - } - break; - } - } - } - if (version) - { - struct acpi_2_xsdt *xsdt ; - xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress); - if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000) - { - int i; - int xsdt_entries_num=(xsdt->Length-sizeof(struct acpi_2_xsdt))/8; - uint64_t *xsdt_entries=(uint64_t *)(xsdt+1); - for (i=0;iSignature, table)) - { - header=(struct acpi_common_header *)(uint32_t)xsdt_entries[i]; - if (!header || (uint64_t)xsdt_entries[i] >= 0xffffffff) - { - printf("ACPIv2+ TABLE (%s) incorrect.\n", table); - header = NULL; - } - break; - } - } - } - } - } - return header; -} - -static void setup_machine_signature() -{ Node *chosenNode = DT__FindNode("/chosen", false); if (chosenNode) { if (Platform->hardware_signature == 0xFFFFFFFF) - { - if (!gFADT) - gFADT = (struct acpi_2_fadt *)get_ACPI_TABLE("FACP"); + { + if (!local_rsd_p) + { + + if (!FindAcpiTables(&acpi_tables)){ + printf("Failed to detect ACPI tables.\n"); + goto out; + } + + local_rsd_p = ((uint64_t)((uint32_t)acpi_tables.RsdPointer)); + } + ACPI_TABLE_FACS *FacsPointer; + + if (acpi_tables.RsdRevision > 0 ) + FacsPointer = (ACPI_TABLE_FACS *)acpi_tables.FacsPointer64; + else + FacsPointer = (ACPI_TABLE_FACS *)acpi_tables.FacsPointer; - struct acpi_2_facs * facs = 0; + Platform->hardware_signature = FacsPointer->HardwareSignature; - facs = (struct acpi_2_facs *)(uint32_t)gFADT->X_FIRMWARE_CTRL; - - if (!facs || strcmp(facs->Signature, "FACS") != 0) - facs = (struct acpi_2_facs *)gFADT->FIRMWARE_CTRL; - - if (!facs || strcmp(facs->Signature, "FACS") != 0) - Platform->hardware_signature = 0; - else - Platform->hardware_signature = facs->hardware_signature; - } - +out: // Verify that we have a valid hardware signature if (Platform->hardware_signature == 0xFFFFFFFF) { - printf("warning hardware_signature is invalid"); + verbose("Warning: hardware_signature is invalid, defaulting to 0 \n"); Platform->hardware_signature = 0; } @@ -1151,41 +863,37 @@ * Installs all the needed configuration table entries */ -static void setupEfiConfigurationTable() +static VOID setupEfiConfigurationTable() { - addConfigurationTable(&gEfiSmbiosTableGuid, &smbios_p, NULL); - - - - struct mp_t *mps_p = getAddressOfMPSTable() ; - uint64_t mps = (uint32_t)mps_p; - - if (mps_p->config_ptr) { + if (smbios_p) + addConfigurationTable(&gEfiSmbiosTableGuid, &smbios_p, NULL); - struct imps_cth *local_cth_ptr - = (struct imps_cth *)ptov(mps_p->config_ptr); - - imps_lapic_addr = local_cth_ptr->lapic_addr; - - } else { - imps_lapic_addr = LAPIC_ADDR_DEFAULT; + + void *mps_p = getMPSTable(); + + if (mps_p) + { + uint64_t mps = ((uint64_t)((uint32_t)mps_p)); + + addConfigurationTable(&gEfiMpsTableGuid, &mps, NULL); } - addConfigurationTable(&gEfiMpsTableGuid, &mps, NULL); - - //Slice // PM_Model - if (platformCPUFeature(CPU_FEATURE_MOBILE)) { + if (Platform->CPU.isServer == true) + { + Platform->Type = Workstation; + } + else if (Platform->CPU.isMobile == true) { Platform->Type = Mobile; } else { Platform->Type = Desktop; } - // Invalid the platform hardware signature (this needs to be verified with acpica, but i guess that 0xFFFFFFFF is an invalid signature) + // Invalidate the platform hardware signature (this needs to be verified with acpica, but i guess that 0xFFFFFFFF is an invalid signature) Platform->hardware_signature = 0xFFFFFFFF; - // Setup ACPI with DSDT overrides (mackerintel's patch) + // Setup ACPI (mackerintel's patch) setup_acpi(); setup_machine_signature(); @@ -1193,17 +901,8 @@ // because we need to take care of facp original content, if it is correct. setupSystemType(); - // We've obviously changed the count.. so fix up the CRC32 - if (archCpuType == CPU_TYPE_I386) - { - gST32->Hdr.CRC32 = 0; - gST32->Hdr.CRC32 = crc32(0L, gST32, gST32->Hdr.HeaderSize); - } - else - { - gST64->Hdr.CRC32 = 0; - gST64->Hdr.CRC32 = crc32(0L, gST64, gST64->Hdr.HeaderSize); - } + // We've obviously changed the count.. so fix up the CRC32 + EFI_ST_FIX_CRC32(); } /* @@ -1212,7 +911,7 @@ void setupFakeEfi(void) { - // Generate efi device strings + // Collect PCI info &| Generate device prop string setup_pci_devs(root_pci_dev); // load smbios.plist file if any @@ -1233,6 +932,7 @@ setupEfiDeviceTree(); // Add configuration table entries to both the services table and the device tree - setupEfiConfigurationTable(); + setupEfiConfigurationTable(); + } Index: branches/cparm/i386/libsaio/saio_internal.h =================================================================== --- branches/cparm/i386/libsaio/saio_internal.h (revision 1118) +++ branches/cparm/i386/libsaio/saio_internal.h (revision 1119) @@ -118,7 +118,6 @@ extern int rawDiskRead(BVRef bvr, unsigned int secno, void *buffer, unsigned int len); extern int rawDiskWrite(BVRef bvr, unsigned int secno, void *buffer, unsigned int len); extern int readBootSector(int biosdev, unsigned int secno, void *buffer); -extern void turnOffFloppy(void); extern int testFAT32EFIBootSector( int biosdev, unsigned int secno, void * buffer ); /* hfs_compare.c */ @@ -136,12 +135,17 @@ /* memory.c */ long AllocateKernelMemory( long inSize ); -long AllocateMemoryRange(char * rangeName, long start, long length, long type); - +#if UNUSED +long +AllocateMemoryRange(char * rangeName, long start, long length, long type); +#else +long +AllocateMemoryRange(char * rangeName, long start, long length); +#endif /* misc.c */ extern void enableA20(void); -extern int checkForSupportedHardware(); -extern int isLaptop(); +extern void turnOffFloppy(void); + extern void getPlatformName(char *nameBuf); #ifdef NBP_SUPPORT @@ -188,8 +192,16 @@ extern long GetFSUUID(char *spec, char *uuidStr); extern long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr); extern int openmem(char *buf, int len); -extern int open(const char *str, int how); +#if UNUSED +extern int open(const char *path, int flags); +#else +extern int open(const char *path); +#endif +#if UNUSED extern int open_bvdev(const char *bvd, const char *path, int flags); +#else +extern int open_bvdev(const char *bvd, const char *path); +#endif extern int close(int fdesc); extern int file_size(int fdesc); extern int read(int fdesc, char *buf, int count); @@ -207,7 +219,11 @@ long * time, FinderInfo *finderInfo, long *infoValid); extern void flushdev(void); extern void scanBootVolumes(int biosdev, int *count); -extern void scanDisks(int biosdev, int *count); +#if UNUSED +extern void scanDisks(int biosdev, int *count); +#else +extern void scanDisks(void); +#endif extern BVRef selectBootVolume(BVRef chain); extern void getBootVolumeDescription(BVRef bvr, char *str, long strMaxLen, bool verbose); extern void setRootVolume(BVRef volume); @@ -219,52 +235,8 @@ extern BVRef gBootVolume; extern BVRef gBIOSBootVolume; -extern void turnOffFloppy(void); -#if UNUSED -extern void ichwd_init(void); -extern void ichwd_event(int sec); -extern void ichwd_free(void); +/* smp.c */ +extern void * getMPSTable(); -/* - * Exported globals here. - */ -/* - * "imps_enabled" is non-zero if the probe sequence found IMPS - * information and was successful. - */ -extern int imps_enabled; - -/* - * This contains the local APIC hardware address. - */ -extern unsigned imps_lapic_addr; - -/* - * This represents the number of CPUs found. - */ -extern int imps_num_cpus; - -/* - * This is the primary function for probing for Intel MPS 1.1/1.4 - * compatible hardware and BIOS information. While probing the CPUs - * information returned from the BIOS, this also starts up each CPU - * and gets it ready for use. - * - * Call this during the early stages of OS startup, before memory can - * be messed up. - * - * Returns N if IMPS information was found (for number of CPUs started) - * and is valid, else 0. - */ - -extern int imps_probe(void); - -/* - * This one is used as a "force" function. Give it the number of CPUs - * to start, and it will assume a certain number and try it. - */ - -extern int imps_force(int ncpus); -#endif #endif /* !__LIBSAIO_SAIO_INTERNAL_H */ Index: branches/cparm/i386/boot0/chain0.s =================================================================== --- branches/cparm/i386/boot0/chain0.s (revision 1118) +++ branches/cparm/i386/boot0/chain0.s (revision 1119) @@ -473,7 +473,7 @@ ; es:bx = pointer where to place sectors read from disk ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; AL = burst error length if ah=0x11 (ECC corrected) ; carry = 0 success ; 1 error @@ -545,7 +545,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: branches/cparm/i386/boot0/boot0.s =================================================================== --- branches/cparm/i386/boot0/boot0.s (revision 1118) +++ branches/cparm/i386/boot0/boot0.s (revision 1119) @@ -636,7 +636,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: branches/cparm/i386/boot1/boot1f32.s =================================================================== --- branches/cparm/i386/boot1/boot1f32.s (revision 1118) +++ branches/cparm/i386/boot1/boot1f32.s (revision 1119) @@ -464,7 +464,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: branches/cparm/i386/boot1/boot1he.s =================================================================== --- branches/cparm/i386/boot1/boot1he.s (revision 1118) +++ branches/cparm/i386/boot1/boot1he.s (revision 1119) @@ -609,7 +609,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: branches/cparm/i386/boot1/boot1.s =================================================================== --- branches/cparm/i386/boot1/boot1.s (revision 1118) +++ branches/cparm/i386/boot1/boot1.s (revision 1119) @@ -605,7 +605,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: branches/cparm/i386/boot1/boot1hp.s =================================================================== --- branches/cparm/i386/boot1/boot1hp.s (revision 1118) +++ branches/cparm/i386/boot1/boot1hp.s (revision 1119) @@ -489,7 +489,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: branches/cparm/i386/boot2/options.h =================================================================== --- branches/cparm/i386/boot2/options.h (revision 1118) +++ branches/cparm/i386/boot2/options.h (revision 1119) @@ -22,13 +22,14 @@ * @APPLE_LICENSE_HEADER_END@ */ -#include "boot.h" -#include "bootstruct.h" -#include "graphics.h" + #ifndef __BOOT2_OPTIONS_H #define __BOOT2_OPTIONS_H +#include "boot.h" +#include "bootstruct.h" +#include "graphics.h" typedef struct { int x; Index: branches/cparm/i386/boot2/graphics.c =================================================================== --- branches/cparm/i386/boot2/graphics.c (revision 1118) +++ branches/cparm/i386/boot2/graphics.c (revision 1119) @@ -274,8 +274,11 @@ //========================================================================== // setVESAGraphicsMode - +#if UNUSED int setVESAGraphicsMode( unsigned short width, unsigned short height, unsigned char bitsPerPixel, unsigned short refreshRate ) +#else +int setVESAGraphicsMode( unsigned short width, unsigned short height, unsigned char bitsPerPixel) +#endif { VBEModeInfoBlock minfo; unsigned short mode; @@ -294,7 +297,7 @@ { break; } - +#if UNUSED // // FIXME : generateCRTCTiming() causes crash. // @@ -331,7 +334,7 @@ // // err = setVBEMode( mode | kLinearFrameBufferBit, NULL ); // } - +#endif // Set the mode with default refresh rate. err = setVBEMode( mode | kLinearFrameBufferBit, NULL ); @@ -575,17 +578,24 @@ if ( params[2] == 256 ) params[2] = 8; if ( params[2] == 555 ) params[2] = 16; if ( params[2] == 888 ) params[2] = 32; - +#if UNUSED return setVESAGraphicsMode( params[0], params[1], params[2], params[3] ); +#else + return setVESAGraphicsMode( params[0], params[1], params[2] ); +#endif } //========================================================================== // setVideoMode // // Set the video mode to VGA_TEXT_MODE or GRAPHICS_MODE. - +#if UNUSED void setVideoMode( int mode, int drawgraphics) +#else +void +setVideoMode( int mode) +#endif { unsigned long params[4]; int count; Index: branches/cparm/i386/boot2/boot.c =================================================================== --- branches/cparm/i386/boot2/boot.c (revision 1118) +++ branches/cparm/i386/boot2/boot.c (revision 1119) @@ -79,6 +79,8 @@ char rootPath[ROOT_PATH_LEN]; } PlatformInfo; + +char *gboardproduct = NULL; char *gPlatformName = NULL; //char gRootPath[256]; long gBootMode; /* defaults to 0 == kBootModeNormal */ @@ -241,7 +243,7 @@ { wait = true; - if (strval && strcmp(strval, "no") == 0) { + if (strval && ((strcmp(strval, "no") == 0) || (strcmp(strval, "No") == 0))) { wait = false; } } @@ -250,10 +252,13 @@ pause(); } - if ((execute_hook("GUI_ExecKernel", NULL, NULL, NULL, NULL, NULL, NULL) == 0)) - //if (bootArgs->Video.v_display == VGA_TEXT_MODE) + if ((execute_hook("GUI_ExecKernel", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)) // (bootArgs->Video.v_display == VGA_TEXT_MODE) { +#if UNUSED setVideoMode( GRAPHICS_MODE, 0 ); +#else + setVideoMode( GRAPHICS_MODE ); +#endif #ifndef OPTION_ROM @@ -284,27 +289,40 @@ } #endif } - + + finalizeEFIConfigTable(); + setupBooterLog(); - finalizeBootStruct(); + finalizeBootStruct(); + if (gMacOSVersion[3] <= '6') reserveKernLegacyBootStruct(); + //uint8_t Pic1,Pic2; + + //Pic1 = inb(0x21); /* Save all interrupts Pic1 */ + //Pic2 = inb(0xa1); /* Save all interrupts Pic2 */ + + + execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL, NULL, NULL); // Notify modules that the kernel is about to be started -#if UNUSED +//#if UNUSED turnOffFloppy(); -#endif -#if BETA +//#endif +//#if BETA #include "smp.h" #include "apic.h" IMPS_LAPIC_WRITE(LAPIC_LVT1, LAPIC_ICR_DM_NMI); -#endif +//#endif if (gMacOSVersion[3] <= '6') { + //outb(0x21, Pic1); /* Restore all interrupts Pic1 */ + //outb(0xa1, Pic2); /* Restore all interrupts Pic2 */ + // Jump to kernel's entry point. There's no going back now. XXX LEGACY OS XXX startprog( kernelEntry, bootArgsLegacy ); } @@ -397,6 +415,9 @@ // Load boot.plist config file status = loadSystemConfig(&bootInfo->bootConfig); + Platform->CPU.isServer = false; + getBoolForKey(kIsServer, &Platform->CPU.isServer, &bootInfo->bootConfig); // set this as soon as possible + if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) { gBootMode |= kBootModeQuiet; } @@ -420,23 +441,27 @@ else #endif { - scanDisks(gBIOSDev, &bvCount); +#if UNUSED + scanDisks(gBIOSDev, &bvCount); +#else + scanDisks(); +#endif } // Create a separated bvr chain using the specified filters. bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount); gBootVolume = selectBootVolume(bvChain); - // Intialize module system - if(init_module_system()) + EFI_STATUS sysinit = init_module_system(); + if((sysinit == EFI_SUCCESS) || (sysinit == EFI_ALREADY_STARTED)/*should never happen*/ ) { load_all_modules(); } - + // Loading preboot ramdisk if exists. - execute_hook("loadPrebootRAMDisk", NULL, NULL, NULL, NULL, NULL, NULL); - + execute_hook("loadPrebootRAMDisk", NULL, NULL, NULL, NULL, NULL, NULL); + #ifndef OPTION_ROM // Disable rescan option by default @@ -452,21 +477,19 @@ if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev)) { gEnableCDROMRescan = promptForRescanOption(); } -#endif +#endif - - - #if DEBUG printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags); printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags); getc(); #endif - - - + setBootGlobals(bvChain); + // Display the GUI + execute_hook("GUI_Display", NULL, NULL, NULL, NULL, NULL, NULL); + // Parse args, load and start kernel. while (1) { const char *val; @@ -518,7 +541,8 @@ // Find out which version mac os we're booting. getOSVersion(gMacOSVersion); - if (platformCPUFeature(CPU_FEATURE_EM64T)) { + //if (platformCPUFeature(CPU_FEATURE_EM64T)) { + if (cpu_mode_is64bit()) { archCpuType = CPU_TYPE_X86_64; } else { archCpuType = CPU_TYPE_I386; @@ -528,24 +552,20 @@ archCpuType = CPU_TYPE_I386; } } + + getRootDevice(); - // Notify moduals that we are attempting to boot + // Notify to all modules that we are attempting to boot execute_hook("PreBoot", NULL, NULL, NULL, NULL, NULL, NULL); - if (execute_hook("getProductNamePatched", NULL, NULL, NULL, NULL, NULL, NULL) == 0) - local_readSMBIOS(1); // read smbios Platform Name + if (execute_hook("getProductNamePatched", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS) + readSMBIOS(thePlatformName); // read smbios Platform Name - getRootDevice(); if (!getValueForBootKey(bootArgs->CommandLine, kIgnorePrelinkKern, &val, &len)) { - if (getValueForKey(kPrelinkKernelKey, &val, &len, &bootInfo->bootConfig)) { - strlcpy(gBootKernelCacheFile, val, len+1); - bootInfo->adler32 = 0; //TODO: get the (unsigned long)adler32 value from kernelcache path string - - } else { - if(gMacOSVersion[3] == '7'){ - sprintf(gBootKernelCacheFile, "%s", kDefaultCachePath); + if(gMacOSVersion[3] == '7'){ + sprintf(gBootKernelCacheFile, "%s", kDefaultCachePath); } else if(gMacOSVersion[3] <= '6') { @@ -561,7 +581,7 @@ if (gRootDevice) { char *rootPath_p = platformInfo->rootPath; int len = strlen(gRootDevice) + 1; - if (len > sizeof(platformInfo->rootPath)) { + if ((unsigned)len > sizeof(platformInfo->rootPath)) { len = sizeof(platformInfo->rootPath); } memcpy(rootPath_p, gRootDevice,len); @@ -570,7 +590,7 @@ len = strlen(bootInfo->bootFile); - if ((rootPath_p - platformInfo->rootPath + len) >= + if ((unsigned)(rootPath_p - platformInfo->rootPath + len) >= sizeof(platformInfo->rootPath)) { len = sizeof(platformInfo->rootPath) - @@ -604,9 +624,7 @@ sprintf(gBootKernelCacheFile, "%s_%s.%08lX", kDefaultCachePath, (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64", bootInfo->adler32); //Snow Leopard - } - - } + } } @@ -737,7 +755,11 @@ // chainboot if (status==1) { if (getVideoMode() == GRAPHICS_MODE) { // if we are already in graphics-mode, +#if UNUSED setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode +#else + setVideoMode(VGA_TEXT_MODE); // switch back to text mode +#endif } } #ifdef NBP_SUPPORT @@ -747,7 +769,6 @@ #endif } - // Maximum config table value size #define VALUE_SIZE 2048 static void getRootDevice() Index: branches/cparm/i386/boot2/graphics.h =================================================================== --- branches/cparm/i386/boot2/graphics.h (revision 1118) +++ branches/cparm/i386/boot2/graphics.h (revision 1119) @@ -7,13 +7,14 @@ * */ + +#ifndef __BOOT_GRAPHICS_H +#define __BOOT_GRAPHICS_H + #include "boot.h" #include "bootstruct.h" #include "vbe.h" -#ifndef __BOOT_GRAPHICS_H -#define __BOOT_GRAPHICS_H - #define DEFAULT_SCREEN_WIDTH 1024 #define DEFAULT_SCREEN_HEIGHT 768 @@ -38,7 +39,11 @@ char *getVBEModeInfoString(); void getGraphicModeParams(unsigned long params[]); +#if UNUSED int setVESAGraphicsMode( unsigned short width, unsigned short height, unsigned char bitsPerPixel, unsigned short refreshRate ); +#else +int setVESAGraphicsMode( unsigned short width, unsigned short height, unsigned char bitsPerPixel); +#endif int getNumberArrayFromProperty( const char * propKey, unsigned long numbers[], Index: branches/cparm/i386/boot2/boot.h =================================================================== --- branches/cparm/i386/boot2/boot.h (revision 1118) +++ branches/cparm/i386/boot2/boot.h (revision 1119) @@ -113,6 +113,8 @@ extern bool gEnableCDROMRescan; extern bool gScanSingleDrive; extern char *gPlatformName; +extern char *gboardproduct; + //extern char gRootPath[]; extern char *gRootDevice; @@ -137,7 +139,11 @@ * graphics.c */ extern void printVBEModeInfo(); +#if UNUSED extern void setVideoMode(int mode, int drawgraphics); +#else +extern void setVideoMode(int mode); +#endif #if TEXT_SPINNER extern void spinActivityIndicator(); extern void clearActivityIndicator(); @@ -158,7 +164,7 @@ const unsigned char *imageData, unsigned char **newImageData ); extern char * decodeRLE( const void * rleData, int rleBlocks, int outBytes ); -extern void drawBootGraphics(void); +//extern void drawBootGraphics(void); extern void drawPreview(void *src, uint8_t * saveunder); extern int getVideoMode(void); extern void loadImageScale (void *input, int iw, int ih, int ip, void *output, int ow, int oh, int op, int or); Index: branches/cparm/i386/boot2/modules.c =================================================================== --- branches/cparm/i386/boot2/modules.c (revision 1118) +++ branches/cparm/i386/boot2/modules.c (revision 1119) @@ -27,15 +27,8 @@ symbolList_t* moduleSymbols = NULL; unsigned int (*lookup_symbol)(const char*) = NULL; - - -#define MOD_ERROR 0 -#define MOD_SUCCESS 1 -#define MOD_ALREADY_LOADED 2 -#define MOD_START_ERROR 3 - #if DEBUG_MODULES -void print_hook_list() +VOID print_hook_list() { moduleHook_t* hooks = moduleCallbacks; printf("Hook list: \n"); @@ -47,7 +40,7 @@ printf("\n"); } -void print_symbol_list() +VOID print_symbol_list() { symbolList_t* symbol = moduleSymbols; printf("Symbol list: \n"); @@ -66,21 +59,24 @@ * Once loaded, locate the _lookup_symbol function so that internal * symbols can be resolved. */ -int init_module_system() +EFI_STATUS init_module_system() { + msglog("* Attempting to load system module\n"); + // Intialize module system - if(load_module(SYMBOLS_MODULE)) + EFI_STATUS status = load_module(SYMBOLS_MODULE); + if((status == EFI_SUCCESS) || (status == EFI_ALREADY_STARTED)/*should never happen*/ ) { lookup_symbol = (void*)lookup_all_symbols(SYMBOL_LOOKUP_SYMBOL); if((UInt32)lookup_symbol != 0xFFFFFFFF) { - return MOD_SUCCESS; + return status; } } - return MOD_ERROR; + return EFI_LOAD_ERROR; } @@ -94,7 +90,7 @@ * reference at least one symbol within the module. */ -void load_all_modules() +VOID load_all_modules() { char* name; long flags; @@ -102,60 +98,65 @@ struct dirstuff* moduleDir = opendir("/Extra/modules/"); while(readdir(moduleDir, (const char**)&name, &flags, &time) >= 0) { + if ((strcmp(SYMBOLS_MODULE,name)) == 0) continue; // if we found Symbols.dylib, just skip it + if(strcmp(&name[strlen(name) - sizeof("dylib")], ".dylib") == 0) { char* tmp = malloc(strlen(name) + 1); strcpy(tmp, name); - DBG("Attempting to load %s\n", tmp); - //load_module(tmp); - if(load_module(tmp) != MOD_SUCCESS) + msglog("* Attempting to load module: %s\n", tmp); + if(load_module(tmp) != EFI_SUCCESS) { - // failed to load + // failed to load or already loaded free(tmp); } } +#if DEBUG_MODULES else { DBG("Ignoring %s\n", name); } +#endif } - //print_symbol_list(); +#if DEBUG_MODULES + print_symbol_list(); +#endif } /* * Load a module file in /Extra/modules * TODO: verify version number of module */ -int load_module(char* module) +EFI_STATUS load_module(char* module) { void (*module_start)(void) = NULL; // Check to see if the module has already been loaded - if(is_module_loaded(module)) + if(is_module_loaded(module) == EFI_SUCCESS) { - // NOTE: Symbols.dylib tries to load twice, this catches it as well - // as when a module links with an already loaded module - DBG("Module %s already loaded\n", module); - return MOD_ALREADY_LOADED; + msglog("Module %s already registred\n", module); + return EFI_ALREADY_STARTED; } char modString[128]; int fh = -1; sprintf(modString, "/Extra/modules/%s", module); - fh = open(modString, 0); + fh = open(modString); if(fh < 0) { #if DEBUG_MODULES - printf("Unable to locate module %s\n", modString); - getc(); + DBG("Unable to locate module %s\n", modString); + getc(); +#else + msglog("Unable to locate module %s\n", modString); #endif - return MOD_ERROR; + return EFI_OUT_OF_RESOURCES; } - int ret = MOD_SUCCESS; - unsigned int moduleSize = file_size(fh); + EFI_STATUS ret = EFI_SUCCESS; + int moduleSize = file_size(fh); char* module_base = (char*) malloc(moduleSize); if (moduleSize && read(fh, module_base, moduleSize) == moduleSize) { @@ -167,15 +168,15 @@ if(module_start && module_start != (void*)0xFFFFFFFF) { - // Notify the system that it was laoded module_loaded(module/*moduleName, moduleVersion, moduleCompat*/); + // Notify the system that it was laoded (*module_start)(); // Start the module - DBG("Module %s Loaded.\n", module); + msglog("%s successfully Loaded.\n", module); } else { // The module does not have a valid start function printf("Unable to start %s\n", module); - ret = MOD_START_ERROR; + ret = EFI_NOT_STARTED; #if DEBUG_MODULES getc(); #endif @@ -187,7 +188,7 @@ #if DEBUG_MODULES getc(); #endif - ret = MOD_ERROR; + ret = EFI_LOAD_ERROR; } close(fh); return ret; @@ -219,7 +220,7 @@ * they will be executed now in the same order that the * hooks were added. */ -int execute_hook(const char* name, void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) +EFI_STATUS execute_hook(const char* name, void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { DBG("Attempting to execute hook '%s'\n", name); moduleHook_t* hook = get_callback(name); @@ -236,17 +237,15 @@ callbacks = callbacks->next; } DBG("Hook '%s' executed.\n", name); - return MOD_SUCCESS; + return EFI_SUCCESS; } // Callback for this hook doesn't exist; DBG("No callbacks for '%s' hook.\n", name); - return MOD_ERROR; + return EFI_NOT_FOUND; } - - /* * register_hook_callback( const char* name, void(*callback)()) * name - Name of the module hook to attach to. @@ -254,7 +253,7 @@ * hook is executed. When registering a new callback name, the callback is added sorted. * NOTE: the hooks take four void* arguments. */ -void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)) +VOID register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)) { DBG("Adding callback for '%s' hook.\n", name); @@ -296,14 +295,14 @@ /* * Parse through a macho module. The module will be rebased and binded - * as specified in the macho header. If the module is sucessfuly laoded + * as specified in the macho header. If the module is successfully loaded * the module iinit address will be returned. * NOTE; all dependecies will be loaded before this module is started * NOTE: If the module is unable to load ot completeion, the modules * symbols will still be available (TODO: fix this). This should not * happen as all dependencies are verified before the sybols are read in. */ -void* parse_mach(void* binary, int(*dylib_loader)(char*), long long(*symbol_handler)(char*, long long, char)) // TODO: add param to specify valid archs +void* parse_mach(void* binary, EFI_STATUS(*dylib_loader)(char*), long long(*symbol_handler)(char*, long long, char)) // TODO: add param to specify valid archs { char is64 = false; void (*module_start)(void) = NULL; @@ -377,7 +376,7 @@ { UInt32 sectionIndex; -#if DEBUG_MODULES_r +#if HARD_DEBUG_MODULES unsigned long fileaddr; long filesize; vmaddr = (segCommand->vmaddr & 0x3fffffff); @@ -420,7 +419,7 @@ { UInt32 sectionIndex; -#if DEBUG_MODULES_r +#if HARD_DEBUG_MODULES unsigned long fileaddr; long filesize; @@ -471,14 +470,14 @@ // = dylibCommand->dylib.compatibility_version; char* name = malloc(strlen(module) + strlen(".dylib") + 1); sprintf(name, "%s.dylib", module); - if(dylib_loader) + if(dylib_loader == EFI_SUCCESS) { - int statue = dylib_loader(name); + EFI_STATUS statue = dylib_loader(name); - if( statue != MOD_SUCCESS) + if( statue != EFI_SUCCESS) { free(name); - if (statue == MOD_ERROR) { + if (statue != EFI_ALREADY_STARTED) { // Unable to load dependancy return NULL; } @@ -565,7 +564,7 @@ UInt32 tmp = 0; UInt32 tmp2 = 0; UInt8 bits = 0; - int index = 0; + UInt32 index = 0; int done = 0; unsigned int i = 0; @@ -715,6 +714,8 @@ segmentAddress += tmp2 + sizeof(void*); } break; + default: + break; } i++; } @@ -835,8 +836,7 @@ segCommand = base + sizeof(struct mach_header) + binIndex; binIndex += segCommand->cmdsize; index++; - } - while(index <= immediate); + }while(index <= immediate); segmentAddress = segCommand->fileoff; @@ -847,8 +847,7 @@ { tmp |= (bind_stream[++i] & 0x7f) << bits; bits += 7; - } - while(bind_stream[i] & 0x80); + }while(bind_stream[i] & 0x80); segmentAddress += tmp; @@ -979,6 +978,8 @@ break; + default: + break; } i++; @@ -1021,7 +1022,6 @@ } -//unsigned char *dappleClut8 [256]; /* * add_symbol * This function adds a symbol from a module to the list of known symbols @@ -1031,12 +1031,6 @@ */ long long add_symbol(char* symbol, long long addr, char is64) { - /*if (strcmp(symbol,"_appleClut8") == 0) { - //dappleClut8 = (uint8_t *)(UInt32)addr; - memcpy(dappleClut8, (uint8_t *)(UInt32)addr, 256); - return addr; - - } else*/ if(is64) return 0xFFFFFFFF; // Fixme // This only can handle 32bit symbols @@ -1059,7 +1053,7 @@ /* * print out the information about the loaded module */ -void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/) +VOID module_loaded(const char* name/*, UInt32 version, UInt32 compat*/) { moduleList_t* new_entry = malloc(sizeof(moduleList_t)); if (new_entry) { @@ -1073,7 +1067,7 @@ } } -int is_module_loaded(const char* name) +EFI_STATUS is_module_loaded(const char* name) { moduleList_t* entry = loadedModules; while(entry) @@ -1084,7 +1078,7 @@ if((strcmp(entry->module, name) == 0) || (strcmp(entry->module, fullname) == 0)) { DBG("Located module %s\n", name); - return MOD_ALREADY_LOADED; + return EFI_SUCCESS; } else { @@ -1094,7 +1088,7 @@ } DBG("Module %s not found\n", name); - return MOD_ERROR; + return EFI_NOT_FOUND; } // Look for symbols using the Smbols moduel function. @@ -1127,7 +1121,7 @@ } } -#if DEBUG_MODULES_r +#if DEBUG_MODULES if(strcmp(name, SYMBOL_DYLD_STUB_BINDER) != 0) { verbose("Unable to locate symbol %s\n", name); @@ -1165,7 +1159,7 @@ symbol_handler(symbolString + symbolEntry->n_un.n_strx, (long long)base + symbolEntry->n_value, is64); } -#if DEBUG_MODULES +#if HARD_DEBUG_MODULES bool isTexT = (((unsigned)symbolEntry->n_value > (unsigned)vmaddr) && ((unsigned)(vmaddr + vmsize) > (unsigned)symbolEntry->n_value )); printf("%s %s\n", isTexT ? "__TEXT :" : "__DATA(OR ANY) :", symbolString + symbolEntry->n_un.n_strx); @@ -1216,7 +1210,7 @@ * the function to jump directly to the new one * example: replace_function("_HelloWorld_start", &replacement_start); */ -int replace_function(const char* symbol, void* newAddress) +EFI_STATUS replace_function(const char* symbol, void* newAddress) { UInt32* jumpPointer = malloc(sizeof(UInt32*)); // TODO: look into using the next four bytes of the function instead @@ -1234,10 +1228,10 @@ *jumpPointer = (UInt32)newAddress; - return MOD_SUCCESS; + return EFI_SUCCESS; } - return MOD_ERROR; + return EFI_NOT_FOUND; } @@ -1245,7 +1239,7 @@ /* Nedded to divide 64bit numbers correctly. TODO: look into why modules need this * And why it isn't needed when compiled into boot2 */ - +/* uint64_t __udivdi3(uint64_t numerator, uint64_t denominator) { uint64_t quotient = 0, qbit = 1; @@ -1273,5 +1267,6 @@ } stop("Divide by 0"); - return MOD_ERROR; + return 0; } +*/ \ No newline at end of file Index: branches/cparm/i386/boot2/modules.h =================================================================== --- branches/cparm/i386/boot2/modules.h (revision 1118) +++ branches/cparm/i386/boot2/modules.h (revision 1119) @@ -4,10 +4,6 @@ * */ -#include -#include - - // There is a bug with the module system / rebasing / binding // that causes static variables to be incorrectly rebased or bound // Disable static variables for the moment @@ -16,10 +12,13 @@ #ifndef __BOOT_MODULES_H #define __BOOT_MODULES_H +#include +#include +#include "efi.h" + extern unsigned long long textAddress; extern unsigned long long textSection; - typedef struct symbolList_t { char* symbol; @@ -27,22 +26,10 @@ struct symbolList_t* next; } symbolList_t; -/*typedef struct moduleInfo_t -{ - char *name; - char *author; - char *date; - unsigned int *version; - unsigned int *compat; - char *licenseshort; - char *licenselong; - -}moduleInfo_t;*/ - typedef struct moduleList_t { - char* module; - //struct moduleInfo_t* info; + char* module; + //struct moduleHook_t* hook_list; struct moduleList_t* next; } moduleList_t; @@ -68,11 +55,9 @@ #define SECT_NON_LAZY_SYMBOL_PTR "__nl_symbol_ptr" #define SECT_SYMBOL_STUBS "__symbol_stub" +EFI_STATUS init_module_system(); +VOID load_all_modules(); - -int init_module_system(); -void load_all_modules(); - /* * Modules Interface * execute_hook @@ -83,22 +68,22 @@ * registers a void function to be executed when a * hook is executed. */ -int execute_hook(const char* name, void*, void*, void*, void*, void*, void*); -void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)); +EFI_STATUS execute_hook(const char* name, void*, void*, void*, void*, void*, void*); +VOID register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)); inline void rebase_location(UInt32* location, char* base, int type); inline void bind_location(UInt32* location, char* value, UInt32 addend, int type); void rebase_macho(void* base, char* rebase_stream, UInt32 size); void bind_macho(void* base, char* bind_stream, UInt32 size); -int load_module(char* module); -int is_module_loaded(const char* name); -void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/); +EFI_STATUS load_module(char* module); +EFI_STATUS is_module_loaded(const char* name); +VOID module_loaded(const char* name/*, UInt32 version, UInt32 compat*/); long long add_symbol(char* symbol, long long addr, char is64); -void* parse_mach(void* binary, - int(*dylib_loader)(char*), +VOID* parse_mach(void* binary, + EFI_STATUS(*dylib_loader)(char*), long long(*symbol_handler)(char*, long long, char) ); @@ -109,7 +94,7 @@ unsigned int lookup_all_symbols(const char* name); -int replace_function(const char* symbol, void* newAddress); +EFI_STATUS replace_function(const char* symbol, void* newAddress); extern unsigned int (*lookup_symbol)(const char*); Index: branches/cparm/i386/boot2/drivers.c =================================================================== --- branches/cparm/i386/boot2/drivers.c (revision 1118) +++ branches/cparm/i386/boot2/drivers.c (revision 1119) @@ -334,7 +334,7 @@ // Load the MKext. length = LoadThinFatFile(fileSpec, (void **)&package); - if (length < sizeof (DriversPackage)) return -1; + if (!length || (unsigned)length < sizeof (DriversPackage)) return -1; // call hook to notify modules that the mkext has been loaded execute_hook("LoadDriverMKext", (void*)fileSpec, (void*)package, (void*) length, NULL, NULL, NULL); @@ -359,9 +359,14 @@ memcpy((void *)driversAddr, (void *)package, driversLength); // Add the MKext to the memory map. - sprintf(segName, "DriversPackage-%lx", driversAddr); + sprintf(segName, "DriversPackage-%lx", driversAddr); + +#if UNUSED AllocateMemoryRange(segName, driversAddr, driversLength, kBootDriverTypeMKEXT); +#else + AllocateMemoryRange(segName, driversAddr, driversLength); +#endif return 0; } @@ -552,9 +557,14 @@ strcpy(driver->bundlePathAddr, module->bundlePath); // Add an entry to the memory map. - sprintf(segName, "Driver-%lx", (unsigned long)driver); + sprintf(segName, "Driver-%lx", (unsigned long)driver); +#if UNUSED AllocateMemoryRange(segName, driverAddr, driverLength, kBootDriverTypeKEXT); +#else + AllocateMemoryRange(segName, driverAddr, driverLength); +#endif + } } module = module->nextModule; Index: branches/cparm/i386/boot2/mboot.c =================================================================== --- branches/cparm/i386/boot2/mboot.c (revision 1118) +++ branches/cparm/i386/boot2/mboot.c (revision 1119) @@ -48,13 +48,7 @@ void chainLoad(); void waitThenReload(); -/* -int multibootRamdiskReadBytes( int biosdev, unsigned int blkno, - unsigned int byteoff, - unsigned int byteCount, void * buffer ); -int multiboot_get_ramdisk_info(int biosdev, struct driveInfo *dip); -static long multiboot_LoadExtraDrivers(FileLoadDrivers_t FileLoadDrivers_p); -*/ + // Starts off in the multiboot context 1 MB high but eventually gets into low memory // and winds up with a bootdevice in eax which is all that boot() wants // This lets the stack pointer remain very high. @@ -136,8 +130,6 @@ // want to call it under any circumstances. extern struct {} boot2_sym asm("boot2"); -//char *patch_code_start; - // prototype multiboot and keep its implementation below hi_multiboot to // ensure that it doesn't get inlined by the compiler static inline uint32_t multiboot(int multiboot_magic, struct multiboot_info *mi); @@ -173,7 +165,7 @@ if(mi_orig->mi_flags & MULTIBOOT_INFO_HAS_MODS) { struct multiboot_module *modules = (void*)mi_orig->mi_mods_addr; - int i; + uint32_t i; for(i=0; i < mi_orig->mi_mods_count; ++i) { // make sure the multiboot_module struct itself won't get clobbered @@ -264,7 +256,7 @@ mi_copy->mi_mods_addr = (uint32_t)dst_modules; // Copy all of the module info plus the actual module into high memory - int i; + uint32_t i; for(i=0; i < mi_orig->mi_mods_count; ++i) { // Assume mod_end is 1 past the actual end (i.e. it is start + size, not really end (i.e. start + size - 1)) @@ -295,11 +287,8 @@ // contains absolute locations to other things which eventually // makes a BIOS call from real mode which of course won't work // because we're stuck in extended memory at this point. - struct multiboot_info *mi_p = copyMultibootInfo(multiboot_magic, mi_orig); - + struct multiboot_info *mi_p = copyMultibootInfo(multiboot_magic, mi_orig); - //memcpy(patch_code_start, (char*)&boot2_sym + OFFSET_1MEG, 0x5fe00 /* 383.5k */); - // Get us in to low memory so we can run everything // We cannot possibly be more than 383.5k and copying extra won't really hurt anything @@ -365,9 +354,9 @@ // Multiboot puts boot device in high byte // Normal booter wants it in low byte - int bootdevice = mi->mi_boot_device_drive; + uint32_t bootdevice = mi->mi_boot_device_drive; - bool doSelectDevice = false; + //bool doSelectDevice = false; if(mi->mi_flags & MULTIBOOT_INFO_HAS_BOOT_DEVICE) { printf("Boot device 0x%x\n", bootdevice); @@ -375,7 +364,7 @@ else { printf("Multiboot info does not include chosen boot device\n"); - doSelectDevice = true; + //doSelectDevice = true; bootdevice = BAD_BOOT_DEVICE; } if(mi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) @@ -391,10 +380,10 @@ { printf("Boot device overridden to %02x with biosdev=%s\n", intVal, val); bootdevice = intVal; - doSelectDevice = false; + //doSelectDevice = false; } - else - doSelectDevice = true; + //else + // doSelectDevice = true; } #if UNUSED if(getValueForBootKey(mi->mi_cmdline, "timeout", &val, &size)) Index: branches/cparm/i386/boot2/mboot.h =================================================================== --- branches/cparm/i386/boot2/mboot.h (revision 1118) +++ branches/cparm/i386/boot2/mboot.h (revision 1119) @@ -1,4 +1,8 @@ /* File added by David F. Elliott on 2007/06/27 */ + +#ifndef __BOOT2_MBOOT_H +#define __BOOT2_MBOOT_H + #include "multiboot.h" /* @@ -19,3 +23,5 @@ #ifndef __ASSEMBLER__ /* Put any desired prototypes or other C stuff here. */ #endif + +#endif /* !__BOOT2_MBOOT_H */ \ No newline at end of file Index: branches/cparm/i386/boot2/lzss.c =================================================================== --- branches/cparm/i386/boot2/lzss.c (revision 1118) +++ branches/cparm/i386/boot2/lzss.c (revision 1119) @@ -46,7 +46,7 @@ #define F 18 /* upper limit for match_length */ #define THRESHOLD 2 /* encode string into position and length if match_length is greater than this */ -#define NIL N /* index for root of binary search trees */ +//#define NIL N /* index for root of binary search trees */ int decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen) Index: branches/cparm/i386/boot2/options.c =================================================================== --- branches/cparm/i386/boot2/options.c (revision 1118) +++ branches/cparm/i386/boot2/options.c (revision 1119) @@ -106,7 +106,7 @@ int multi_buff = 18 * (timeout); int multi = ++multi_buff; - int lasttime=0; + unsigned int lasttime=0; for ( time = time18(), timeout++; timeout > 0; ) { @@ -116,7 +116,7 @@ lasttime=time18(); } - if (ch = readKeyboardStatus()) + if ((ch = readKeyboardStatus())) break; // Count can be interrupted by holding down shift, @@ -332,7 +332,7 @@ unsigned int w; } draw = {{0}}; - if ( gMenuItems == NULL ) + if ( gMenuItems == NULL ) return 0; switch ( key ) @@ -350,6 +350,8 @@ else if ( gMenuBottom < (gMenuItemCount - 1) ) draw.f.scrollUp = 1; break; + default: + break; } if ( draw.w ) @@ -459,7 +461,7 @@ void printMemoryInfo(void) { int line; - int i; + unsigned long i; MemoryRange *mp = bootInfo->memoryMap; // Activate and clear page 1 @@ -492,7 +494,7 @@ char *getMemoryInfoString() { - int i; + unsigned long i; MemoryRange *mp = bootInfo->memoryMap; char *buff = malloc(sizeof(char)*1024); if(!buff) return 0; @@ -539,7 +541,7 @@ int key; int nextRow; int timeout; -#ifndef OPTION_ROM +#if UNUSED int bvCount; #endif BVRef bvr; @@ -787,7 +789,7 @@ } else if (strcmp(booterCommand, "rd") == 0) { - if (execute_hook("processRAMDiskCommand", (void*)argPtr, &booterParam, NULL, NULL, NULL, NULL) == 0) + if (execute_hook("processRAMDiskCommand", (void*)argPtr, &booterParam, NULL, NULL, NULL, NULL) != EFI_SUCCESS) showMessage("ramdisk module not found, please install RamdiskLoader.dylib in /Extra/modules/"); } else if (strcmp(booterCommand, "norescan") == 0) @@ -829,7 +831,11 @@ case kF10Key: gScanSingleDrive = false; - scanDisks(gBIOSDev, &bvCount); +#if UNUSED + scanDisks(gBIOSDev, &bvCount); +#else + scanDisks(); +#endif gBootVolume = NULL; clearBootArgs(); break; @@ -1105,11 +1111,11 @@ // Check Extra on booting partition sprintf(dirspec,"/Extra/%s",filename); - fd=open (dirspec,0); + fd=open (dirspec); if (fd<0) { // Fall back to booter partition sprintf(dirspec,"bt(0,0)/Extra/%s",filename); - fd=open (dirspec,0); + fd=open (dirspec); if (fd<0) { printf("BootHelp not found: %s\n", filename); @@ -1146,7 +1152,7 @@ int fd; int size; - if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { + if ((fd = open_bvdev("bt(0,0)", filename)) < 0) { printf("\nFile not found: %s\n", filename); sleep(2); return; Index: branches/cparm/i386/boot2/Makefile =================================================================== --- branches/cparm/i386/boot2/Makefile (revision 1118) +++ branches/cparm/i386/boot2/Makefile (revision 1119) @@ -12,7 +12,7 @@ CFLAGS = $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost -Werror \ -fno-builtin -DSAIO_INTERNAL_USER -static $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float + -march=pentium4 -msse2 -mfpmath=sse -msoft-float DEFINES= CONFIG = hd @@ -65,7 +65,7 @@ DATA_ADDR = $(shell printf "%d" `otool -l $(SYMROOT)/boot_embeded.sys | grep __data -A 4 | grep __DATA -A 3 | head -n 2 | tail -n 1 | cut -f 8 -d " "`) PATCH_ADDR = $(shell echo ${SYMBOL_ADDR}-${DATA_ADDR}+${DATA_OFFSET} | bc) -CFLAGS += -DSAFE_MALLOC +#CFLAGS += -DSAFE_MALLOC # CFLAGS += -DBOOT_HELPER_SUPPORT # +992 bytes @@ -109,14 +109,6 @@ @echo "\t[MACHOCONV] boot_embeded" @$(SYMROOT)/machOconv $(SYMROOT)/boot_embeded.sys $(SYMROOT)/boot_embeded - -prompt.o: vers.h -vers.h: - @echo "#define I386BOOT_VERSION \"5.0.132\"" > $(SYMROOT)/vers.h - @echo "#define I386BOOT_BUILDDATE \"`date \"+%Y-%m-%d %H:%M:%S\"`\"" >> $(SYMROOT)/vers.h - @echo "#define I386BOOT_CHAMELEONVERSION \"`cat ../../version`\"" >> $(SYMROOT)/vers.h - @echo "#define I386BOOT_CHAMELEONREVISION \"`svnversion -n | tr -d [:alpha:]`\"" >> $(SYMROOT)/vers.h - embedded.h: @cd $(SYMROOT)/../../doc && xxd -i BootHelp.txt > $(SYMROOT)/embedded.h @@ -137,6 +129,7 @@ -compatibility_version 1.0.0 \ -final_output Symbols \ -exported_symbols_list ${OBJROOT}/Symbols.save \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ ${OBJROOT}/Symbols.o \ -o $(SYMROOT)/${SYMBOLS_MODULE} Index: branches/cparm/i386/modules/NetbookInstaller/NBI.c =================================================================== --- branches/cparm/i386/modules/NetbookInstaller/NBI.c (revision 1118) +++ branches/cparm/i386/modules/NetbookInstaller/NBI.c (revision 1119) @@ -45,10 +45,14 @@ extern char * gTempSpec; extern char * gFileName; +#define kEnableNBI "EnableNBIModule" + void NetbookInstaller_start() { - //else printf("Unable to locate Extra/SystemVersion.LastPatched.plist\n"); + bool enable = true; + getBoolForKey(kEnableNBI, &enable, &bootInfo->bootConfig) ; + if (enable) register_hook_callback("PreBoot", &NBI_PreBoot_hook); } @@ -123,7 +127,7 @@ if(runNetbookInstaller == 1 ) { - if (is_module_loaded("RamDiskLoader")) { + if (execute_hook("isRamDiskRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { replace_function("_md0Ramdisk", &NBI_md0Ramdisk); } else { register_hook_callback("md0Ramdisk", NBI_md0Ramdisk_hook); @@ -157,7 +161,7 @@ // TODO: embed NBI.img in this file // If runNetbookInstaller is true, then the system has changed states, patch it sprintf(filename, "%s", "Extra/NetbookInstaller.img");; - fh = open(filename, 0); + fh = open(filename); if (fh >= 0) { @@ -170,8 +174,12 @@ { // Read new ramdisk image contents in kernel memory. if (read(fh, (char*) ramdiskPtr.base, ramdiskPtr.size) == ramdiskPtr.size) - { - AllocateMemoryRange("RAMDisk", ramdiskPtr.base, ramdiskPtr.size, kBootDriverTypeInvalid); + { +#if UNUSED + AllocateMemoryRange("RAMDisk", ramdiskPtr.base, ramdiskPtr.size, kBootDriverTypeInvalid); +#else + AllocateMemoryRange("RAMDisk", ramdiskPtr.base, ramdiskPtr.size); +#endif Node* node = DT__FindNode("/chosen/memory-map", false); if(node != NULL) { Index: branches/cparm/i386/modules/NetbookInstaller/Makefile =================================================================== --- branches/cparm/i386/modules/NetbookInstaller/Makefile (revision 1118) +++ branches/cparm/i386/modules/NetbookInstaller/Makefile (revision 1119) @@ -70,6 +70,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/*.o \ -weak_library $(SYMROOT)/Symbols.dylib \ -o $(SYMROOT)/$(MODULE_NAME).dylib Index: branches/cparm/i386/modules/RamDiskLoader/RamDiskLoader.c =================================================================== --- branches/cparm/i386/modules/RamDiskLoader/RamDiskLoader.c (revision 1118) +++ branches/cparm/i386/modules/RamDiskLoader/RamDiskLoader.c (revision 1119) @@ -16,6 +16,7 @@ #include "disk.h" +#define kEnableEDL "EnableRamDiskLoader" enum { @@ -122,14 +123,23 @@ *ret = (*p_ramdiskReadBytes)(biosdev, blkno, byteoff, byteCount, buffer); } +void is_Ram_Disk_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6){} + + void RamDiskLoader_start() { - register_hook_callback("loadPrebootRAMDisk", &loadPrebootRAMDisk_hook); - register_hook_callback("md0Ramdisk", &md0Ramdisk_hook); - register_hook_callback("processRAMDiskCommand", &processRAMDiskCommand_hook); - register_hook_callback("ramDiskLoadDrivers", &ramDiskLoadDrivers_hook); - register_hook_callback("newRamDisk_BVR", &newRamDisk_BVR_hook); - register_hook_callback("p_get_ramdisk_info", &p_get_ramdisk_info_hook); - register_hook_callback("p_ramdiskReadBytes", &p_ramdiskReadBytes_hook); + bool enable = true; + getBoolForKey(kEnableEDL, &enable, &bootInfo->bootConfig) ; + + if (enable) { + register_hook_callback("loadPrebootRAMDisk", &loadPrebootRAMDisk_hook); + register_hook_callback("md0Ramdisk", &md0Ramdisk_hook); + register_hook_callback("processRAMDiskCommand", &processRAMDiskCommand_hook); + register_hook_callback("ramDiskLoadDrivers", &ramDiskLoadDrivers_hook); + register_hook_callback("newRamDisk_BVR", &newRamDisk_BVR_hook); + register_hook_callback("p_get_ramdisk_info", &p_get_ramdisk_info_hook); + register_hook_callback("p_ramdiskReadBytes", &p_ramdiskReadBytes_hook); + register_hook_callback("isRamDiskRegistred", &is_Ram_Disk_Registred_Hook); + } } \ No newline at end of file Index: branches/cparm/i386/modules/RamDiskLoader/ramdisk.c =================================================================== --- branches/cparm/i386/modules/RamDiskLoader/ramdisk.c (revision 1118) +++ branches/cparm/i386/modules/RamDiskLoader/ramdisk.c (revision 1119) @@ -43,22 +43,22 @@ { // Use user specified md0 file sprintf(filename, "%s", override_filename); - fh = open(filename, 0); + fh = open(filename); if(fh < 0) { sprintf(filename, "bt(0,0)/Extra/%s", override_filename); - fh = open(filename, 0); + fh = open(filename); if(fh < 0) { sprintf(filename, "rd(0,0)/Extra/%s", override_filename); - fh = open(filename, 0); + fh = open(filename); if(fh < 0) { sprintf(filename, "/Extra/%s", override_filename); - fh = open(filename, 0); + fh = open(filename); } } } @@ -67,17 +67,17 @@ if(fh < 0) { sprintf(filename, "bt(0,0)/Extra/Postboot.img"); - fh = open(filename, 0); + fh = open(filename); if(fh < 0) { sprintf(filename, "rd(0,0)/Extra/Postboot.img"); - fh = open(filename, 0); + fh = open(filename); if(fh < 0) { sprintf(filename, "/Extra/Postboot.img"); // Check /Extra if not in rd(0,0) - fh = open(filename, 0); + fh = open(filename); } } } @@ -93,8 +93,12 @@ { // Read new ramdisk image contents in kernel memory. if (read(fh, (char*) ramdiskPtr.base, ramdiskPtr.size) == ramdiskPtr.size) - { - AllocateMemoryRange("RAMDisk", ramdiskPtr.base, ramdiskPtr.size, kBootDriverTypeInvalid); + { +#if UNUSED + AllocateMemoryRange("RAMDisk", ramdiskPtr.base, ramdiskPtr.size, kBootDriverTypeInvalid); +#else + AllocateMemoryRange("RAMDisk", ramdiskPtr.base, ramdiskPtr.size); +#endif Node* node = DT__FindNode("/chosen/memory-map", false); if(node != NULL) { @@ -156,10 +160,10 @@ int error = 0; // Get file handle for ramdisk file. - fh = open(param, 0); + fh = open(param); if (fh != -1) { - verbose("\nreading ramdisk image: %s\n", param); + printf("\nreading ramdisk image: %s\n", param); ramDiskSize = file_size(fh); if (ramDiskSize > 0) @@ -226,7 +230,7 @@ verbose("\nno ramdisk config...\n"); } - verbose("\nmounting: done"); + printf("\nmounting: done"); } } } Index: branches/cparm/i386/modules/RamDiskLoader/Makefile =================================================================== --- branches/cparm/i386/modules/RamDiskLoader/Makefile (revision 1118) +++ branches/cparm/i386/modules/RamDiskLoader/Makefile (revision 1119) @@ -28,7 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-mdynamic-no-pic + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-mdynamic-no-pic DEFINES= CONFIG = hd Index: branches/cparm/i386/modules/KextPatcher/Makefile =================================================================== --- branches/cparm/i386/modules/KextPatcher/Makefile (revision 1118) +++ branches/cparm/i386/modules/KextPatcher/Makefile (revision 1119) @@ -70,6 +70,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/*.o \ -weak_library $(SYMROOT)/Symbols.dylib \ -o $(SYMROOT)/$(MODULE_NAME).dylib Index: branches/cparm/i386/modules/GUI/picopng.c =================================================================== --- branches/cparm/i386/modules/GUI/picopng.c (revision 1118) +++ branches/cparm/i386/modules/GUI/picopng.c (revision 1119) @@ -17,14 +17,18 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -#include "libsa.h" + +#include "libsaio.h" #include "picopng.h" /* sys.c */ -int open_bvdev(const char *bvd, const char *path, int flags); -int read(int fdesc, char * buf, int count); -int close(int fdesc); -int file_size(int fdesc); +/* +extern int open_bvdev(const char *bvd, const char *path); +extern int close(int fdesc); +extern int file_size(int fdesc); +extern int read(int fdesc, char *buf, int count); +*/ + /*************************************************************************************************/ typedef struct png_alloc_node { @@ -1159,12 +1163,14 @@ uint8_t **imageData) { uint8_t *pngData = NULL; - int pngFile = 0, pngSize; + int pngFile = -1/*0*/, pngSize; PNG_info_t *info; int error = 0; - pngFile = open_bvdev("bt(0,0)", filename, 0); - if (pngFile == -1) { + //pngFile = open_bvdev("bt(0,0)", filename); + pngFile = open(filename); + //if (pngFile == -1) { + if (pngFile < 0) { error = -1; goto failed; } Index: branches/cparm/i386/modules/GUI/gui.c =================================================================== --- branches/cparm/i386/modules/GUI/gui.c (revision 1118) +++ branches/cparm/i386/modules/GUI/gui.c (revision 1119) @@ -27,14 +27,18 @@ #define IMG_REQUIRED -1 #define THEME_NAME_DEFAULT "Default" -const char* theme_name = THEME_NAME_DEFAULT; +const char* theme_name = THEME_NAME_DEFAULT; +char dirsrc[22]; + #ifdef EMBED_THEME #include "art.h" #endif -#define LOADPNG(img, alt_img) if (loadThemeImage(#img, alt_img) != 0) { return 1; } +static int loadThemeImage(char *src, const char *image, int alt_image); +#define LOADPNG(src, img, alt_img) if (loadThemeImage(src, #img, alt_img) != 0) { return 1; } + #ifndef MIN #define MIN(x, y) ((x) < (y) ? (x) : (y)) #endif @@ -196,7 +200,7 @@ int getImageIndexByName(const char *name) { int i; - for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) + for (i = 0; (unsigned)i < sizeof(images) / sizeof(images[0]); i++) { if (strcmp(name, images[i].name) == 0) return i; // found the name @@ -246,7 +250,7 @@ } #endif -static int loadThemeImage(const char *image, int alt_image) +static int loadThemeImage(char* src, const char *image, int alt_image) { char dirspec[256]; int i; @@ -256,7 +260,7 @@ uint16_t width; uint16_t height; uint8_t *imagedata; - if ((strlen(image) + strlen(theme_name) + 20 ) > sizeof(dirspec)) { + if ((unsigned)(strlen(image) + strlen(theme_name) + 30 ) > sizeof(dirspec)) { return 1; } @@ -265,7 +269,7 @@ if (images[i].image == NULL) { images[i].image = malloc(sizeof(pixmap_t)); } - sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image); + sprintf(dirspec, "%s/%s/%s.png", src, theme_name, image); width = 0; height = 0; @@ -320,59 +324,59 @@ return 1; } -static int loadGraphics(void) +static int loadGraphics(char *src) { - LOADPNG(background, IMG_REQUIRED); + LOADPNG(src, background, IMG_REQUIRED); - LOADPNG(logo, IMG_REQUIRED); + LOADPNG(src, logo, IMG_REQUIRED); - LOADPNG(device_generic, IMG_REQUIRED); - LOADPNG(device_generic_o, iDeviceGeneric); - LOADPNG(device_hfsplus, iDeviceGeneric); - LOADPNG(device_hfsplus_o, iDeviceHFS); - LOADPNG(device_hfsraid, iDeviceGeneric); - LOADPNG(device_hfsraid_o, iDeviceHFSRAID); - LOADPNG(device_ext3, iDeviceGeneric); - LOADPNG(device_ext3_o, iDeviceEXT3); - LOADPNG(device_freebsd, iDeviceGeneric); - LOADPNG(device_freebsd_o, iDeviceFreeBSD); - LOADPNG(device_openbsd, iDeviceGeneric); - LOADPNG(device_openbsd_o, iDeviceOpenBSD); - LOADPNG(device_fat, iDeviceGeneric); - LOADPNG(device_fat_o, iDeviceFAT); - LOADPNG(device_fat16, iDeviceFAT); - LOADPNG(device_fat16_o, iDeviceFAT_o); - LOADPNG(device_fat32, iDeviceFAT); - LOADPNG(device_fat32_o, iDeviceFAT_o); - LOADPNG(device_ntfs, iDeviceGeneric); - LOADPNG(device_ntfs_o, iDeviceNTFS); - LOADPNG(device_cdrom, iDeviceGeneric); - LOADPNG(device_cdrom_o, iDeviceCDROM); + LOADPNG(src, device_generic, IMG_REQUIRED); + LOADPNG(src, device_generic_o, iDeviceGeneric); + LOADPNG(src, device_hfsplus, iDeviceGeneric); + LOADPNG(src, device_hfsplus_o, iDeviceHFS); + LOADPNG(src, device_hfsraid, iDeviceGeneric); + LOADPNG(src, device_hfsraid_o, iDeviceHFSRAID); + LOADPNG(src, device_ext3, iDeviceGeneric); + LOADPNG(src, device_ext3_o, iDeviceEXT3); + LOADPNG(src, device_freebsd, iDeviceGeneric); + LOADPNG(src, device_freebsd_o, iDeviceFreeBSD); + LOADPNG(src, device_openbsd, iDeviceGeneric); + LOADPNG(src, device_openbsd_o, iDeviceOpenBSD); + LOADPNG(src, device_fat, iDeviceGeneric); + LOADPNG(src, device_fat_o, iDeviceFAT); + LOADPNG(src, device_fat16, iDeviceFAT); + LOADPNG(src, device_fat16_o, iDeviceFAT_o); + LOADPNG(src, device_fat32, iDeviceFAT); + LOADPNG(src, device_fat32_o, iDeviceFAT_o); + LOADPNG(src, device_ntfs, iDeviceGeneric); + LOADPNG(src, device_ntfs_o, iDeviceNTFS); + LOADPNG(src, device_cdrom, iDeviceGeneric); + LOADPNG(src, device_cdrom_o, iDeviceCDROM); - LOADPNG(device_selection, IMG_REQUIRED); - LOADPNG(device_scroll_prev, IMG_REQUIRED); - LOADPNG(device_scroll_next, IMG_REQUIRED); + LOADPNG(src, device_selection, IMG_REQUIRED); + LOADPNG(src, device_scroll_prev, IMG_REQUIRED); + LOADPNG(src, device_scroll_next, IMG_REQUIRED); - LOADPNG(menu_boot, IMG_REQUIRED); - LOADPNG(menu_verbose, IMG_REQUIRED); - LOADPNG(menu_ignore_caches, IMG_REQUIRED); - LOADPNG(menu_single_user, IMG_REQUIRED); - LOADPNG(menu_memory_info, IMG_REQUIRED); - LOADPNG(menu_video_info, IMG_REQUIRED); - LOADPNG(menu_help, IMG_REQUIRED); - LOADPNG(menu_verbose_disabled, IMG_REQUIRED); - LOADPNG(menu_ignore_caches_disabled, IMG_REQUIRED); - LOADPNG(menu_single_user_disabled, IMG_REQUIRED); - LOADPNG(menu_selection, IMG_REQUIRED); + LOADPNG(src, menu_boot, IMG_REQUIRED); + LOADPNG(src, menu_verbose, IMG_REQUIRED); + LOADPNG(src, menu_ignore_caches, IMG_REQUIRED); + LOADPNG(src, menu_single_user, IMG_REQUIRED); + LOADPNG(src, menu_memory_info, IMG_REQUIRED); + LOADPNG(src, menu_video_info, IMG_REQUIRED); + LOADPNG(src, menu_help, IMG_REQUIRED); + LOADPNG(src, menu_verbose_disabled, IMG_REQUIRED); + LOADPNG(src, menu_ignore_caches_disabled, IMG_REQUIRED); + LOADPNG(src, menu_single_user_disabled, IMG_REQUIRED); + LOADPNG(src, menu_selection, IMG_REQUIRED); - LOADPNG(progress_bar, IMG_REQUIRED); - LOADPNG(progress_bar_background, IMG_REQUIRED); + LOADPNG(src, progress_bar, IMG_REQUIRED); + LOADPNG(src, progress_bar_background, IMG_REQUIRED); - LOADPNG(text_scroll_prev, IMG_REQUIRED); - LOADPNG(text_scroll_next, IMG_REQUIRED); + LOADPNG(src, text_scroll_prev, IMG_REQUIRED); + LOADPNG(src, text_scroll_next, IMG_REQUIRED); - LOADPNG(font_console, IMG_REQUIRED); - LOADPNG(font_small, IMG_REQUIRED); + LOADPNG(src, font_console, IMG_REQUIRED); + LOADPNG(src, font_small, IMG_REQUIRED); initFont( &font_console, &images[iFontConsole]); initFont( &font_small, &images[iFontSmall]); @@ -617,11 +621,11 @@ /* * Parse infobox parameters */ - if(getIntForKey("infobox_width", &val, theme)) - gui.infobox.width = MIN( screen_width , val ); + if(getIntForKey("infobox_width", &val, theme) && val >= 0) + gui.infobox.width = MIN( screen_width ,(unsigned) val ); - if(getIntForKey("infobox_height", &val, theme)) - gui.infobox.height = MIN( screen_height , val ); + if(getIntForKey("infobox_height", &val, theme) && val >= 0) + gui.infobox.height = MIN( screen_height , (unsigned)val ); if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) ) gui.infobox.pos.x = pixel; @@ -678,8 +682,8 @@ if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) ) gui.bootprompt.width = pixel; - if(getIntForKey("bootprompt_height", &val, theme)) - gui.bootprompt.height = MIN( screen_height , val ); + if(getIntForKey("bootprompt_height", &val, theme) && val >= 0) + gui.bootprompt.height = MIN( screen_height , (unsigned)val ); if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) ) gui.bootprompt.pos.x = pixel; @@ -687,11 +691,11 @@ if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) ) gui.bootprompt.pos.y = pixel; - if(getIntForKey("bootprompt_textmargin_h", &val, theme)) - gui.bootprompt.hborder = MIN( gui.bootprompt.width , val ); + if(getIntForKey("bootprompt_textmargin_h", &val, theme) && val >= 0) + gui.bootprompt.hborder = MIN( gui.bootprompt.width , (unsigned)val ); - if(getIntForKey("bootprompt_textmargin_v", &val, theme)) - gui.bootprompt.vborder = MIN( gui.bootprompt.height , val ); + if(getIntForKey("bootprompt_textmargin_v", &val, theme) && val >= 0) + gui.bootprompt.vborder = MIN( gui.bootprompt.height , (unsigned)val ); if(getColorForKey("bootprompt_bgcolor", &color, theme)) gui.bootprompt.bgcolor = (color & 0x00FFFFFF); @@ -708,11 +712,8 @@ #define MAX_tHEME 255 -int randomTheme(const char **theme) { - - char dirspec[256]; - sprintf(dirspec, "/Extra/Themes"); - +int randomTheme(char *dirspec, const char **theme) { + long ret, flags, time; long long index; @@ -733,7 +734,7 @@ // Make sure this is a directory. if ((flags & kFileTypeMask) != kFileTypeDirectory) continue; - if ((strlen(name) + 27) > sizeof(dirspec)) continue; + if ((unsigned)(strlen(name) + 34) > 256) continue; if ((list[i] = (char *)malloc(strlen(name))) == NULL) continue; @@ -777,6 +778,27 @@ return 1; } + { + long flags; + long time; + long ret = -1; + + ret = GetFileInfo("/Extra/", "Themes", &flags, &time); + if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) { + sprintf(dirsrc, "/Extra/Themes"); + + } else { + ret = GetFileInfo("bt(0,0)/Extra/", "Themes", &flags, &time); + if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) { + sprintf(dirsrc, "bt(0,0)/Extra/Themes"); + + } else { + return 1; + } + + } + } + int len; bool theme_ran= false; getBoolForKey("RandomTheme", &theme_ran, &bootInfo->bootConfig); @@ -784,7 +806,7 @@ if (theme_ran) { - ret = randomTheme(&theme_name); + ret = randomTheme(dirsrc, &theme_name); } @@ -814,27 +836,31 @@ { int val; char dirspec[256]; - - if ((strlen(theme_name) + 27) > sizeof(dirspec)) { + + + if ((unsigned)(strlen(theme_name) + 34) > sizeof(dirspec)) { return 1; } + + sprintf(dirspec, "%s/%s/theme.plist", dirsrc ,theme_name); - sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name); - - if (strlen(theme_name) == 0 || loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) { + if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) { + #ifdef EMBED_THEME - config_file_t *config; - - config = &bootInfo->themeConfig; - if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) { + if (strlen(theme_name) == 0) { + config_file_t *config; + + config = &bootInfo->themeConfig; + if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) { + return 1; + } + } +#else return 1; - } -#else - return 1; -#endif - } +#endif + } - if (execute_hook("getResolution_hook", &screen_params[0], &screen_params[1], &screen_params[2], NULL, NULL, NULL) == 0) + if (execute_hook("getResolution_hook", &screen_params[0], &screen_params[1], &screen_params[2], NULL, NULL, NULL) != EFI_SUCCESS) { // parse display size parameters if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0) { @@ -857,7 +883,7 @@ gui.screen.height = screen_params[1]; // load graphics otherwise fail and return - if (loadGraphics() == 0) { + if (loadGraphics(dirsrc) == 0) { loadThemeValues(&bootInfo->themeConfig); colorFont(&font_small, gui.screen.font_small_color); colorFont(&font_console, gui.screen.font_console_color); @@ -878,7 +904,11 @@ gui.logo.draw = true; drawBackground(); // lets copy the screen into the back buffer - setVideoMode( GRAPHICS_MODE, 0 ); +#if UNUSED + setVideoMode( GRAPHICS_MODE, 0 ); +#else + setVideoMode( GRAPHICS_MODE ); +#endif gui.initialised = true; return 0; } @@ -1119,15 +1149,20 @@ return; } +#if UNUSED inline void vramwrite (void *data, int width, int height) +#else +inline +void vramwrite (void *data, int width) +#endif { - if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) + if (VIDEO (depth) == 0x20 /*32*/ && VIDEO (rowBytes) == (unsigned long)gui.backbuffer->width * 4) memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height)); else { uint32_t r, g, b; - int i, j; + uint32_t i, j; for (i = 0; i < VIDEO (height); i++) for (j = 0; j < VIDEO (width); j++) { @@ -1149,7 +1184,9 @@ // break; case 15: *(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7); - break; + break; + default: + break; } } } @@ -1171,9 +1208,11 @@ if (gui.infobox.draw) blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos ); } - +#if UNUSED vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height ); - +#else + vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width ); +#endif if (gui.redraw) { memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); @@ -1538,7 +1577,7 @@ // we skip the first line because there are just the red pixels for the char width for( y = 1; y< (font->height); y++) { - for( x2 = start, x3 = 0; x2 < end; x2++, x3++) + for( x2 = (unsigned)start, x3 = 0; x2 < (unsigned)end; x2++, x3++) { pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y ); } @@ -1754,7 +1793,7 @@ { int y; - if( time18() > lasttime) + if( time18() > (unsigned) lasttime) { lasttime = time18(); @@ -1944,6 +1983,8 @@ return buff; } break; + default: + break; } return DO_NOT_BOOT; } @@ -1955,7 +1996,7 @@ //========================================================================== // loadBootGraphics -void loadBootGraphics(void) +void loadBootGraphics(char *src) { if (bootImageData != NULL) { return; @@ -1963,11 +2004,11 @@ char dirspec[256]; - if ((strlen(theme_name) + 24) > sizeof(dirspec)) { + if ((unsigned)(strlen(theme_name) + 34) > sizeof(dirspec)) { usePngImage = false; return; } - sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name); + sprintf(dirspec, "%s/%s/boot.png", src, theme_name); if (strlen(theme_name) == 0 || loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) { #ifdef EMBED_THEME if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0) @@ -1991,12 +2032,12 @@ usePngImage = true; if (bootImageData == NULL) - loadBootGraphics(); + loadBootGraphics(dirsrc); } - if (execute_hook("getResolution_hook", &screen_params[0], &screen_params[1], &screen_params[2], NULL, NULL, NULL) == 0) + if (execute_hook("getResolution_hook", &screen_params[0], &screen_params[1], &screen_params[2], NULL, NULL, NULL) != EFI_SUCCESS) { // parse screen size parameters if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) { @@ -2023,9 +2064,13 @@ // Set graphics mode if the booter was in text mode or the screen resolution has changed. if (bootArgs->Video.v_display == VGA_TEXT_MODE - || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) + || (screen_params[0] != (uint32_t)oldScreenWidth && screen_params[1] != (uint32_t)oldScreenHeight) ) { +#if UNUSED setVideoMode(GRAPHICS_MODE, 0); +#else + setVideoMode(GRAPHICS_MODE); +#endif } if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) { @@ -2090,7 +2135,11 @@ if ( params[2] == 555 ) params[2] = 16; if ( params[2] == 888 ) params[2] = 32; - return setVESAGraphicsMode( params[0], params[1], params[2], params[3] ); +#if UNUSED + return setVESAGraphicsMode( params[0], params[1], params[2], params[3] ); +#else + return setVESAGraphicsMode( params[0], params[1], params[2] ); +#endif } @@ -2128,13 +2177,13 @@ for ( time = time18(), timeout++; timeout > 0; ) { - if( time18() > lasttime) + if( time18() > (unsigned)lasttime) { multi--; lasttime=time18(); } - if (ch = readKeyboardStatus()) + if ((ch = readKeyboardStatus())) break; // Count can be interrupted by holding down shift, Index: branches/cparm/i386/modules/GUI/picopng.h =================================================================== --- branches/cparm/i386/modules/GUI/picopng.h (revision 1118) +++ branches/cparm/i386/modules/GUI/picopng.h (revision 1119) @@ -2,7 +2,10 @@ #define _PICOPNG_H #include - +#include +#include +#include +#include typedef struct { uint32_t *data; size_t size; Index: branches/cparm/i386/modules/GUI/GUI_module.c =================================================================== --- branches/cparm/i386/modules/GUI/GUI_module.c (revision 1118) +++ branches/cparm/i386/modules/GUI/GUI_module.c (revision 1119) @@ -68,7 +68,7 @@ ** The kernel is about to start, draw the boot graphics if we are not in ** verbose mode. **/ -void GUI_ExecKernel_hook(void* kernelEntry, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) +void GUI_ExecKernel_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { if(!gVerboseMode) { @@ -77,7 +77,11 @@ } else { - setVideoMode( GRAPHICS_MODE, 0 ); +#if UNUSED + setVideoMode(GRAPHICS_MODE, 0); +#else + setVideoMode(GRAPHICS_MODE); +#endif } KernelStart = true; @@ -110,21 +114,18 @@ } -/** - ** Module startup code. Replace console only print functions as well as - ** replace various menu functions. Finaly, initialize the gui and hook - ** into important events. - **/ -void GUI_start() +void GUI_diplay_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { + // Start and display the gui + msglog("* Attempting to Display GUI\n"); - // Start the gui - if (initGUI()) { - useGUI = false; // initGUI() returned with an error, disabling GUI. + useGUI = false; // initGUI() returned with an error, disabling GUI. + msglog("* GUI failed to Display, or disabled by user (a.k.a you)\n"); + } else { @@ -138,13 +139,26 @@ replace_function("_error", &GUI_error); replace_function("_stop", &GUI_stop); replace_function("_showMessage", &GUI_showMessage); - - + + // Hoot for the boot screen register_hook_callback("GUI_ExecKernel", &GUI_ExecKernel_hook); register_hook_callback("GUI_PreBoot", &GUI_PreBoot_hook); - - } + + msglog("* GUI successfully Displayed\n"); + + + } +} + +/** + ** Module startup code. Replace console only print functions as well as + ** replace various menu functions. Finaly, initialize the gui and hook + ** into important events. + **/ +void GUI_start(moduleList_t* module) +{ + register_hook_callback("GUI_Display", &GUI_diplay_hook); } @@ -248,6 +262,8 @@ gBootMode = kBootModeNormal; addBootArg(kSingleUserModeFlag); break; + default: + break; } } @@ -278,6 +294,8 @@ draw.f.scrollUp = 1; } break; + default: + break; } } @@ -519,7 +537,9 @@ int key; int nextRow; int timeout; +#if UNUSED int bvCount; +#endif BVRef bvr; BVRef menuBVR; bool showPrompt, newShowPrompt, isCDROM; @@ -539,7 +559,11 @@ // ensure we're in graphics mode if gui is setup if (gui.initialised && bootArgs->Video.v_display == VGA_TEXT_MODE) { +#if UNUSED setVideoMode(GRAPHICS_MODE, 0); +#else + setVideoMode(GRAPHICS_MODE); +#endif } // Clear command line boot arguments @@ -862,7 +886,7 @@ } else if (strcmp(booterCommand, "rd") == 0) { - if (execute_hook("processRAMDiskCommand", (void*)argPtr, &booterParam, NULL, NULL, NULL, NULL) == 0) + if (execute_hook("processRAMDiskCommand", (void*)argPtr, &booterParam, NULL, NULL, NULL, NULL) != EFI_SUCCESS) showMessage("ramdisk module not found, please install RamdiskLoader.dylib in /Extra/modules/"); } else if (strcmp(booterCommand, "norescan") == 0) @@ -904,7 +928,11 @@ case kF10Key: gScanSingleDrive = false; - scanDisks(gBIOSDev, &bvCount); +#if UNUSED + scanDisks(gBIOSDev, &bvCount); +#else + scanDisks(); +#endif gBootVolume = NULL; clearBootArgs(); break; @@ -917,8 +945,11 @@ { if (bootArgs->Video.v_display == GRAPHICS_MODE) { +#if UNUSED setVideoMode(VGA_TEXT_MODE, 0); - +#else + setVideoMode(VGA_TEXT_MODE); +#endif setCursorPosition(0, 0, 0); clearScreenRows(0, kScreenLastRow); @@ -946,7 +977,11 @@ else { gui.redraw = true; +#if UNUSED setVideoMode(GRAPHICS_MODE, 0); +#else + setVideoMode(GRAPHICS_MODE); +#endif updateVRAM(); } } Index: branches/cparm/i386/modules/GUI/gui.h =================================================================== --- branches/cparm/i386/modules/GUI/gui.h (revision 1118) +++ branches/cparm/i386/modules/GUI/gui.h (revision 1119) @@ -11,6 +11,8 @@ /* * cparm : cleaned */ +#ifndef __BOOT2_GUI_H +#define __BOOT2_GUI_H #include "boot.h" #include "bootstruct.h" @@ -19,9 +21,6 @@ #include "picopng.h" #include "options.h" -#ifndef __BOOT2_GUI_H -#define __BOOT2_GUI_H - void showTextBuffer(char *buf, int size); int GUI_initGraphicsMode (); int GUI_countdown( const char * msg, int row, int timeout ); Index: branches/cparm/i386/modules/GUI/rand.h =================================================================== --- branches/cparm/i386/modules/GUI/rand.h (revision 1118) +++ branches/cparm/i386/modules/GUI/rand.h (revision 1119) @@ -4,10 +4,11 @@ * rand & srand implementation */ +#ifndef __RAND_H +#define __RAND_H + #include "libsa.h" -#ifndef __RAND_H -#define __RAND_H extern int rand (void); extern void srand (unsigned int seed); #endif /* !__RAND_H */ \ No newline at end of file Index: branches/cparm/i386/modules/GUI/Makefile =================================================================== --- branches/cparm/i386/modules/GUI/Makefile (revision 1118) +++ branches/cparm/i386/modules/GUI/Makefile (revision 1119) @@ -27,8 +27,8 @@ -D__ARCHITECTURE__=\"i386\" -DSAIO_INTERNAL_USER \ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ - -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common + -mpreferred-stack-boundary=2 -fno-align-functions \ + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common -fno-stack-protector #-lc_kext -libcc_kext -fstack-protector-all DEFINES= CONFIG = hd @@ -81,6 +81,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/rand.o \ $(OBJROOT)/GUI_module.o \ $(OBJROOT)/gui.o \ @@ -89,21 +90,21 @@ -o $(SYMROOT)/$(MODULE_NAME).dylib GUI_module.o: - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "GUI_module.c" $(INC) -o "$(OBJROOT)/GUI_module.o" + gcc-4.2 $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "GUI_module.c" $(INC) -o "$(OBJROOT)/GUI_module.o" gui.o: - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "gui.c" $(INC) -o "$(OBJROOT)/gui.o" + gcc-4.2 $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "gui.c" $(INC) -o "$(OBJROOT)/gui.o" picopng.o: - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "picopng.c" $(INC) -o "$(OBJROOT)/picopng.o" + gcc-4.2 $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "picopng.c" $(INC) -o "$(OBJROOT)/picopng.o" graphic_utils.o: - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "graphic_utils.c" $(INC) -o "$(OBJROOT)/graphic_utils.o" + gcc-4.2 $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "graphic_utils.c" $(INC) -o "$(OBJROOT)/graphic_utils.o" rand.o: - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "rand.c" $(INC) -o "$(OBJROOT)/rand.o" - + gcc-4.2 $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "rand.c" $(INC) -o "$(OBJROOT)/rand.o" + art.h: @if [ "$(PNGCRUSH)" ]; then \ echo "optimizing art files ...\n$(PNGCRUSH) $(PNGOPTIONS) artwork/$(THEME)"; \ Index: branches/cparm/i386/modules/GUI/graphic_utils.c =================================================================== --- branches/cparm/i386/modules/GUI/graphic_utils.c (revision 1118) +++ branches/cparm/i386/modules/GUI/graphic_utils.c (revision 1119) @@ -277,7 +277,9 @@ // break; case 15: *(uint16_t *)(vram + bpp*pos) = ((db&0xf8)>>3) | ((dg&0xf8)<<2) | ((dr&0xf8)<<7); - break; + break; + default: + break; } } @@ -428,7 +430,7 @@ uint32_t x; register uint8_t tempB; - for (x = 0; x < (p->height) * (p->width) ; x++) { + for (x = 0; x < (unsigned long)(p->height) * (p->width) ; x++) { tempB = (p->pixels[x]).ch.b; (p->pixels[x]).ch.b = (p->pixels[x]).ch.r; (p->pixels[x]).ch.r = tempB; Index: branches/cparm/i386/modules/KernelPatcher/kernel_patcher.h =================================================================== --- branches/cparm/i386/modules/KernelPatcher/kernel_patcher.h (revision 1118) +++ branches/cparm/i386/modules/KernelPatcher/kernel_patcher.h (revision 1119) @@ -12,15 +12,6 @@ #define CPUID_MODEL_ANY 0x00 #define CPUID_MODEL_UNKNOWN 0x01 -#define CPUID_MODEL_YONAH 14 -#define CPUID_MODEL_MEROM 15 -#define CPUID_MODEL_PENRYN 23 -#define CPUID_MODEL_NEHALEM 26 -#define CPUID_MODEL_ATOM 28 -#define CPUID_MODEL_FIELDS 30 /* Lynnfield, Clarksfield, Jasper */ -#define CPUID_MODEL_DALES 31 /* Havendale, Auburndale */ -#define CPUID_MODEL_NEHALEM_EX 46 - #define KERNEL_ANY 0x00 #define KERNEL_64 0x01 #define KERNEL_32 0x02 Index: branches/cparm/i386/modules/KernelPatcher/Makefile =================================================================== --- branches/cparm/i386/modules/KernelPatcher/Makefile (revision 1118) +++ branches/cparm/i386/modules/KernelPatcher/Makefile (revision 1119) @@ -69,6 +69,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/*.o \ -weak_library $(SYMROOT)/Symbols.dylib \ -o $(SYMROOT)/$(MODULE_NAME).dylib Index: branches/cparm/i386/modules/Networking/Networking.c =================================================================== --- branches/cparm/i386/modules/Networking/Networking.c (revision 1118) +++ branches/cparm/i386/modules/Networking/Networking.c (revision 1119) @@ -19,8 +19,9 @@ #else #define DBG(x...) #endif - +#define kEnableWifi "EnableWifi" #define kEthernetBuiltIn "EthernetBuiltIn" +#define kEnableNetworking "EnableNetworkModule" void set_eth_builtin(pci_dt_t *eth_dev); void set_wifi_airport(pci_dt_t *wlan_dev); @@ -48,6 +49,10 @@ else if(current->class_id == PCI_CLASS_NETWORK_OTHER) { // WIFI + bool do_wifi_devprop = true; + getBoolForKey(kEnableWifi, &do_wifi_devprop, &bootInfo->bootConfig); + + if (do_wifi_devprop) set_wifi_airport(current); } @@ -56,7 +61,12 @@ void Networking_start() { - register_hook_callback("PCIDevice", &Networking_hook); + bool enable = true; + getBoolForKey(kEnableNetworking, &enable, &bootInfo->bootConfig) ; + + if (enable) { + register_hook_callback("PCIDevice", &Networking_hook); + } } /* a fine place for this code */ @@ -148,7 +158,7 @@ devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1); - int i = 0; + unsigned int i = 0; for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++) { if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id && Index: branches/cparm/i386/modules/Networking/Makefile =================================================================== --- branches/cparm/i386/modules/Networking/Makefile (revision 1118) +++ branches/cparm/i386/modules/Networking/Makefile (revision 1119) @@ -28,7 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common DEFINES= CONFIG = hd Index: branches/cparm/i386/modules/ACPIMini/aml_generator.c =================================================================== --- branches/cparm/i386/modules/ACPIMini/aml_generator.c (revision 0) +++ branches/cparm/i386/modules/ACPIMini/aml_generator.c (revision 1119) @@ -0,0 +1,562 @@ +/* + * aml_generator.c + * Chameleon + * + * Created by Mozodojo on 20/07/10. + * Copyright 2010 mozo. All rights reserved. + * + */ + +#include "aml_generator.h" + +bool aml_add_to_parent(struct aml_chunk* parent, struct aml_chunk* node) +{ + if (parent && node) + { + switch (parent->Type) + { + case AML_CHUNK_NONE: + case AML_CHUNK_BYTE: + case AML_CHUNK_WORD: + case AML_CHUNK_DWORD: + case AML_CHUNK_QWORD: + case AML_CHUNK_ALIAS: + verbose("aml_add_to_parent: Node isn't supports child nodes!\n"); + return false; + case AML_CHUNK_NAME: + if (parent->First) + { + verbose("aml_add_to_parent: Name node could have only one child node!\n"); + return false; + } + break; + + default: + break; + } + + if (!parent->First) + parent->First = node; + + if (parent->Last) + parent->Last->Next = node; + + parent->Last = node; + + return true; + } + + return false; +} + +struct aml_chunk* aml_create_node(struct aml_chunk* parent) +{ + struct aml_chunk* node = (struct aml_chunk*)malloc(sizeof(struct aml_chunk)); + + aml_add_to_parent(parent, node); + + return node; +} + +void aml_destroy_node(struct aml_chunk* node) +{ + // Delete child nodes + struct aml_chunk* child = node->First; + + while (child) + { + struct aml_chunk* next = child->Next; + + if (child->Buffer) + free(child->Buffer); + + free(child); + + child = next; + } + + // Free node + if (node->Buffer) + free(node->Buffer); + + free(node); +} + +struct aml_chunk* aml_add_buffer(struct aml_chunk* parent, const char* buffer, unsigned int size) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_NONE; + node->Length = size; + node->Buffer = malloc(node->Length); + memcpy(node->Buffer, buffer, node->Length); + } + + return node; +} + +struct aml_chunk* aml_add_byte(struct aml_chunk* parent, unsigned char value) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_BYTE; + + node->Length = 1; + node->Buffer = malloc(node->Length); + node->Buffer[0] = value; + } + + return node; +} + +struct aml_chunk* aml_add_word(struct aml_chunk* parent, unsigned int value) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_WORD; + node->Length = 2; + node->Buffer = malloc(node->Length); + node->Buffer[0] = value & 0xff; + node->Buffer[1] = value >> 8; + } + + return node; +} + +struct aml_chunk* aml_add_dword(struct aml_chunk* parent, unsigned long value) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_DWORD; + node->Length = 4; + node->Buffer = malloc(node->Length); + node->Buffer[0] = value & 0xff; + node->Buffer[1] = (value >> 8) & 0xff; + node->Buffer[2] = (value >> 16) & 0xff; + node->Buffer[3] = (value >> 24) & 0xff; + } + + return node; +} + +struct aml_chunk* aml_add_qword(struct aml_chunk* parent, unsigned long long value) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_QWORD; + node->Length = 8; + node->Buffer = malloc(node->Length); + node->Buffer[0] = value & 0xff; + node->Buffer[1] = (value >> 8) & 0xff; + node->Buffer[2] = (value >> 16) & 0xff; + node->Buffer[3] = (value >> 24) & 0xff; + node->Buffer[4] = (value >> 32) & 0xff; + node->Buffer[5] = (value >> 40) & 0xff; + node->Buffer[6] = (value >> 48) & 0xff; + node->Buffer[7] = (value >> 56) & 0xff; + } + + return node; +} + +unsigned int aml_fill_simple_name(char* buffer, const char* name) +{ + if (strlen(name) < 4) + { + verbose("aml_fill_simple_name: simple name %s has incorrect lengh! Must be 4\n", name); + return 0; + } + + memcpy(buffer, name, 4); + return 4; +} + +unsigned int aml_fill_name(struct aml_chunk* node, const char* name) +{ + if (!node) + return 0; + + int len = strlen(name), offset = 0, count = len / 4; + + if ((len % 4) > 1 || count == 0) + { + verbose("aml_fill_name: pathname %s has incorrect length! Must be 4, 8, 12, 16 etc.\n", name); + return 0; + } + + unsigned int root = 0; + + if ((len % 4) == 1 && name[0] == '\\') + root++; + + if (count == 1) + { + node->Length = 4 + root; + node->Buffer = malloc(node->Length); + memcpy(node->Buffer, name, 4 + root); + return node->Length; + } + + if (count == 2) + { + node->Length = 2 + 8; + node->Buffer = malloc(node->Length); + node->Buffer[offset++] = 0x5c; // Root Char + node->Buffer[offset++] = 0x2e; // Double name + memcpy(node->Buffer+offset, name + root, 8); + return node->Length; + } + + node->Length = 3 + count*4; + node->Buffer = malloc(node->Length); + node->Buffer[offset++] = 0x5c; // Root Char + node->Buffer[offset++] = 0x2f; // Multi name + node->Buffer[offset++] = count; // Names count + memcpy(node->Buffer+offset, name + root, count*4); + + return node->Length; +} + +struct aml_chunk* aml_add_scope(struct aml_chunk* parent, const char* name) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_SCOPE; + + aml_fill_name(node, name); + } + + return node; +} + +struct aml_chunk* aml_add_name(struct aml_chunk* parent, const char* name) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_NAME; + + aml_fill_name(node, name); + } + + return node; +} + +struct aml_chunk* aml_add_package(struct aml_chunk* parent) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_PACKAGE; + + node->Length = 1; + node->Buffer = malloc(node->Length); + } + + return node; +} + +struct aml_chunk* aml_add_package_with_value(struct aml_chunk* parent, uint64_t *lst, int num) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_PACKAGE; + node->Length = 1; + node->Buffer = malloc(node->Length); + aml_add_multiple_value(node,lst,num); + + } + + return node; +} + +void aml_add_value(struct aml_chunk* parent, uint64_t val) +{ + if (parent) + { + if (val > 0xffffffff) + aml_add_qword(parent,val); + else if (val > 0xffff) + aml_add_dword(parent,val); + else if (val > 0xff) + aml_add_word(parent,val); + else + aml_add_byte(parent, val); + } + +} + +void aml_add_multiple_value(struct aml_chunk* parent, uint64_t *lst, int num) +{ + if (parent) + { + int i; + for (i=0; i<(num / 8); i++) { + + aml_add_value(parent, lst[i]); + } + } + +} + +struct aml_chunk* aml_add_alias(struct aml_chunk* parent, const char* name1, const char* name2) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_ALIAS; + + node->Length = 8; + node->Buffer = malloc(node->Length); + aml_fill_simple_name(node->Buffer, name1); + aml_fill_simple_name(node->Buffer+4, name2); + } + + return node; +} + +unsigned char aml_get_size_length(unsigned int size) +{ + if (size + 1 <= 0x3f) + return 1; + else if (size + 2 <= 0x3fff) + return 2; + else if (size + 3 <= 0x3fffff) + return 3; + + return 4; +} + +unsigned int aml_calculate_size(struct aml_chunk* node) +{ + if (node) + { + node->Size = 0; + + // Calculate child nodes size + struct aml_chunk* child = node->First; + unsigned char child_count = 0; + + while (child) + { + child_count++; + + node->Size += aml_calculate_size(child); + + child = child->Next; + } + + switch (node->Type) + { + case AML_CHUNK_NONE: + node->Size += node->Length; + break; + case AML_CHUNK_SCOPE: + node->Size += 1 + node->Length; + node->Size += aml_get_size_length(node->Size); + break; + case AML_CHUNK_PACKAGE: + node->Buffer[0] = child_count; + node->Size += 1 + node->Length; + node->Size += aml_get_size_length(node->Size); + break; + + case AML_CHUNK_BYTE: + if (node->Buffer[0] == 0x0 || node->Buffer[0] == 0x1) + { + node->Size += node->Length; + } + else + { + node->Size += 1 + node->Length; + } + + break; + + case AML_CHUNK_WORD: + case AML_CHUNK_DWORD: + case AML_CHUNK_QWORD: + case AML_CHUNK_ALIAS: + case AML_CHUNK_NAME: + node->Size += 1 + node->Length; + break; + } + + return node->Size; + } + + return 0; +} + +unsigned int aml_write_byte(unsigned char value, char* buffer, unsigned int offset) +{ + buffer[offset++] = value; + + return offset; +} + +unsigned int aml_write_word(unsigned int value, char* buffer, unsigned int offset) +{ + buffer[offset++] = value & 0xff; + buffer[offset++] = value >> 8; + + return offset; +} + +unsigned int aml_write_dword(unsigned long value, char* buffer, unsigned int offset) +{ + buffer[offset++] = value & 0xff; + buffer[offset++] = (value >> 8) & 0xff; + buffer[offset++] = (value >> 16) & 0xff; + buffer[offset++] = (value >> 24) & 0xff; + + return offset; +} + +unsigned int aml_write_qword(unsigned long long value, char* buffer, unsigned int offset) +{ + buffer[offset++] = value & 0xff; + buffer[offset++] = (value >> 8) & 0xff; + buffer[offset++] = (value >> 16) & 0xff; + buffer[offset++] = (value >> 24) & 0xff; + buffer[offset++] = (value >> 32) & 0xff; + buffer[offset++] = (value >> 40) & 0xff; + buffer[offset++] = (value >> 48) & 0xff; + buffer[offset++] = (value >> 56) & 0xff; + + return offset; +} + +unsigned int aml_write_buffer(const char* value, unsigned int size, char* buffer, unsigned int offset) +{ + if (size > 0) + { + memcpy(buffer + offset, value, size); + } + + return offset + size; +} + +void aml_add_ressource_t_fxhw(struct aml_chunk* parent, uint64_t *lst) +{ + if (parent) { + char resource_template[] = + { + 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, + 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x79, 0x00 + }; + + char *buffer = resource_template; + unsigned int offset = aml_write_byte(lst[0], buffer, 8); + offset = aml_write_byte(lst[1], buffer, offset); + offset = aml_write_byte(lst[2], buffer, offset); + aml_write_qword(lst[3], buffer, offset); + aml_add_buffer(parent, buffer, sizeof(resource_template)); + } +} + +unsigned int aml_write_size(unsigned int size, char* buffer, unsigned int offset) +{ + if (size <= 0x3f) + { + buffer[offset++] = size; + } + else if (size <= 0x3fff) + { + buffer[offset++] = 0x40 | (size & 0xf); + buffer[offset++] = (size >> 4) & 0xff; + } + else if (size <= 0x3fffff) + { + buffer[offset++] = 0x80 | (size & 0xf); + buffer[offset++] = (size >> 4) & 0xff; + buffer[offset++] = (size >> 12) & 0xff; + } + else + { + buffer[offset++] = 0xc0 | (size & 0xf); + buffer[offset++] = (size >> 4) & 0xff; + buffer[offset++] = (size >> 12) & 0xff; + buffer[offset++] = (size >> 20) & 0xff; + } + + return offset; +} + +unsigned int aml_write_node(struct aml_chunk* node, char* buffer, unsigned int offset) +{ + if (node && buffer) + { + unsigned int old = offset; + + switch (node->Type) + { + case AML_CHUNK_NONE: + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + break; + + case AML_CHUNK_SCOPE: + case AML_CHUNK_PACKAGE: + offset = aml_write_byte(node->Type, buffer, offset); + offset = aml_write_size(node->Size-1, buffer, offset); + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + break; + + case AML_CHUNK_BYTE: + if (node->Buffer[0] == 0x0 || node->Buffer[0] == 0x1) + { + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + } + else + { + offset = aml_write_byte(node->Type, buffer, offset); + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + } + break; + + case AML_CHUNK_WORD: + case AML_CHUNK_DWORD: + case AML_CHUNK_QWORD: + case AML_CHUNK_ALIAS: + case AML_CHUNK_NAME: + offset = aml_write_byte(node->Type, buffer, offset); + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + break; + + default: + break; + } + + struct aml_chunk* child = node->First; + + while (child) + { + offset = aml_write_node(child, buffer, offset); + + child = child->Next; + } + + if (offset - old != node->Size) + verbose("Node size incorrect: 0x%x\n", node->Type); + } + + return offset; +} \ No newline at end of file Index: branches/cparm/i386/modules/ACPIMini/acpi_patcher.c =================================================================== --- branches/cparm/i386/modules/ACPIMini/acpi_patcher.c (revision 0) +++ branches/cparm/i386/modules/ACPIMini/acpi_patcher.c (revision 1119) @@ -0,0 +1,2018 @@ +/* + * Copyright 2008 mackerintel + */ + +/* + * Copyright (c) 2010 cparm . All rights reserved. + * + */ + +#include "libsaio.h" +#include "boot.h" +#include "bootstruct.h" +#include "acpi.h" +#include "efi_tables.h" +#include "fake_efi.h" +#include "acpi_patcher.h" +#include "platform.h" +#include "cpu.h" +#include "aml_generator.h" +#include "xml.h" +#include "smp.h" + +uint64_t acpi10_p; +uint64_t acpi20_p; + +#ifndef DEBUG_ACPI +#define DEBUG_ACPI 0 +#endif + +#if DEBUG_ACPI==2 +#define DBG(x...) {printf(x); sleep(1);} +#elif DEBUG_ACPI==1 +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + +extern EFI_STATUS addConfigurationTable(); + +extern EFI_GUID gEfiAcpiTableGuid; +extern EFI_GUID gEfiAcpi20TableGuid; + +#define tableSign(table, sgn) (table[0]==sgn[0] && table[1]==sgn[1] && table[2]==sgn[2] && table[3]==sgn[3]) + +#define CMOS_WRITE_BYTE(x, y) cmos_write_byte(x, y) +#define CMOS_READ_BYTE(x) cmos_read_byte(x) + +#define RSDP_CHECKSUM_LENGTH 20 + +/*- + * FOR biosacpi_search_rsdp AND biosacpi_find_rsdp + * + * Copyright (c) 2001 Michael Smith + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/sys/boot/i386/libi386/biosacpi.c,v 1.7 2003/08/25 23:28:31 obrien Exp $ + * $DragonFly: src/sys/boot/pc32/libi386/biosacpi.c,v 1.5 2007/01/17 17:31:19 y0netan1 Exp $ + */ + +static struct acpi_2_rsdp * +biosacpi_search_rsdp(char *base, int length, int rev) +{ + struct acpi_2_rsdp *rsdp; + int ofs; + + /* search on 16-byte boundaries */ + for (ofs = 0; ofs < length; ofs += 16) { + rsdp = (struct acpi_2_rsdp*)ptov(base + ofs); + + /* compare signature, validate checksum */ + if (!strncmp(rsdp->Signature, ACPI_SIG_RSDP, strlen(ACPI_SIG_RSDP))) { + + uint8_t csum = checksum8(rsdp, RSDP_CHECKSUM_LENGTH); + if(csum == 0) + { + /* Only assume this is a 2.0 or better table if the revision is greater than 0 + * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1 + * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0. + */ + + if((rsdp->Revision > 0) && rev > 0) + { + uint8_t csum2 = checksum8(rsdp, sizeof(struct acpi_2_rsdp)); + if(csum2 == 0) + return(rsdp); + } + + // Only return the table if it is a true version 1.0 table (Revision 0) + if((rsdp->Revision == 0) && rev == 0) + return(rsdp); + } + + } + } + return(NULL); +} + +/* + * Find the RSDP in low memory. See section 5.2.2 of the ACPI spec. + */ +static struct acpi_2_rsdp * +biosacpi_find_rsdp(int rev) +{ + struct acpi_2_rsdp *rsdp; + uint16_t *addr; + + /* EBDA is the 1 KB addressed by the 16 bit pointer at 0x40E. */ + addr = (uint16_t *)ptov(EBDA_SEG_ADDR); + if ((rsdp = biosacpi_search_rsdp((char *)(*addr << 4), EBDA_SEG_LEN, rev)) != NULL) + return (rsdp); + + unsigned mem_lower = ((CMOS_READ_BYTE(CMOS_BASE_MEMORY+1) << 8) + | CMOS_READ_BYTE(CMOS_BASE_MEMORY)) << 10; + + if ((rsdp = biosacpi_search_rsdp((char *)mem_lower, EBDA_SEG_LEN, rev)) != NULL) + return (rsdp); + + + /* Check the upper memory BIOS space, 0xe0000 - 0xfffff. */ + if ((rsdp = biosacpi_search_rsdp((char *)0xe0000, 0x20000, rev)) != NULL) + return (rsdp); + + return (NULL); +} + + + +#define __RES(s, u) \ +inline unsigned u \ +resolve_##s(unsigned u defaultentry, char *str, int base) \ +{ \ +unsigned u entry = defaultentry; \ +if (str && (strcmp(str,"Default") != 0)) { \ +entry = strtoul((const char *)str, NULL,base); \ +} \ +return entry; \ +} + +__RES(pss, long) +__RES(cst, int) + + +static void setchecksum(struct acpi_common_header *header) +{ + header->Checksum = 0; + header->Checksum = 256-checksum8(header, header->Length); +} + +static void setRsdpchecksum(struct acpi_2_rsdp *rsdp) +{ + rsdp->Checksum = 0; + rsdp->Checksum = 256-checksum8(rsdp, 20); +} + +static void setRsdpXchecksum(struct acpi_2_rsdp *rsdp) +{ + rsdp->ExtendedChecksum = 0; + rsdp->ExtendedChecksum = 256-checksum8(rsdp, rsdp->Length); +} + +static struct acpi_2_rsdp * gen_rsdp_v2_from_v1(struct acpi_2_rsdp *rsdp) +{ + struct acpi_2_rsdp * rsdp_conv = (struct acpi_2_rsdp *)AllocateKernelMemory(sizeof(struct acpi_2_rsdp)); + memcpy(rsdp_conv, rsdp, 20); + + /* Add/change fields */ + rsdp_conv->Revision = 2; /* ACPI version 3 */ + rsdp_conv->Length = sizeof(struct acpi_2_rsdp); + + /* Correct checksums */ + setRsdpchecksum(rsdp_conv); + setRsdpXchecksum(rsdp_conv); + + rsdp = rsdp_conv; + + return rsdp_conv; +} + +static struct acpi_2_xsdt * gen_xsdt_from_rsdt(struct acpi_2_rsdt *rsdt) +{ + int i,rsdt_entries_num=(rsdt->Length-sizeof(struct acpi_2_rsdt))/4; + + uint32_t *rsdt_entries=(uint32_t *)(rsdt+1); + + struct acpi_2_xsdt * xsdt_conv=(struct acpi_2_xsdt *)AllocateKernelMemory(sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8)); + memcpy(xsdt_conv, rsdt, sizeof(struct acpi_2_rsdt)); + + xsdt_conv->Signature[0] = 'X'; + xsdt_conv->Signature[1] = 'S'; + xsdt_conv->Signature[2] = 'D'; + xsdt_conv->Signature[3] = 'T'; + xsdt_conv->Length = sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8); + + uint64_t *xsdt_conv_entries=(uint64_t *)(xsdt_conv+1); + + for (i=0;iXsdtAddress = (uint32_t)xsdt; + + setRsdpXchecksum(rsdp); +} + +static void update_rsdp_with_rsdt(struct acpi_2_rsdp *rsdp, struct acpi_2_rsdt *rsdt) +{ + rsdp->RsdtAddress = (uint32_t)rsdt; + + setRsdpchecksum(rsdp); + +} + + +void *loadSSDTTable(int ssdt_number) +{ + int fd = -1; + char dirspec[512]; + char filename[512]; + const char * overriden_pathname=NULL; + int len=0; + + // Check booting partition + + // Rek: if user specified a full path name then take it in consideration + if (getValueForKey(kSSDT, &overriden_pathname, &len, + &bootInfo->bootConfig)) + { + sprintf(filename, "%s-%d.aml", overriden_pathname, ssdt_number); // start searching root + } + else + sprintf(filename, "SSDT-%d.aml", ssdt_number); + + sprintf(dirspec, "/%s", filename); // start searching root + + fd=open (dirspec); + + if (fd<0) + { // Check Extra on booting partition + sprintf(dirspec,"/Extra/%s",filename); + fd=open (dirspec); + if (fd<0) + { // Fall back to booter partition + sprintf(dirspec,"bt(0,0)/Extra/%s",filename); + fd=open (dirspec); + if (fd<0) + { + DBG("SSDT Table not found: %s\n", filename); + return NULL; + } + } + } + + void *tableAddr=(void*)AllocateKernelMemory(file_size (fd)); + if (tableAddr) + { + if (read (fd, tableAddr, file_size (fd))!=file_size (fd)) + { + printf("Couldn't read table %s\n",dirspec); + free (tableAddr); + close (fd); + return NULL; + } + + printf("Valid SSDT Table found: %s\n", filename); + DBG("Table %s read and stored at: %x\n", dirspec, tableAddr); + close (fd); + return tableAddr; + } + + printf("Couldn't allocate memory for table %s\n", dirspec); + close (fd); + + return NULL; +} + +void *loadACPITable(char *key) +{ + int fd = -1; + char dirspec[512]; + char filename[512]; + const char * overriden_pathname=NULL; + int len=0; + + DBG("Searching for %s.aml file ...\n", key); + // Check booting partition + + // Rek: if user specified a full path name then take it in consideration + if (getValueForKey(key, &overriden_pathname, &len, + &bootInfo->bootConfig)) + { + sprintf(filename, "%s", overriden_pathname); + } + else + sprintf(filename, "%s.aml", key); + + + sprintf(dirspec, "/%s", filename); // start searching root + + fd=open (dirspec); + + if (fd<0) + { + // Check Extra on booting partition + sprintf(dirspec,"/Extra/%s",filename); + fd=open (dirspec); + if (fd<0) + { // Fall back to booter partition + sprintf(dirspec,"bt(0,0)/Extra/%s",filename); + fd=open (dirspec); + if (fd<0) + { + DBG("ACPI Table not found: %s\n", key); + return NULL; + } + + } + + } + + void *tableAddr=(void*)AllocateKernelMemory(file_size (fd)); + if (tableAddr) + { + if (read (fd, tableAddr, file_size (fd))!=file_size (fd)) + { + printf("Couldn't read table %s\n",key); + free (tableAddr); + close (fd); + return NULL; + } + verbose("Valid ACPI Table found: %s\n", key); + //DBG("Table %s read and stored at: %x\n", key, tableAddr); + close (fd); + return tableAddr; + } + + printf("Couldn't allocate memory for table %s\n", key); + close (fd); + + return NULL; +} + +uint8_t acpi_cpu_count = 0; +char* acpi_cpu_name[32]; + +void get_acpi_cpu_names(unsigned char* dsdt, uint32_t length) +{ + uint32_t i; + + 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; + verbose("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; + + verbose("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; + } + } + } +} + + +struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt* fadt) +{ + char ssdt_header[] = + { + 0x53, 0x53, 0x44, 0x54, 0xE7, 0x00, 0x00, 0x00, /* SSDT.... */ + 0x01, 0x17, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x41, /* ..PmRefA */ + 0x43, 0x70, 0x75, 0x43, 0x73, 0x74, 0x00, 0x00, /* CpuCst.. */ + 0x00, 0x10, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* ....INTL */ + 0x31, 0x03, 0x10, 0x20 /* 1.._ */ + }; + + char cstate_resource_template[] = + { + 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, + 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; + } + + if (fadt == NULL) { + verbose ("FACP not exists: C-States will not be generated !!!\n"); + return NULL; + } + + struct acpi_2_dsdt* dsdt = (void*)fadt->DSDT; + + if (dsdt == NULL) { + verbose ("DSDT not found: C-States will not be generated !!!\n"); + return NULL; + } + + if (acpi_cpu_count == 0) + get_acpi_cpu_names((void*)dsdt, dsdt->Length); + + if (acpi_cpu_count > 0) + { + bool c2_enabled = fadt->C2_Latency < 100; + bool c3_enabled = fadt->C3_Latency < 1000; + bool c4_enabled = false; + + getBoolForKey(kEnableC4State, &c4_enabled, &bootInfo->bootConfig); + + unsigned char cstates_count = 1 + (c2_enabled ? 1 : 0) + ((c3_enabled || c4_enabled) ? 1 : 0); + char *Lat = NULL, *Pw = NULL, *tmpstr =NULL; + int base = 16; + TagPtr personality = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"C-States")); + + if ((tmpstr = XMLCastString(XMLGetProperty(personality, (const char*)"Base")))) { + + int mybase = strtol(tmpstr, NULL, 10); + + if (mybase == 8 || mybase == 10 || mybase == 16 ) + base = mybase; + } + + 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); + + struct aml_chunk* tmpl = aml_add_package(pack); + TagPtr match_Status = XMLGetProperty(personality, (const char*)"C1"); + if (match_Status) { + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency")); + } + 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, (unsigned char)resolve_cst(0x01, Lat, base)); // Latency + aml_add_word(tmpl, resolve_cst(0x03e8, Pw, base)); // Power + // C2 + if (c2_enabled) + { + tmpl = aml_add_package(pack); + Lat = NULL; + Pw = NULL; + match_Status = XMLGetProperty(personality, (const char*)"C2"); + if (match_Status) { + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency")); + } + + 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_word(tmpl, resolve_cst(fadt->C2_Latency, Lat, base)); // Latency + aml_add_word(tmpl, resolve_cst(0x01f4, Pw, base)); // Power + } + + // C4 + if (c4_enabled) + { + tmpl = aml_add_package(pack); + Lat = NULL; + Pw = NULL; + match_Status = XMLGetProperty(personality, (const char*)"C4"); + if (match_Status) { + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency")); + } + 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, resolve_cst(fadt->C3_Latency / 2, Lat, base)); // TODO: right latency for C4 + aml_add_word(tmpl, resolve_cst(0xfa, Pw, base)); // Power + + } + // C3 + else if (c3_enabled) + { + tmpl = aml_add_package(pack); + Lat = NULL; + Pw = NULL; + match_Status = XMLGetProperty(personality, (const char*)"C3"); + if (match_Status) { + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency")); + } + 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, resolve_cst(fadt->C3_Latency , Lat, base)); + aml_add_word(tmpl, resolve_cst(0x015e, Pw, base)); // 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; + + setchecksum((struct acpi_common_header *)ssdt); + + aml_destroy_node(root); + + verbose ("SSDT with CPU C-States generated successfully\n"); + + return ssdt; + } + else + { + verbose ("ACPI CPUs not found: C-States not generated !!!\n"); + } + + return NULL; +} + +struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt* dsdt) +{ + + char ssdt_header[] = + { + 0x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */ + 0x01, 0x6A, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x00, /* ..PmRef. */ + 0x43, 0x70, 0x75, 0x50, 0x6D, 0x00, 0x00, 0x00, /* CpuPm... */ + 0x00, 0x30, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* .0..INTL */ + 0x31, 0x03, 0x10, 0x20, /* 1.._ */ + }; + + if (Platform->CPU.Vendor != 0x756E6547) { + verbose ("Not an Intel platform: P-States will not be generated !!!\n"); + return NULL; + } + + if (!(Platform->CPU.Features & CPUID_FEATURE_MSR)) { + verbose ("Unsupported CPU: P-States will not be generated !!!\n"); + return NULL; + } + + if (acpi_cpu_count == 0) + get_acpi_cpu_names((void*)dsdt, dsdt->Length); + + if (acpi_cpu_count > 0) + { + struct p_state initial, maximum, minimum, p_states[32]; + uint8_t p_states_count = 0; + + // Retrieving P-States, ported from code by superhai (c) + switch (Platform->CPU.Family) { + case 0x06: + { + switch (Platform->CPU.Model) + { + case CPUID_MODEL_DOTHAN: // ? + case CPUID_MODEL_YONAH: // Yonah + case CPUID_MODEL_MEROM: // Merom + case CPUID_MODEL_PENRYN: // Penryn + case CPUID_MODEL_ATOM: // Intel Atom (45nm) + { + bool cpu_dynamic_fsb = false; + + if (rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 27)) + { + wrmsr64(MSR_IA32_EXT_CONFIG, (rdmsr64(MSR_IA32_EXT_CONFIG) | (1 << 28))); + delay(1); + cpu_dynamic_fsb = rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 28); + } + + bool cpu_noninteger_bus_ratio = (rdmsr64(MSR_IA32_PERF_STATUS) & (1ULL << 46)); + + initial.Control = rdmsr64(MSR_IA32_PERF_STATUS); + + maximum.Control = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 32) & 0x1F3F) | (0x4000 * cpu_noninteger_bus_ratio); + maximum.CID = ((maximum.FID & 0x1F) << 1) | cpu_noninteger_bus_ratio; + + minimum.FID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 24) & 0x1F) | (0x80 * cpu_dynamic_fsb); + minimum.VID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 48) & 0x3F); + + if (minimum.FID == 0) + { + uint64_t msr; + uint8_t i; + // Probe for lowest fid + for (i = maximum.FID; i >= 0x6; i--) + { + msr = rdmsr64(MSR_IA32_PERF_CONTROL); + wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (i << 8) | minimum.VID); + intel_waitforsts(); + minimum.FID = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0x1F; + delay(1); + } + + msr = rdmsr64(MSR_IA32_PERF_CONTROL); + wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID); + intel_waitforsts(); + } + + if (minimum.VID == maximum.VID) + { + uint64_t msr; + uint8_t i; + // Probe for lowest vid + for (i = maximum.VID; i > 0xA; i--) + { + msr = rdmsr64(MSR_IA32_PERF_CONTROL); + wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (minimum.FID << 8) | i); + intel_waitforsts(); + minimum.VID = rdmsr64(MSR_IA32_PERF_STATUS) & 0x3F; + delay(1); + } + + msr = rdmsr64(MSR_IA32_PERF_CONTROL); + wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID); + intel_waitforsts(); + } + + minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb; + + // Sanity check + if (maximum.CID < minimum.CID) + { + DBG("Insane FID values!"); + p_states_count = 0; + } + else + { + // Finalize P-States + // Find how many P-States machine supports + p_states_count = maximum.CID - minimum.CID + 1; + + if (p_states_count > 32) + p_states_count = 32; + + uint8_t vidstep; + uint8_t i = 0, u, invalid = 0; + + vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1); + + for (u = 0; u < p_states_count; u++) + { + i = u - invalid; + + p_states[i].CID = maximum.CID - u; + p_states[i].FID = (p_states[i].CID >> 1); + + 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) + { + 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) + invalid++; + + p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2; + + uint32_t multiplier = p_states[i].FID & 0x1f; // = 0x08 + bool half = p_states[i].FID & 0x40; // = 0x01 + bool dfsb = p_states[i].FID & 0x80; // = 0x00 + uint32_t fsb = Platform->CPU.FSBFrequency / 1000000; // = 400 + uint32_t halffsb = (fsb + 1) >> 1; // = 200 + uint32_t frequency = (multiplier * fsb); // = 3200 + + p_states[i].Frequency = (frequency + (half * halffsb)) >> dfsb; // = 3200 + 200 = 3400 + } + + p_states_count -= invalid; + } + break; + } + case CPUID_MODEL_FIELDS: + case CPUID_MODEL_DALES: + case CPUID_MODEL_DALES_32NM: + case CPUID_MODEL_NEHALEM: + case CPUID_MODEL_NEHALEM_EX: + case CPUID_MODEL_WESTMERE: + case CPUID_MODEL_WESTMERE_EX: + case CPUID_MODEL_SANDYBRIDGE: + case CPUID_MODEL_JAKETOWN: + { + maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff; // Seems it always contains maximum multiplier value (with turbo, that's we need)... + minimum.Control = (rdmsr64(MSR_PLATFORM_INFO) >> 40) & 0xff; + + verbose("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control); + + // Sanity check + if (maximum.Control < minimum.Control) + { + DBG("Insane control values!"); + p_states_count = 0; + } + else + { + uint8_t i; + p_states_count = 0; + + 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; + p_states_count++; + } + } + + break; + } + default: + verbose ("Unsupported CPU: P-States not generated !!!\n"); + break; + } + } + default: + break; + } + + // Generating SSDT + if (p_states_count) + { + 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); + + uint8_t minPSratio = (p_states[p_states_count-1].Frequency / (Platform->CPU.FSBFrequency / 10000000 )); + uint8_t maxPSratio = (p_states[0].Frequency / (Platform->CPU.FSBFrequency / 10000000 )); + + uint8_t cpu_div = Platform->CPU.CurrDiv; + uint8_t cpu_ratio = 0; + + if (cpu_div) + cpu_ratio = (Platform->CPU.CurrCoef * 10) + 5; + else + cpu_ratio = Platform->CPU.CurrCoef * 10; + + + int user_max_ratio = 0; + getIntForKey(kMaxRatio, &user_max_ratio, &bootInfo->bootConfig); + if (user_max_ratio >= minPSratio && maxPSratio >= user_max_ratio) { + + uint8_t maxcurrdiv = 0, maxcurrcoef = (int)(user_max_ratio / 10); + + uint8_t maxdiv = user_max_ratio - (maxcurrcoef * 10); + if (maxdiv > 0) + maxcurrdiv = 1; + + if (maxcurrdiv) + cpu_ratio = (maxcurrcoef * 10) + 5; + else + cpu_ratio = maxcurrcoef * 10; + } + + int user_min_ratio = 0; + getIntForKey(kMinRatio, &user_min_ratio, &bootInfo->bootConfig); + if (user_min_ratio >= minPSratio && cpu_ratio >= user_min_ratio) { + + uint8_t mincurrdiv = 0, mincurrcoef = (int)(user_min_ratio / 10); + + uint8_t mindiv = user_min_ratio - (mincurrcoef * 10); + + if (mindiv > 0) + mincurrdiv = 1; + + if (mincurrdiv) + minPSratio = (mincurrcoef * 10) + 5; + else + minPSratio = mincurrcoef * 10; + + } + + if (maxPSratio >= cpu_ratio && cpu_ratio >= minPSratio) maxPSratio = cpu_ratio; + + TagPtr personality = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"P-States")); + char* MatchStat = 0; + int dropPSS = 0, Pstatus = 0, base = 16; + int expert = 0;/* Default: 0 , mean mixed mode | expert mode : 1 , mean add only p-states found in boot.plist*/ + char *tmpstr = XMLCastString(XMLGetProperty(personality, (const char*)"Mode")); + + if (strcmp(tmpstr,"Expert") == 0) { + p_states_count = (XMLTagCount(personality)) - 1 ; // - 1 = - ("Mode" tag) + expert = 1; + } + + + if ((tmpstr = XMLCastString(XMLGetProperty(personality, (const char*)"Base")))) { + + if (expert) p_states_count--; // -= ("Base" tag) + + int mybase = strtol(tmpstr, NULL, 10); + + if (mybase == 8 || mybase == 10 || mybase == 16 ) + base = mybase; + } + + for (i = 0; i < p_states_count; i++) + { + sprintf(MatchStat, "%d",i); + TagPtr match_Status = XMLGetProperty(personality, (const char*)MatchStat); + + char *Lat1 = NULL, *clk = NULL, *Pw = NULL, *Lat2 = NULL, *Ctrl = NULL ; + + if (match_Status) { + + clk = XMLCastString(XMLGetProperty(match_Status, (const char*)"CoreFreq")); + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat1 = XMLCastString(XMLGetProperty(match_Status, (const char*)"Transition Latency")); + Lat2 = XMLCastString(XMLGetProperty(match_Status, (const char*)"Bus Master Latency")); + Ctrl = XMLCastString(XMLGetProperty(match_Status, (const char*)"Control")); + + + } else if (expert) + continue; + + + unsigned long Frequency = 0x00000000; + + if (!expert) Frequency = p_states[i].Frequency; + + if (clk) + Frequency = strtoul((const char *)clk, NULL,base); + + if (!Frequency || Frequency > p_states[0].Frequency ) continue; + + uint8_t curr_ratio = (Frequency / (Platform->CPU.FSBFrequency / 10000000 )); + + if (curr_ratio > maxPSratio || minPSratio > curr_ratio) + goto dropPstate; + + struct aml_chunk* pstt = aml_add_package(pack); + aml_add_dword(pstt, Frequency); // CoreFreq (in MHz). + aml_add_dword(pstt, resolve_pss(0x00000000, Pw, base)); // Power (in milliWatts) + aml_add_dword(pstt, resolve_pss(0x0000000A, Lat1, base)); // Transition Latency (in microseconds). + aml_add_dword(pstt, resolve_pss(0x0000000A, Lat2, base)); // Bus Master Latency (in microseconds). + unsigned long Control = 0x00000000; + if (!expert) Control = p_states[i].Control; + aml_add_dword(pstt, resolve_pss(Control, Ctrl, base)); // Control + Pstatus++; + aml_add_dword(pstt, Pstatus); // Status + continue; + dropPstate: +#if DEBUG_ACPI + verbose("state with cpu frequency :%d and ratio :%d will be dropped\n",p_states[i].Frequency,curr_ratio); +#endif + dropPSS++; + + + } + + // Add aliaces + 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, "PSS_", "_PSS"); + } + + 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; + + setchecksum((struct acpi_common_header *)ssdt); + + aml_destroy_node(root); + + verbose ("SSDT with CPU P-States generated successfully"); + + if (dropPSS) + verbose(", %d P-state(s) dropped",dropPSS); + + verbose("\n"); + + return ssdt; + } + } + else + { + verbose("ACPI CPUs not found: P-States not generated !!!\n"); + } + + return NULL; +} + + +struct acpi_2_gas FillGASStruct(uint32_t Address, uint8_t Length) +{ + struct acpi_2_gas TmpGAS; + + TmpGAS.Address_Space_ID = 1; /* I/O Address */ + + if (Address == 0) + { + TmpGAS.Register_Bit_Width = 0; + } else { + TmpGAS.Register_Bit_Width = Length * 8; + } + + TmpGAS.Register_Bit_Offset = 0; + TmpGAS.Access_Size = 0; /* Not set for Legacy reasons... */ + TmpGAS.Address = (uint64_t)Address; + + return(TmpGAS); +} + +struct acpi_2_fadt * +patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt, bool UpdateFADT) +{ + + struct acpi_2_fadt *fadt_mod; + struct acpi_2_fadt *fadt_file = (struct acpi_2_fadt *)loadACPITable(kFADT); + bool fadt_rev2_needed = false; + bool fix_restart = false; + const char * value; + bool aspmOff = true; + bool msiOff = true; + + // Restart Fix + if (Platform->CPU.Vendor == 0x756E6547) { /* Intel */ + fix_restart = true; + getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig); + + } else { + verbose ("Not an Intel platform: Restart Fix not applied !!!\n"); + } + + if (fix_restart) + fadt_rev2_needed = true; + + // Allocate new fadt table + if ((UpdateFADT) && (((fadt_file) && (fadt_file->Length < sizeof(struct acpi_2_fadt))) || + ((!fadt_file) && (fadt->Length < sizeof(struct acpi_2_fadt))))) + { + getBoolForKey(kDisableMSI, &msiOff, &bootInfo->bootConfig) ; + getBoolForKey(kDisableASPM, &aspmOff, &bootInfo->bootConfig); + + if (fadt_file) + { + if (fadt_file->Length < 0xF4) + { + fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0xF4); + memcpy(fadt_mod, fadt_file, fadt_file->Length); + fadt_mod->Length = 0xF4; + } + else + { + + fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt_file->Length); + memcpy(fadt_mod, fadt_file, fadt_file->Length); + } + } + else + { + if (fadt->Length < 0xF4) + { + fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0xF4); + memcpy(fadt_mod, fadt, fadt->Length); + fadt_mod->Length = 0xF4; + } + else + { + + fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length); + memcpy(fadt_mod, fadt, fadt->Length); + } + } + + fadt_mod->Revision = 0x04; // FADT rev 4 + fadt_mod->RESET_REG = FillGASStruct(0, 0); + fadt_mod->Reset_Value = 0; + fadt_mod->Reserved[0] = 0; + fadt_mod->Reserved[1] = 0; + fadt_mod->Reserved[2] = 0; + + fadt_mod->X_PM1a_EVT_BLK = FillGASStruct(fadt_mod->PM1A_Event_Block_Address, fadt_mod->PM1_Event_Block_Length); + fadt_mod->X_PM1b_EVT_BLK = FillGASStruct(fadt_mod->PM1B_Event_Block_Address, fadt_mod->PM1_Event_Block_Length); + fadt_mod->X_PM1a_CNT_BLK = FillGASStruct(fadt_mod->PM1A_Control_Block_Address, fadt_mod->PM1_Control_Block_Length); + fadt_mod->X_PM1b_CNT_BLK = FillGASStruct(fadt_mod->PM1B_Control_Block_Address, fadt_mod->PM1_Control_Block_Length); + fadt_mod->X_PM2_CNT_BLK = FillGASStruct(fadt_mod->PM2_Control_Block_Address, fadt_mod->PM2_Control_Block_Length); + fadt_mod->X_PM_TMR_BLK = FillGASStruct(fadt_mod->PM_Timer_Block_Address, fadt_mod->PM_Timer_Block_Length); + fadt_mod->X_GPE0_BLK = FillGASStruct(fadt_mod->GPE0_Block_Address, fadt_mod->GPE0_Block_Length); + fadt_mod->X_GPE1_BLK = FillGASStruct(fadt_mod->GPE1_Block_Address, fadt_mod->GPE1_Block_Length); + + verbose("Converted ACPI V%d FADT to ACPI V4 FADT\n", (fadt) ? fadt->Revision : fadt->Revision); + } else { + + if (fadt_file) { + if (fadt_file->Length < 0x84 && fadt_rev2_needed) + { + fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84); + memcpy(fadt_mod, fadt_file, fadt_file->Length); + fadt_mod->Length = 0x84; + fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions) + } else { + fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt_file->Length); + memcpy(fadt_mod, fadt_file, fadt_file->Length); + } + + } else { + 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) + } else { + fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length); + memcpy(fadt_mod, fadt, fadt->Length); + } + + } + + } + + uint8_t Type = PMProfileError; + // Determine system type / PM_Model + + // Fix System-type if needed (should never happen) + if (Platform->Type > MaxSupportedPMProfile) + { + if(fadt_mod->PM_Profile <= MaxSupportedPMProfile) + Platform->Type = fadt_mod->PM_Profile; // get the fadt if correct + else + Platform->Type = 1; /* Set a fixed value (Desktop) */ + } + + // If needed, set System-type from PM_Profile (if valid) else set PM_Profile with a fixed the System-type + // Give prior to the FADT pm profile, allow to also control this value with a patched FADT table + if (fadt_mod->PM_Profile != Platform->Type) + { + bool val = false; + getBoolForKey("PreferInternalProfileDetect", &val, &bootInfo->bootConfig); // if true Give prior to the profile resolved trought the CPU model + + val = Platform->CPU.isServer ; + + if (fadt_mod->PM_Profile <= MaxSupportedPMProfile && !val) { + Platform->Type = fadt_mod->PM_Profile; + } else { + fadt_mod->PM_Profile = Platform->Type; + } + + } + + // Set PM_Profile and System-type if user wanted this value to be forced + if ( (value=getStringForKey("SystemType", &bootInfo->bootConfig))!=NULL) { + if ((Type = (unsigned char) strtoul(value, NULL, 10) ) <= MaxSupportedPMProfile) + { + verbose("FADT: changing Preferred_PM_Profile from 0x%02x to 0x%02x\n", fadt->PM_Profile, Type); + fadt_mod->PM_Profile = Platform->Type = Type; + } else verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform->Type); + } + + // Patch FADT to fix restart + if (fix_restart) + { + fadt_mod->Flags|= 0x400; + + fadt_mod->RESET_REG = FillGASStruct(0x0cf9, 1); + fadt_mod->Reset_Value = 0x06; + verbose("FADT: Restart Fix applied !\n"); + } + + + if (aspmOff) { + fadt_mod->Boot_Flags |= 1 << 4; + } else { + fadt_mod->Boot_Flags &= 0xFFEF; + + } + + if (msiOff) { + fadt_mod->Boot_Flags |= 1 << 3; + } else { + fadt_mod->Boot_Flags &= 0xFFF7; + } + + fadt_mod->FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL; + if ((uint32_t)(&(fadt_mod->X_FIRMWARE_CTRL))-(uint32_t)fadt_mod+8<=fadt_mod->Length) + fadt_mod->X_FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL; + + Platform->hardware_signature = ((struct acpi_2_facs *)fadt->FIRMWARE_CTRL)->hardware_signature; + + DBG("setting hardware_signature to %x \n",Platform->hardware_signature); + + + + // Patch DSDT Address if we have loaded a DSDT table + if(new_dsdt) + { + + fadt_mod->DSDT=(uint32_t)new_dsdt; + if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length) + fadt_mod->X_DSDT=(uint32_t)new_dsdt; + + } + + // Correct the checksum + setchecksum((struct acpi_common_header *)fadt_mod); + + return fadt_mod; +} + + +/* Setup ACPI */ +EFI_STATUS setupAcpi(void) +{ + int version; + EFI_STATUS Status = EFI_ABORTED; + void *new_dsdt=NULL, *new_hpet=NULL, *new_sbst=NULL, *new_ecdt=NULL, *new_asft=NULL, *new_dmar=NULL, *new_apic=NULL, *new_mcfg=NULL, *new_ssdts[14]; + + struct acpi_2_ssdt *new_ssdt[17]; // 15 + 2 additional tables for pss & cst + struct acpi_2_fadt *fadt; // will be used in CST generator + struct acpi_2_fadt *fadt_mod=NULL; + bool oem_dsdt=false, oem_ssdt=false, oem_hpet=false, oem_sbst=false, oem_ecdt=false, oem_asft=false, oem_dmar=false, oem_apic=false, oem_mcfg=false; + bool update_acpi=false, gen_xsdt=false; + bool hpet_replaced=false, sbst_replaced=false, ecdt_replaced=false, asft_replaced=false, dmar_replaced=false, apic_replaced=false, mcfg_replaced=false; + bool hpet_added=false, sbst_added=false, ecdt_added=false, asft_added=false, dmar_added=false, apic_added=false, mcfg_added=false; + bool gen_csta=false, gen_psta=false, speed_step=false; + + bool quick_ssdt= false; + // Quick ssdt search, + // first try to find ssdt-0.aml, if the file do not exist we + // stop searching here, else ssdt-0.aml is loaded and we try + // to find ssdt-1.aml, etc ......... + + int curssdt=0, loadtotssdt=0, totssdt=0, newtotssdt=0; + + { + bool tmpval; + + oem_dsdt=getBoolForKey(kOEMDSDT, &tmpval, &bootInfo->bootConfig)&&tmpval; + oem_ssdt=getBoolForKey(kOEMSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval; + oem_hpet=getBoolForKey(kOEMHPET, &tmpval, &bootInfo->bootConfig)&&tmpval; + oem_sbst=getBoolForKey(kOEMSBST, &tmpval, &bootInfo->bootConfig)&&tmpval; + oem_ecdt=getBoolForKey(kOEMECDT, &tmpval, &bootInfo->bootConfig)&&tmpval; + oem_asft=getBoolForKey(kOEMASFT, &tmpval, &bootInfo->bootConfig)&&tmpval; + oem_dmar=getBoolForKey(kOEMDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval; + oem_apic=getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->bootConfig)&&tmpval; + oem_mcfg=getBoolForKey(kOEMMCFG, &tmpval, &bootInfo->bootConfig)&&tmpval; + + gen_csta=getBoolForKey(kGenerateCStates, &tmpval, &bootInfo->bootConfig)&&tmpval; + gen_psta=getBoolForKey(kGeneratePStates, &tmpval, &bootInfo->bootConfig)&&tmpval; + + update_acpi=getBoolForKey(kUpdateACPI, &tmpval, &bootInfo->bootConfig)&&tmpval; + + quick_ssdt=getBoolForKey(kQSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval; + + speed_step=getBoolForKey(kSpeedstep, &tmpval, &bootInfo->bootConfig)&&tmpval; + + } + + if (speed_step) { + gen_psta= true; + gen_csta= true; + } + + + // Load replacement ACPI tables + if (!oem_dsdt) + new_dsdt=loadACPITable(kDSDT); + + + if (!oem_hpet) + new_hpet=loadACPITable(kHPET); + + + if (!oem_sbst) + new_sbst=loadACPITable(kSBST); + + + if (!oem_ecdt) + new_ecdt=loadACPITable(kECDT); + + + if (!oem_asft) + new_asft=loadACPITable(kASFT); + + + if (!oem_dmar) + new_dmar=loadACPITable(kDMAR); + + + if (!oem_apic) + new_apic=loadACPITable(kAPIC); + + + if (!oem_mcfg) + new_mcfg=loadACPITable(kMCFG); + + if (!oem_ssdt) + { + + for (curssdt=0;curssdt<15;curssdt++) + { + new_ssdt[curssdt]=loadSSDTTable(curssdt); + + if (new_ssdt[curssdt]) + loadtotssdt++; + else if (quick_ssdt) + break; + + } + + curssdt=0; + + } + + DBG("New ACPI tables Loaded in memory\n"); + TagPtr DropTables_p = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"ACPIDropTables")); + // Do the same procedure for both versions of ACPI + for (version=0; version<2; version++) { + struct acpi_2_rsdp *rsdp_mod, *rsdp_conv=(struct acpi_2_rsdp *)0; + struct acpi_2_rsdt *rsdt, *rsdt_mod; + struct acpi_2_xsdt *xsdt_conv = (struct acpi_2_xsdt *)0; + int rsdplength; + + // Find original rsdp + struct acpi_2_rsdp *rsdp=(struct acpi_2_rsdp *)(version?biosacpi_find_rsdp(2):biosacpi_find_rsdp(0)); + + if ((update_acpi) && (rsdp->Revision == 0)) + { + + rsdp_conv = gen_rsdp_v2_from_v1(rsdp); + gen_xsdt = true; + version = 1; + + addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI"); + + verbose("Converted ACPI RSD PTR version 1 to version 3\n"); + } + + if (!rsdp) + { + DBG("No ACPI version %d found. Ignoring\n", version+1); + if (version) + addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20"); + else + addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI"); + continue; + } + rsdplength=version?rsdp->Length:20; + + DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength); + + /* FIXME: no check that memory allocation succeeded + * Copy and patch RSDP,RSDT, XSDT and FADT + * For more info see ACPI Specification pages 110 and following + */ + + if (gen_xsdt) + { + rsdp_mod=rsdp_conv; + } else { + rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength); + memcpy(rsdp_mod, rsdp, rsdplength); + } + + rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress); + + DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length); + + if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000) + { + int dropoffset=0, i; + + rsdt_mod=(struct acpi_2_rsdt *)AllocateKernelMemory(rsdt->Length); + memcpy (rsdt_mod, rsdt, rsdt->Length); + + update_rsdp_with_rsdt(rsdp_mod, rsdt_mod); + + int rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4; + uint32_t *rsdt_entries=(uint32_t *)(rsdt_mod+1); + + if (gen_xsdt) + { + + xsdt_conv=gen_xsdt_from_rsdt(rsdt_mod); + update_rsdp_with_xsdt(rsdp, xsdt_conv); + + + verbose("Converted RSDT table to XSDT table\n"); + } + + for (i=0;iLength); + + if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000) + { + printf("FADT incorrect. Not modified\n"); + continue; + } + verbose("Attempting to patch FADT entry of RSDT\n"); + fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi); + + rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod; + + if (!oem_ssdt) + { + // Generate _CST SSDT + if ( gen_csta && (new_ssdt[loadtotssdt] = generate_cst_ssdt(fadt_mod))) + { + gen_csta= false; + loadtotssdt++; + } + + // Generating _PSS SSDT + if (gen_psta && (new_ssdt[loadtotssdt] = generate_pss_ssdt((void*)fadt_mod->DSDT))) + { + gen_psta= false; + loadtotssdt++; + } + + } + + continue; + } + } + DBG("\n"); + + if ((!oem_hpet) && (!hpet_replaced)) + { + if (new_hpet) + { + rsdt_entries[i-dropoffset]=(uint32_t)new_hpet; + hpet_added=true; + i++; + } + } + + if ((!oem_sbst) && (!sbst_replaced)) + { + if (new_sbst) + { + rsdt_entries[i-dropoffset]=(uint32_t)new_sbst; + sbst_added=true; + i++; + } + } + + if ((!oem_ecdt) && (!ecdt_replaced)) + { + if (new_ecdt) + { + rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt; + ecdt_added=true; + i++; + } + } + + if ((!oem_asft) && (!asft_replaced)) + { + if (new_asft) + { + rsdt_entries[i-dropoffset]=(uint32_t)new_asft; + asft_added=true; + i++; + } + } + + if ((!oem_dmar) && (!dmar_replaced)) + { + if (new_dmar) + { + rsdt_entries[i-dropoffset]=(uint32_t)new_dmar; + dmar_added=true; + i++; + } + } + + if ((!oem_apic) && (!apic_replaced)) + { + if (new_apic) + { + rsdt_entries[i-dropoffset]=(uint32_t)new_apic; + apic_added=true; + i++; + } + } + + if ((!oem_mcfg) && (!mcfg_replaced)) + { + if (new_mcfg) + { + rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg; + mcfg_added=true; + i++; + } + } + + if (!oem_ssdt) + { + while ((totssdt < loadtotssdt) && (curssdt < 17)) + { + if (new_ssdt[curssdt]) + { + DBG("adding SSDT %d\n", curssdt); + rsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt]; + totssdt++; + newtotssdt++; + i++; + } else if (quick_ssdt) { + break; + } + + curssdt++; + } + } + + // Correct the checksum of RSDT + rsdt_mod->Length-=4*dropoffset; + rsdt_mod->Length+=4*newtotssdt; + if (hpet_added) + rsdt_mod->Length+=4; + if (sbst_added) + rsdt_mod->Length+=4; + if (ecdt_added) + rsdt_mod->Length+=4; + if (asft_added) + rsdt_mod->Length+=4; + if (dmar_added) + rsdt_mod->Length+=4; + if (apic_added) + rsdt_mod->Length+=4; + if (mcfg_added) + rsdt_mod->Length+=4; + + DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum); + + setchecksum((struct acpi_common_header *)rsdt_mod); + + DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod); + + } + else + { + rsdp_mod->RsdtAddress=0; + printf("RSDT not found or RSDT incorrect\n"); + } + + if (version) + { + struct acpi_2_xsdt *xsdt, *xsdt_mod; + + // FIXME: handle 64-bit address correctly + + if (gen_xsdt) + xsdt=xsdt_conv; + else + 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) + { + int dropoffset=0, i; + curssdt=0, totssdt=0, newtotssdt=0; + hpet_replaced=false, hpet_added=false; + sbst_replaced=false, sbst_added=false; + ecdt_replaced=false, ecdt_added=false; + asft_replaced=false, asft_added=false; + dmar_replaced=false, dmar_added=false; + apic_replaced=false, apic_added=false; + mcfg_replaced=false, mcfg_added=false; + + if (gen_xsdt) + xsdt_mod=xsdt; + else + { + xsdt_mod=(struct acpi_2_xsdt*)AllocateKernelMemory(xsdt->Length); + memcpy(xsdt_mod, xsdt, xsdt->Length); + } + + update_rsdp_with_xsdt(rsdp_mod, xsdt_mod); + + int xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8; + uint64_t *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) + { + verbose("FADT incorrect or after 4GB. Dropping XSDT\n"); + goto drop_xsdt; + } + verbose("Attempting to patch FADT entry of XSDT\n"); + fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi); + + + xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod; + + //DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]); + + if (!oem_ssdt) + { + // Generate _CST SSDT + if ( gen_csta && (new_ssdt[loadtotssdt] = generate_cst_ssdt(fadt_mod))) + { + gen_csta= false; + loadtotssdt++; + } + + // Generating _PSS SSDT + if (gen_psta && (new_ssdt[loadtotssdt] = generate_pss_ssdt((void*)fadt_mod->DSDT))) + { + gen_psta= false; + loadtotssdt++; + } + } + + + continue; + } + + //DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]); + + } + + if ((!oem_hpet) && (!hpet_replaced)) + { + if (new_hpet) + { + xsdt_entries[i-dropoffset]=(uint32_t)new_hpet; + hpet_added=true; + i++; + } + } + + if ((!oem_sbst) && (!sbst_replaced)) + { + if (new_sbst) + { + xsdt_entries[i-dropoffset]=(uint32_t)new_sbst; + sbst_added=true; + i++; + } + } + + if ((!oem_ecdt) && (!ecdt_replaced)) + { + if (new_ecdt) + { + + xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt; + ecdt_added=true; + i++; + } + } + + if ((!oem_asft) && (!asft_replaced)) + { + if (new_asft) + { + xsdt_entries[i-dropoffset]=(uint32_t)new_asft; + asft_added=true; + i++; + } + } + + if ((!oem_dmar) && (!dmar_replaced)) + { + if (new_dmar) + { + xsdt_entries[i-dropoffset]=(uint32_t)new_dmar; + dmar_added=true; + i++; + } + } + + if ((!oem_apic) && (!apic_replaced)) + { + if (new_apic) + { + xsdt_entries[i-dropoffset]=(uint32_t)new_apic; + apic_added=true; + i++; + } + } + + if ((!oem_mcfg) && (!mcfg_replaced)) + { + if (new_mcfg) + { + xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg; + mcfg_added=true; + i++; + } + } + + if (!oem_ssdt) + { + while ((totssdt < loadtotssdt) && (curssdt < 17)) + { + if (new_ssdt[curssdt]) + { + DBG("adding SSDT %d\n", curssdt); + xsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt]; + totssdt++; + newtotssdt++; + i++; + } else if (quick_ssdt){ + break; + } + + curssdt++; + } + } + + // Correct the checksum of XSDT + xsdt_mod->Length-=8*dropoffset; + xsdt_mod->Length+=8*newtotssdt; + if (hpet_added) + xsdt_mod->Length+=8; + if (sbst_added) + xsdt_mod->Length+=8; + if (ecdt_added) + xsdt_mod->Length+=8; + if (asft_added) + xsdt_mod->Length+=8; + if (dmar_added) + xsdt_mod->Length+=8; + if (apic_added) + xsdt_mod->Length+=8; + if (mcfg_added) + xsdt_mod->Length+=8; + + setchecksum((struct acpi_common_header *)xsdt_mod); + } + 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"); + } + } + + // Correct the checksum of RSDP + + DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum); + + setRsdpchecksum(rsdp_mod); + + DBG("New checksum %d\n", rsdp_mod->Checksum); + + if (version) + { + DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum); + + setRsdpXchecksum(rsdp_mod); + + DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum); + + } + + verbose("Patched ACPI version %d\n", version+1); + + if (version) + { + /* XXX aserebln why uint32 cast if pointer is uint64 ? */ + acpi20_p = (uint32_t)rsdp_mod; + if (acpi20_p) + Status = addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20"); + } + else + { + /* XXX aserebln why uint32 cast if pointer is uint64 ? */ + acpi10_p = (uint32_t)rsdp_mod; + if (acpi10_p) + Status = addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI"); + } + } + +#if DEBUG_DSDT + printf("Press a key to continue... (DEBUG_DSDT)\n"); + getc(); +#endif + //return (Status == EFI_SUCCESS) ? 1 : 0; + return Status ; +} Index: branches/cparm/i386/modules/ACPIMini/AcpiPatcher.c =================================================================== --- branches/cparm/i386/modules/ACPIMini/AcpiPatcher.c (revision 0) +++ branches/cparm/i386/modules/ACPIMini/AcpiPatcher.c (revision 1119) @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009 Evan Lojewski. All rights reserved. + * + */ + +/* + * Copyright (c) 2010 cparm . All rights reserved. + * + */ + +#include "libsaio.h" +#include "modules.h" +#include "boot.h" +#include "bootstruct.h" +#include "pci_root.h" +#include "acpi_patcher.h" + +#define kEnableAcpi "EnableAcpiModule" + +void AcpiPatcher_setupEfiConfigurationTable_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) +{ + EFI_STATUS *ret = (EFI_STATUS *)arg1; + + // Setup ACPI (mackerintel's patch) + *ret = setupAcpi(); + +} + +void is_ACPI_Patcher_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6){} + +void AcpiPatcher_start() +{ + bool enable = true; + + getBoolForKey(kEnableAcpi, &enable, &bootInfo->bootConfig); + + enable = (execute_hook("isACPIRegistred", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS); + + if (enable) { + register_hook_callback("setupEfiConfigurationTable", &AcpiPatcher_setupEfiConfigurationTable_hook); + register_hook_callback("isACPIRegistred", &is_ACPI_Patcher_Registred_Hook); + + } +} \ No newline at end of file Property changes on: branches/cparm/i386/modules/ACPIMini/AcpiPatcher.c ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/modules/ACPIMini/aml_generator.h =================================================================== --- branches/cparm/i386/modules/ACPIMini/aml_generator.h (revision 0) +++ branches/cparm/i386/modules/ACPIMini/aml_generator.h (revision 1119) @@ -0,0 +1,65 @@ +/* + * aml_generator.h + * Chameleon + * + * Created by Mozodojo on 20/07/10. + * Copyright 2010 mozo. All rights reserved. + * + */ + +#ifndef __LIBSAIO_AML_GENERATOR_H +#define __LIBSAIO_AML_GENERATOR_H + +#include "libsaio.h" + +#define AML_CHUNK_NONE 0xff +#define AML_CHUNK_ZERO 0x00 +#define AML_CHUNK_ONE 0x01 +#define AML_CHUNK_ALIAS 0x06 +#define AML_CHUNK_NAME 0x08 +#define AML_CHUNK_BYTE 0x0A +#define AML_CHUNK_WORD 0x0B +#define AML_CHUNK_DWORD 0x0C +#define AML_CHUNK_STRING 0x0D +#define AML_CHUNK_QWORD 0x0E +#define AML_CHUNK_SCOPE 0x10 +#define AML_CHUNK_PACKAGE 0x12 + +struct aml_chunk +{ + unsigned char Type; + unsigned int Length; + char* Buffer; + + unsigned int Size; + + struct aml_chunk* Next; + struct aml_chunk* First; + struct aml_chunk* Last; +}; + +static inline bool aml_isvalidchar(char c) +{ + return isupper(c) || isdigit(c) || c == '_'; +}; + +bool aml_add_to_parent(struct aml_chunk* parent, struct aml_chunk* node); +struct aml_chunk* aml_create_node(struct aml_chunk* parent); +void aml_destroy_node(struct aml_chunk* node); +struct aml_chunk* aml_add_buffer(struct aml_chunk* parent, const char* buffer, unsigned int size); +struct aml_chunk* aml_add_byte(struct aml_chunk* parent, unsigned char value); +struct aml_chunk* aml_add_word(struct aml_chunk* parent, unsigned int value); +struct aml_chunk* aml_add_dword(struct aml_chunk* parent, unsigned long value); +struct aml_chunk* aml_add_qword(struct aml_chunk* parent, unsigned long long value); +struct aml_chunk* aml_add_scope(struct aml_chunk* parent, const char* name); +struct aml_chunk* aml_add_name(struct aml_chunk* parent, const char* name); +struct aml_chunk* aml_add_package(struct aml_chunk* parent); +struct aml_chunk* aml_add_alias(struct aml_chunk* parent, const char* name1, const char* name2); +unsigned int aml_calculate_size(struct aml_chunk* node); +unsigned int aml_write_node(struct aml_chunk* node, char* buffer, unsigned int offset); +struct aml_chunk* aml_add_package_with_value(struct aml_chunk* parent, uint64_t *lst, int num); +void aml_add_multiple_value(struct aml_chunk* parent, uint64_t *lst, int num); +void aml_add_ressource_t_fxhw(struct aml_chunk* parent, uint64_t *lst); +void aml_add_value(struct aml_chunk* parent, uint64_t val); + +#endif /* !__LIBSAIO_AML_GENERATOR_H */ \ No newline at end of file Index: branches/cparm/i386/modules/ACPIMini/acpi_patcher.h =================================================================== --- branches/cparm/i386/modules/ACPIMini/acpi_patcher.h (revision 0) +++ branches/cparm/i386/modules/ACPIMini/acpi_patcher.h (revision 1119) @@ -0,0 +1,235 @@ +/* + * Copyright 2008 mackerintel + */ + +/* + * Copyright (c) 2010 cparm . All rights reserved. + * + */ + +#ifndef __LIBSAIO_ACPI_PATCHER_H +#define __LIBSAIO_ACPI_PATCHER_H + +#include "libsaio.h" +#include "efi.h" + +#define kDSDT "DSDT" /* acpi_patcher.c */ +#define kRestartFix "RestartFix" /* acpi_patcher.c */ +#define kGeneratePStates "GeneratePStates" /* acpi_patcher.c */ +#define kGenerateCStates "GenerateCStates" /* acpi_patcher.c */ +#define kMaxRatio "MaxBusRatio" /* acpi_patcher.c */ +#define kMinRatio "MinBusRatio" /* acpi_patcher.c */ +#define kQSSDT "quickSSDTsearch" /* acpi_patcher.c */ +#define kSpeedstep "EnableSpeedStep" /* acpi_patcher.c */ +#define kEnableC4State "EnableC4State" /* acpi_patcher.c */ + +#define kFACS "FACS" /* acpi_patcher.c */ +#define kSSDT "SSDT" /* acpi_patcher.c */ +#define kHPET "HPET" /* acpi_patcher.c */ +#define kSBST "SBST" /* acpi_patcher.c */ +#define kECDT "ECDT" /* acpi_patcher.c */ +#define kASFT "ASFT" /* acpi_patcher.c */ +#define kDMAR "DMAR" /* acpi_patcher.c */ +#define kFADT "FADT" /* acpi_patcher.c */ +#define kAPIC "APIC" /* acpi_patcher.c */ +#define kMCFG "MCFG" /* acpi_patcher.c */ +#define kOEMDSDT "oemDSDT" /* acpi_patcher.c */ +#define kOEMSSDT "oemSSDT" /* acpi_patcher.c */ +#define kOEMHPET "oemHPET" /* acpi_patcher.c */ +#define kOEMSBST "oemSBST" /* acpi_patcher.c */ +#define kOEMECDT "oemECDT" /* acpi_patcher.c */ +#define kOEMASFT "oemASFT" /* acpi_patcher.c */ +#define kOEMDMAR "oemDMAR" /* acpi_patcher.c */ +#define kOEMFADT "oemFADT" /* acpi_patcher.c */ +#define kOEMAPIC "oemAPIC" /* acpi_patcher.c */ +#define kOEMMCFG "oemMCFG" /* acpi_patcher.c */ + +#define kUpdateACPI "UpdateACPI" /* acpi_patcher.c */ + +#define kDisableASPM "DisableASPM" /* acpi_patcher.c */ +#define kDisableMSI "DisableMSI" /* acpi_patcher.c */ + +#if UNUSED +#define kGenerateFACS "GenerateFACS" /* acpi_patcher.c */ +#define kOEMFACS "oemFACS" /* acpi_patcher.c */ +#endif + +extern EFI_STATUS setupAcpi(); + +struct p_state +{ + union + { + uint16_t Control; + struct + { + uint8_t VID; // Voltage ID + uint8_t FID; // Frequency ID + }; + }; + + uint8_t CID; // Compare ID + uint32_t Frequency; +}; + +/* + * SIGNATURE_16, SIGNATURE_32, SIGNATURE_64 are extracted from the edk2 project (Base.h), and are under the following license: + * + * Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. + * Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved. + * This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php. + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + */ + +#define SIGNATURE_16(A, B) ((A) | (B << 8)) + +#define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16)) + +#define SIGNATURE_64(A, B, C, D, E, F, G, H) \ +(SIGNATURE_32 (A, B, C, D) | ((uint64_t) (SIGNATURE_32 (E, F, G, H)) << 32)) + +#define ACPI_SIGNATURE_UINT64_LE SIGNATURE_64('R','S','D',' ','P','T','R',' ') + + +/* Per ACPI 3.0a spec */ + +// TODO Migrate +struct acpi_2_rsdp { + char Signature[8]; + uint8_t Checksum; + char OEMID[6]; + uint8_t Revision; + uint32_t RsdtAddress; + uint32_t Length; + uint64_t XsdtAddress; + uint8_t ExtendedChecksum; + char Reserved[3]; +} __attribute__((packed)); + + +#define ACPI_HEADER_CORE \ +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; + +struct acpi_common_header { + ACPI_HEADER_CORE +} __attribute__((packed)); + +// TODO Migrate +struct acpi_2_rsdt { + ACPI_HEADER_CORE +} __attribute__((packed)); + +// TODO Migrate +struct acpi_2_xsdt { + ACPI_HEADER_CORE +} __attribute__((packed)); + +// TODO Migrate +struct acpi_2_gas { + uint8_t Address_Space_ID; + uint8_t Register_Bit_Width; + uint8_t Register_Bit_Offset; + uint8_t Access_Size; + uint64_t Address; +} __attribute__((packed)); + +// TODO Migrate +struct acpi_2_ssdt { + ACPI_HEADER_CORE +} __attribute__((packed)); + +// TODO Migrate +struct acpi_2_dsdt { + ACPI_HEADER_CORE +} __attribute__((packed)); + +// TODO Migrate +struct acpi_2_fadt { + ACPI_HEADER_CORE + uint32_t FIRMWARE_CTRL; + uint32_t DSDT; + uint8_t Model; // JrCs + uint8_t PM_Profile; // JrCs + uint16_t SCI_Interrupt; + uint32_t SMI_Command_Port; + uint8_t ACPI_Enable; + uint8_t ACPI_Disable; + uint8_t S4BIOS_Command; + uint8_t PState_Control; + uint32_t PM1A_Event_Block_Address; + uint32_t PM1B_Event_Block_Address; + uint32_t PM1A_Control_Block_Address; + uint32_t PM1B_Control_Block_Address; + uint32_t PM2_Control_Block_Address; + uint32_t PM_Timer_Block_Address; + uint32_t GPE0_Block_Address; + uint32_t GPE1_Block_Address; + uint8_t PM1_Event_Block_Length; + uint8_t PM1_Control_Block_Length; + uint8_t PM2_Control_Block_Length; + uint8_t PM_Timer_Block_Length; + uint8_t GPE0_Block_Length; + uint8_t GPE1_Block_Length; + uint8_t GPE1_Base_Offset; + uint8_t CST_Support; + uint16_t C2_Latency; + uint16_t C3_Latency; + uint16_t CPU_Cache_Size; + uint16_t Cache_Flush_Stride; + uint8_t Duty_Cycle_Offset; + uint8_t Duty_Cycle_Width; + uint8_t RTC_Day_Alarm_Index; + uint8_t RTC_Month_Alarm_Index; + uint8_t RTC_Century_Index; + uint16_t Boot_Flags; + uint8_t Reserved0; + /* Begin Asere */ + //Reset Fix + uint32_t Flags; + struct acpi_2_gas RESET_REG; + uint8_t Reset_Value; + uint8_t Reserved[3]; + + uint64_t X_FIRMWARE_CTRL; + uint64_t X_DSDT; + +#if UNUSED + /* End Asere */ + /*We absolutely don't care about theese fields*/ + uint8_t notimp2[96]; +#else + struct acpi_2_gas X_PM1a_EVT_BLK; + struct acpi_2_gas X_PM1b_EVT_BLK; + struct acpi_2_gas X_PM1a_CNT_BLK; + struct acpi_2_gas X_PM1b_CNT_BLK; + struct acpi_2_gas X_PM2_CNT_BLK; + struct acpi_2_gas X_PM_TMR_BLK; + struct acpi_2_gas X_GPE0_BLK; + struct acpi_2_gas X_GPE1_BLK; +#endif + +} __attribute__((packed)); + +struct acpi_2_facs { + char Signature[4]; + uint32_t Length; + uint32_t hardware_signature; + uint32_t firmware_waking_vector; + uint32_t global_lock; + uint32_t flags; + uint64_t x_firmware_waking_vector; + uint8_t version; + uint8_t Reserved[3]; + uint32_t ospm_flags; + uint8_t Reserved1[24]; +} __attribute__ ((packed)); + +#endif /* !__LIBSAIO_ACPI_PATCHER_H */ Index: branches/cparm/i386/modules/ACPIMini/Makefile =================================================================== --- branches/cparm/i386/modules/ACPIMini/Makefile (revision 0) +++ branches/cparm/i386/modules/ACPIMini/Makefile (revision 1119) @@ -0,0 +1,91 @@ + +MODULE_NAME = AcpiPatcher +MODULE_VERSION = "1.0.0" +MODULE_COMPAT_VERSION = "1.0.0" +MODULE_START = _$(MODULE_NAME)_start +MODULE_DEPENDENCIES = + +DIR = AcpiPatcher + +include ../../MakePaths.dir + +OBJROOT=../../../obj/i386/modules/$(DIR) +SYMROOT=../../../sym/i386/modules/ +DSTROOT=../../../dst/i386/modules/ + + +UTILDIR = ../../util +LIBSADIR = ../../libsa +LIBSAIODIR = ../../libsaio +BOOT2DIR = ../../boot2 + +INSTALLDIR = $(DSTROOT)/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/standalone + +OPTIM = -Os -Oz +DEBUG = -DNOTHING +CFLAGS = $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost \ + -D__ARCHITECTURE__=\"i386\" -DSAIO_INTERNAL_USER \ + -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ + -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ + -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-mdynamic-no-pic -Wextra -Wpacked -Wpadded -Wunreachable-code -Winline -Wunsafe-loop-optimizations -funsafe-loop-optimizations -Wconversion + +DEFINES= +CONFIG = hd +INC = -I. -I.. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR) -I$(LIBSAIODIR) -I$(BOOT2DIR) +ifneq "" "$(wildcard /bin/mkdirs)" + MKDIRS = /bin/mkdirs +else + MKDIRS = /bin/mkdir -p +endif +AS = as +LD = ld +# LIBS= -lc_static +LIBS= + +VPATH = $(OBJROOT):$(SYMROOT) + +ACPI_PATCHER_OBJS = AcpiPatcher.o aml_generator.o acpi_patcher.o + + +SFILES = +CFILES = +HFILES = +EXPORTED_HFILES = +INSTALLED_HFILES = +OTHERFILES = Makefile +ALLSRC = $(SFILES) $(CFILES) \ + $(HFILES) $(OTHERFILES) +DIRS_NEEDED = $(OBJROOT) $(SYMROOT) + +all embedtheme: ${ACPI_PATCHER_OBJS} dylib + + +dylib: + ld -arch i386 \ + -undefined dynamic_lookup \ + -alias $(MODULE_START) start \ + -dylib -read_only_relocs suppress \ + -S -x -Z -dead_strip_dylibs \ + -no_uuid \ + -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ + -final_output $(MODULE_NAME) \ + $(OBJROOT)/AcpiPatcher.o \ + $(OBJROOT)/aml_generator.o \ + $(OBJROOT)/acpi_patcher.o \ + -o $(SYMROOT)/$(MODULE_NAME).dylib + +AcpiPatcher.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "AcpiPatcher.c" $(INC) -o "$(OBJROOT)/AcpiPatcher.o" + +aml_generator.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "aml_generator.c" $(INC) -o "$(OBJROOT)/aml_generator.o" + +acpi_patcher.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "acpi_patcher.c" $(INC) -o "$(OBJROOT)/acpi_patcher.o" + + +include ../../MakeInc.dir + +# dependencies +-include $(OBJROOT)/Makedep Index: branches/cparm/i386/modules/GraphicsEnabler/gma.c =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/gma.c (revision 1118) +++ branches/cparm/i386/modules/GraphicsEnabler/gma.c (revision 1119) @@ -64,7 +64,9 @@ }; char *get_gma_model(uint32_t id) { - int i=0; + + unsigned int i = 0; + for(i = 0; i < (sizeof(KnownGPUS) / sizeof(KnownGPUS[0])); i++) { if(KnownGPUS[i].device == id) return KnownGPUS[i].name; Index: branches/cparm/i386/modules/GraphicsEnabler/GraphicsEnabler.c =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/GraphicsEnabler.c (revision 1118) +++ branches/cparm/i386/modules/GraphicsEnabler/GraphicsEnabler.c (revision 1119) @@ -14,17 +14,22 @@ #include "modules.h" -#define kGraphicsEnabler "GraphicsEnabler" +#define kGraphicsEnabler "EnableGFXModule" - void GraphicsEnabler_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6); void GraphicsEnabler_start() { - register_hook_callback("PCIDevice", &GraphicsEnabler_hook); + bool enable = true; + getBoolForKey(kGraphicsEnabler, &enable, &bootInfo->bootConfig); + + + if (enable) + { + register_hook_callback("PCIDevice", &GraphicsEnabler_hook); + } } - void GraphicsEnabler_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { pci_dt_t* current = arg1; @@ -32,29 +37,24 @@ { char *devicepath = get_pci_dev_path(current); - bool do_gfx_devprop = true; - getBoolForKey(kGraphicsEnabler, &do_gfx_devprop, &bootInfo->bootConfig); - - - if (do_gfx_devprop) + switch (current->vendor_id) { - switch (current->vendor_id) - { - case PCI_VENDOR_ID_ATI: - verbose("ATI VGA Controller [%04x:%04x] :: %s \n", - current->vendor_id, current->device_id, devicepath); - setup_ati_devprop(current); - break; + case PCI_VENDOR_ID_ATI: + verbose("ATI VGA Controller [%04x:%04x] :: %s \n", + current->vendor_id, current->device_id, devicepath); + setup_ati_devprop(current); + break; + + case PCI_VENDOR_ID_INTEL: + setup_gma_devprop(current); + break; - case PCI_VENDOR_ID_INTEL: - setup_gma_devprop(current); - break; - - case PCI_VENDOR_ID_NVIDIA: - setup_nvidia_devprop(current); - break; - } - } + case PCI_VENDOR_ID_NVIDIA: + setup_nvidia_devprop(current); + break; + default: + break; + } } -} +} \ No newline at end of file Index: branches/cparm/i386/modules/GraphicsEnabler/nvidia.c =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/nvidia.c (revision 1118) +++ branches/cparm/i386/modules/GraphicsEnabler/nvidia.c (revision 1119) @@ -541,6 +541,8 @@ entries[i+1].type = TYPE_GROUPED; } break; + default: + break; } break; @@ -581,7 +583,7 @@ } static char *get_nvidia_model(uint32_t id) { - int i; + unsigned int i; for (i=1; i< (sizeof(NVKnownChipsets) / sizeof(NVKnownChipsets[0])); i++) { if (NVKnownChipsets[i].device == id) { @@ -596,7 +598,7 @@ int fd; int size; - if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { + if ((fd = open_bvdev("bt(0,0)", filename)) < 0) { return 0; } size = file_size(fd); @@ -664,7 +666,11 @@ return 0; } +#if UNUSED unsigned long long mem_detect(volatile uint8_t *regs, uint8_t nvCardType, pci_dt_t *nvda_dev) +#else +unsigned long long mem_detect(volatile uint8_t *regs, uint8_t nvCardType) +#endif { unsigned long long vram_size = 0; @@ -718,7 +724,11 @@ nvCardType = (REG32(0) >> 20) & 0x1ff; // Amount of VRAM in kilobytes +#if UNUSED videoRam = mem_detect(regs, nvCardType, nvda_dev); +#else + videoRam = mem_detect(regs, nvCardType); +#endif model = get_nvidia_model((nvda_dev->vendor_id << 16) | nvda_dev->device_id); verbose("nVidia %s %dMB NV%02x [%04x:%04x] :: %s\n", @@ -871,7 +881,7 @@ devprop_add_value(device, "model", (uint8_t*)model, strlen(model) + 1); devprop_add_value(device, "rom-revision", (uint8_t*)biosVersion, strlen(biosVersion) + 1); if (getBoolForKey(kVBIOS, &doit, &bootInfo->bootConfig) && doit) { - devprop_add_value(device, "vbios", rom, (nvBiosOveride > 0) ? nvBiosOveride : (rom[2] * 512)); + devprop_add_value(device, "vbios", rom, (nvBiosOveride > 0) ? nvBiosOveride : (uint32_t)(rom[2] * 512)); } stringdata = malloc(sizeof(uint8_t) * string->length); Index: branches/cparm/i386/modules/GraphicsEnabler/Makefile =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/Makefile (revision 1118) +++ branches/cparm/i386/modules/GraphicsEnabler/Makefile (revision 1119) @@ -28,7 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-lc_kext -libcc_kext DEFINES= CONFIG = hd @@ -70,6 +70,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/ati.o \ $(OBJROOT)/nvidia.o \ $(OBJROOT)/gma.o \ Index: branches/cparm/i386/modules/GraphicsEnabler/ati.c =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/ati.c (revision 1118) +++ branches/cparm/i386/modules/GraphicsEnabler/ati.c (revision 1119) @@ -39,9 +39,9 @@ #define DBG(x...) #endif -#define MAX_NUM_DCB_ENTRIES 16 +//#define MAX_NUM_DCB_ENTRIES 16 -#define TYPE_GROUPED 0xff +//#define TYPE_GROUPED 0xff const char *ati_compatible_0[] = { "@0,compatible", "ATY,%s" }; const char *ati_compatible_1[] = { "@1,compatible", "ATY,%s" }; @@ -386,7 +386,7 @@ int fd; int size; - if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { + if ((fd = open_bvdev("bt(0,0)", filename)) < 0) { return 0; } size = file_size(fd); @@ -401,7 +401,7 @@ static char *get_ati_model(uint32_t id) { - int i; + unsigned int i; for (i=0; i< (sizeof(ATIKnownChipsets) / sizeof(ATIKnownChipsets[0])); i++) { if (ATIKnownChipsets[i].device == id) { @@ -413,7 +413,7 @@ static char *get_ati_fb(uint32_t id) { - int i; + unsigned int i; for (i=0; i< (sizeof(ATIKnownFramebuffers) / sizeof(ATIKnownFramebuffers[0])); i++) { if (ATIKnownFramebuffers[i].device == id) { @@ -729,7 +729,14 @@ } else { // readAtomBios result in bug on some cards (100% fan speed and black screen), // not using it for posted card, rading from legacy space instead - bios = readAtomBIOS(ati_dev); + + /* + * This code doesn't work on for 5000+ ati cards and need to be skipped for them, otherwise it results in system freeze and fan spinning at 100%. + * All credit goes to Netkas + */ + bios = NULL; + if (ati_dev->device_id > 0x9400) + bios = readAtomBIOS(ati_dev); } } else { bios = rom; //going custom rom way Index: branches/cparm/i386/modules/SMBiosGetters/smbios_getters.h =================================================================== --- branches/cparm/i386/modules/SMBiosGetters/smbios_getters.h (revision 1118) +++ branches/cparm/i386/modules/SMBiosGetters/smbios_getters.h (revision 1119) @@ -1,13 +1,14 @@ + + +#ifndef __LIBSAIO_SMBIOS_GETTERS_H +#define __LIBSAIO_SMBIOS_GETTERS_H + #include "libsaio.h" #include "mysmbios.h" #include "platform.h" #include "pci.h" -#ifndef __LIBSAIO_SMBIOS_GETTERS_H -#define __LIBSAIO_SMBIOS_GETTERS_H - - typedef enum { kSMBString, kSMBByte, Index: branches/cparm/i386/modules/SMBiosGetters/smbios_decode.c =================================================================== --- branches/cparm/i386/modules/SMBiosGetters/smbios_decode.c (revision 1118) +++ branches/cparm/i386/modules/SMBiosGetters/smbios_decode.c (revision 1119) @@ -169,32 +169,63 @@ DBG("\n"); for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));) { +#if DEBUG_SMBIOS DBG("Type: %d, Length: %d, Handle: 0x%x\n", structHeader->type, structHeader->length, structHeader->handle); - +#endif switch (structHeader->type) { case kSMBTypeBIOSInformation: + { +#if !DEBUG_SMBIOS + DBG("Type: %d, Length: %d, Handle: 0x%x\n", + structHeader->type, structHeader->length, structHeader->handle); +#endif decodeBIOSInformation((SMBBIOSInformation *)structHeader); break; - + } case kSMBTypeSystemInformation: + { +#if !DEBUG_SMBIOS + DBG("Type: %d, Length: %d, Handle: 0x%x\n", + structHeader->type, structHeader->length, structHeader->handle); +#endif decodeSystemInformation((SMBSystemInformation *)structHeader); break; - + } case kSMBTypeBaseBoard: + { +#if !DEBUG_SMBIOS + DBG("Type: %d, Length: %d, Handle: 0x%x\n", + structHeader->type, structHeader->length, structHeader->handle); +#endif decodeBaseBoard((SMBBaseBoard *)structHeader); break; - + } case kSMBTypeSystemEnclosure: + { +#if !DEBUG_SMBIOS + DBG("Type: %d, Length: %d, Handle: 0x%x\n", + structHeader->type, structHeader->length, structHeader->handle); +#endif decodeSystemEnclosure((SMBSystemEnclosure *)structHeader); break; - + } case kSMBTypeProcessorInformation: + { +#if !DEBUG_SMBIOS + DBG("Type: %d, Length: %d, Handle: 0x%x\n", + structHeader->type, structHeader->length, structHeader->handle); +#endif decodeProcessorInformation((SMBProcessorInformation *)structHeader); break; - + } case kSMBTypeMemoryDevice: + { +#if !DEBUG_SMBIOS + DBG("Type: %d, Length: %d, Handle: 0x%x\n", + structHeader->type, structHeader->length, structHeader->handle); +#endif decodeMemoryDevice((SMBMemoryDevice *)structHeader); break; @@ -202,16 +233,26 @@ case kSMBTypeFirmwareVolume: case kSMBTypeMemorySPD: break; - + } case kSMBTypeOemProcessorType: + { +#if !DEBUG_SMBIOS + DBG("Type: %d, Length: %d, Handle: 0x%x\n", + structHeader->type, structHeader->length, structHeader->handle); +#endif decodeOemProcessorType((SMBOemProcessorType *)structHeader); break; - + } case kSMBTypeOemProcessorBusSpeed: + { +#if !DEBUG_SMBIOS + DBG("Type: %d, Length: %d, Handle: 0x%x\n", + structHeader->type, structHeader->length, structHeader->handle); +#endif if (((SMBOemProcessorBusSpeed *)structHeader)->ProcessorBusSpeed) decodeOemProcessorBusSpeed((SMBOemProcessorBusSpeed *)structHeader); break; - + } case kSMBTypeEndOfTable: /* Skip, to be added at the end */ break; Index: branches/cparm/i386/modules/SMBiosGetters/mysmbios.c =================================================================== --- branches/cparm/i386/modules/SMBiosGetters/mysmbios.c (revision 1118) +++ branches/cparm/i386/modules/SMBiosGetters/mysmbios.c (revision 1119) @@ -96,7 +96,9 @@ // defaults for an iMac11,1 core i3/i5/i7 #define kDefaultiMacNehalem "iMac11,1" #define kDefaultiMacNehalemBIOSVersion " IM111.88Z.0034.B00.0903051113" - +// defaults for an iMac12,1 +#define kDefaultiMacSandy "iMac12,1" +#define kDefaultiMacSandyBIOSVersion " IM121.88Z.0047.B00.1102091756" // defaults for a Mac Pro #define kDefaultMacProFamily "MacPro" #define kDefaultMacPro "MacPro3,1" @@ -108,6 +110,11 @@ #define kDefaultMacProWestmere "MacPro5,1" #define kDefaultMacProWestmereBIOSVersion " MP51.88Z.007F.B00.1008031144" #define kDefaulMacProWestmereBIOSReleaseDate "08/03/10" +// defaults for a Xserve +#define kDefaultXserve "Xserve2,1" +#define kDefaultXserveBIOSVersion " XS21.88Z.006C.B06.0804011317" +#define kDefaulXserveBIOSReleaseDate "04/01/2008" +#define kDefaultXserveFamily "Xserve" //------------------------------------------------------------------------------------------------------------------------- @@ -261,8 +268,6 @@ int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter); - -SMBEntryPoint *origeps = 0; SMBEntryPoint *neweps = 0; static uint8_t stringIndex; // increament when a string is added and set the field value accordingly @@ -273,100 +278,141 @@ static SMBWord maxStructSize = 0; static SMBWord structureCount = 0; -/* Rewrite this function */ -char *setDefaultSMBData(void) +void setDefaultSMBData(void); + + +char *getDefaultSMBproductName(void) { - defaultBIOSInfo.vendor = kDefaultVendorManufacturer; - defaultBIOSInfo.releaseDate = kDefaultBIOSReleaseDate; + setDefaultSMBData(); + return defaultSystemInfo.productName; +} - defaultSystemInfo.manufacturer = kDefaultVendorManufacturer; - defaultSystemInfo.version = kDefaultSystemVersion; - defaultSystemInfo.serialNumber = kDefaultSerialNumber; +char *getDefaultSMBBoardProduct(void) +{ + setDefaultSMBData(); + return defaultBaseBoard.product; +} - defaultBaseBoard.manufacturer = kDefaultVendorManufacturer; - defaultBaseBoard.product = kDefaultBoardProduct; - - if (platformCPUFeature(CPU_FEATURE_MOBILE)) - { - if (Platform->CPU.NoCores > 1) +/* Rewrite this function */ +void setDefaultSMBData(void) +{ + static bool setDefSMB = true; + + if (setDefSMB) { + + if (Platform->CPU.isServer == true) { + defaultBIOSInfo.version = kDefaultXserveBIOSVersion; + defaultSystemInfo.productName = kDefaultXserve; + defaultBIOSInfo.releaseDate = kDefaulXserveBIOSReleaseDate; + defaultSystemInfo.family = kDefaultXserveFamily; + } + else if (Platform->CPU.isMobile == true) { - defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion; - defaultSystemInfo.productName = kDefaultMacBookPro; - defaultSystemInfo.family = kDefaultMacBookProFamily; + if (Platform->CPU.NoCores > 1) + { + defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion; + defaultSystemInfo.productName = kDefaultMacBookPro; + defaultSystemInfo.family = kDefaultMacBookProFamily; + } + else + { + defaultBIOSInfo.version = kDefaultMacBookBIOSVersion; + defaultSystemInfo.productName = kDefaultMacBook; + defaultSystemInfo.family = kDefaultMacBookFamily; + } } else { - defaultBIOSInfo.version = kDefaultMacBookBIOSVersion; - defaultSystemInfo.productName = kDefaultMacBook; - defaultSystemInfo.family = kDefaultMacBookFamily; - } - } - else - { - switch (Platform->CPU.NoCores) - { - case 1: - defaultBIOSInfo.version = kDefaultMacminiBIOSVersion; - defaultSystemInfo.productName = kDefaultMacmini; - defaultSystemInfo.family = kDefaultMacminiFamily; - break; - - case 2: - defaultBIOSInfo.version = kDefaultiMacBIOSVersion; - defaultSystemInfo.productName = kDefaultiMac; - defaultSystemInfo.family = kDefaultiMacFamily; - break; - default: + switch (Platform->CPU.NoCores) { - switch (Platform->CPU.Family) + case 1: + defaultBIOSInfo.version = kDefaultMacminiBIOSVersion; + defaultSystemInfo.productName = kDefaultMacmini; + defaultSystemInfo.family = kDefaultMacminiFamily; + break; + + case 2: + defaultBIOSInfo.version = kDefaultiMacBIOSVersion; + defaultSystemInfo.productName = kDefaultiMac; + defaultSystemInfo.family = kDefaultiMacFamily; + break; + default: { - case 0x06: + switch (Platform->CPU.Family) { - switch (Platform->CPU.Model) + case 0x06: { - case CPU_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) - case CPU_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? - case CPU_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale) - case 0x19: // Intel Core i5 650 @3.20 Ghz - defaultBIOSInfo.version = kDefaultiMacNehalemBIOSVersion; - defaultSystemInfo.productName = kDefaultiMacNehalem; - defaultSystemInfo.family = kDefaultiMacFamily; - break; - - case CPU_MODEL_NEHALEM: - case CPU_MODEL_NEHALEM_EX: - defaultBIOSInfo.version = kDefaultMacProNehalemBIOSVersion; - defaultSystemInfo.productName = kDefaultMacProNehalem; - defaultSystemInfo.family = kDefaultMacProFamily; - break; - - case CPU_MODEL_WESTMERE: - case CPU_MODEL_WESTMERE_EX: - defaultBIOSInfo.version = kDefaultMacProWestmereBIOSVersion; - defaultBIOSInfo.releaseDate = kDefaulMacProWestmereBIOSReleaseDate; - defaultSystemInfo.productName = kDefaultMacProWestmere; - defaultSystemInfo.family = kDefaultMacProFamily; - break; - - default: - defaultBIOSInfo.version = kDefaultMacProBIOSVersion; - defaultSystemInfo.productName = kDefaultMacPro; - defaultSystemInfo.family = kDefaultMacProFamily; - break; + switch (Platform->CPU.Model) + { + case CPUID_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) + case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? + case CPUID_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale) + case 0x19: // Intel Core i5 650 @3.20 Ghz + defaultBIOSInfo.version = kDefaultiMacNehalemBIOSVersion; + defaultSystemInfo.productName = kDefaultiMacNehalem; + defaultSystemInfo.family = kDefaultiMacFamily; + break; + + case CPUID_MODEL_SANDYBRIDGE: + case CPUID_MODEL_JAKETOWN: // Until Apple release a MacPro6,1 ?? + defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion; + defaultSystemInfo.productName = kDefaultiMacSandy; + defaultSystemInfo.family = kDefaultiMacFamily; + break; + + case CPUID_MODEL_NEHALEM: + case CPUID_MODEL_NEHALEM_EX: + defaultBIOSInfo.version = kDefaultMacProNehalemBIOSVersion; + defaultSystemInfo.productName = kDefaultMacProNehalem; + defaultSystemInfo.family = kDefaultMacProFamily; + break; + + case CPUID_MODEL_WESTMERE: + case CPUID_MODEL_WESTMERE_EX: + defaultBIOSInfo.version = kDefaultMacProWestmereBIOSVersion; + defaultBIOSInfo.releaseDate = kDefaulMacProWestmereBIOSReleaseDate; + defaultSystemInfo.productName = kDefaultMacProWestmere; + defaultSystemInfo.family = kDefaultMacProFamily; + break; + + default: + defaultBIOSInfo.version = kDefaultMacProBIOSVersion; + defaultSystemInfo.productName = kDefaultMacPro; + defaultSystemInfo.family = kDefaultMacProFamily; + break; + } + break; } - break; + default: + defaultBIOSInfo.version = kDefaultMacProBIOSVersion; + defaultSystemInfo.productName = kDefaultMacPro; + defaultSystemInfo.family = kDefaultMacProFamily; + break; } - default: - defaultBIOSInfo.version = kDefaultMacProBIOSVersion; - defaultSystemInfo.productName = kDefaultMacPro; - defaultSystemInfo.family = kDefaultMacProFamily; - break; + break; } - break; } } - } - return defaultSystemInfo.productName; + + if (!defaultBIOSInfo.vendor) + defaultBIOSInfo.vendor = kDefaultVendorManufacturer; + if (!defaultBIOSInfo.releaseDate) + defaultBIOSInfo.releaseDate = kDefaultBIOSReleaseDate; + + if (!defaultSystemInfo.manufacturer) + defaultSystemInfo.manufacturer = kDefaultVendorManufacturer; + if (!defaultSystemInfo.version) + defaultSystemInfo.version = kDefaultSystemVersion; + if (!defaultSystemInfo.serialNumber) + defaultSystemInfo.serialNumber = kDefaultSerialNumber; + + if (!defaultBaseBoard.manufacturer) + defaultBaseBoard.manufacturer = kDefaultVendorManufacturer; + if (!defaultBaseBoard.product) + defaultBaseBoard.product = kDefaultBoardProduct; + + setDefSMB = false; + } } /* Used for SM*_N smbios.plist keys */ @@ -386,11 +432,16 @@ sprintf(key, "%s%d", keyString, idx); if (value) + { if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) return true; + } else + { if (getValueForKey(key, string, &len, SMBPlist)) return true; + } + return false; } @@ -399,7 +450,10 @@ uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length; if (!field) - return (char *)0; + { + //return (char *)0; + return NULL; + } for (field--; field != 0 && strlen((char *)stringPtr) > 0; field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1)); @@ -407,97 +461,15 @@ return (char *)stringPtr; } -#ifndef BETA void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field) { + int strSize; + if (!field) - return; - if (!string) - { - *field = 0; - return; - } + { - int strSize = strlen(string) + 1; - memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize); - *field = stringIndex; - - stringIndex++; - stringsSize += strSize; -} - -bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value) -{ - const char *string = 0; - int len; - - if (numOfSetters <= idx) - return false; - - switch (SMBSetters[idx].valueType) - { - case kSMBString: - if (SMBSetters[idx].keyString) - { - if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist)) - break; - if (structPtr->orig->type == kSMBTypeMemoryDevice) // MemoryDevice only - if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL)) - break; - } - if (SMBSetters[idx].getSMBValue) - if (SMBSetters[idx].getSMBValue((returnType *)&string)) - break; - if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) - { - string = *(SMBSetters[idx].defaultValue); - break; - } - string = getSMBStringForField(structPtr->orig, *(uint8_t *)value); - break; - - case kSMBByte: - case kSMBWord: - case kSMBDWord: - //case kSMBQWord: - if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist)) - return true; - else - if (structPtr->orig->type == kSMBTypeMemoryDevice) // MemoryDevice only - if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value)) - return true; - if (SMBSetters[idx].getSMBValue(value)) - return true; -#if 0 - if (*(SMBSetters[idx].defaultValue)) - { - value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); - return true; - } -#endif - break; - } - - if (SMBSetters[idx].valueType == kSMBString && string) - setSMBStringForField(structPtr->new, string, &value->byte); - - return true; -} -#else - -#if FIXME -// this function don't work, it give me a corrupted dimm-part-number value (all other values seems to be correct), and so, -// an error in the memory tab of sysprofiler, i haven't checked yet what's wrong inside this function, -// it should be : -// dimm-part-number data <"2G-UDIMM", "99U5429-005.A00LF", "2G-UDIMM", "KLCD48F-A8KB5"> -// but it give: -// dimm-part-number data <11 1b 1e 00 11 1b 1f 00 11 1b 20 13 0f 21 00> // automatic is set in property options, ??? -void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field) -{ - int strSize; - - if (!field) return; + } if (!string) { *field = 0; @@ -507,40 +479,31 @@ strSize = strlen(string); // remove any spaces found at the end - while (string[strSize - 1] == ' ') + while ((strSize != 0) && (string[strSize - 1] == ' ')) strSize--; - memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize); - *field = stringIndex; - - stringIndex++; - stringsSize += strSize + 1; -} -#else -void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field) -{ - if (!field) - return; - if (!string) + + if (strSize == 0) { *field = 0; return; } - int strSize = strlen(string) + 1; memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize); + *field = stringIndex; stringIndex++; - stringsSize += strSize; + stringsSize += strSize + 1; } -#endif bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value) { const char *string = 0; int len; - + bool parsed; + int val; + if (numOfSetters <= idx) return false; @@ -571,15 +534,39 @@ case kSMBWord: case kSMBDWord: //case kSMBQWord: - if (SMBSetters[idx].keyString) + /*if (SMBSetters[idx].keyString) + { + if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist)) + return true; + else + if (structPtr->orig->type == kSMBTypeMemoryDevice) // MemoryDevice only + if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value)) + return true; + }*/ + if (SMBSetters[idx].keyString) { - if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist)) + parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist); + if (!parsed) + if (structPtr->orig->type == kSMBTypeMemoryDevice) // MemoryDevice only + parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val); + if (parsed) + { + switch (SMBSetters[idx].valueType) + { + case kSMBByte: + value->byte = (uint8_t)val; + break; + case kSMBWord: + value->word = (uint16_t)val; + break; + case kSMBDWord: + default: + value->dword = (uint32_t)val; + break; + } return true; - else - if (structPtr->orig->type == kSMBTypeMemoryDevice) // MemoryDevice only - if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value)) - return true; - } + } + } if (SMBSetters[idx].getSMBValue) if (SMBSetters[idx].getSMBValue(value)) return true; @@ -595,10 +582,9 @@ if (SMBSetters[idx].valueType == kSMBString && string) setSMBStringForField(structPtr->new, string, &value->byte); - + return true; } -#endif //------------------------------------------------------------------------------------------------------------------------- // Apple Specific //------------------------------------------------------------------------------------------------------------------------- @@ -616,7 +602,7 @@ void addSMBOemProcessorType(SMBStructPtrs *structPtr) { SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new; - + p->header.type = kSMBTypeOemProcessorType; p->header.length = sizeof(SMBOemProcessorType); p->header.handle = handle++; @@ -632,6 +618,30 @@ { SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new; + switch (Platform->CPU.Family) + { + case 0x06: + { + switch (Platform->CPU.Model) + { + case 0x19: // Intel Core i5 650 @3.20 Ghz + case CPUID_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) + case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? + case CPUID_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) + case CPUID_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) + case CPUID_MODEL_NEHALEM_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? + case CPUID_MODEL_WESTMERE: // Intel Core i7 LGA1366 (32nm) 6 Core + case CPUID_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? + case CPUID_MODEL_SANDYBRIDGE: + case CPUID_MODEL_JAKETOWN: + break; + + default: + return; + } + } + } + p->header.type = kSMBTypeOemProcessorBusSpeed; p->header.length = sizeof(SMBOemProcessorBusSpeed); p->header.handle = handle++; @@ -664,7 +674,7 @@ uint8_t *ptr; SMBWord structSize; int i; - + stringIndex = 1; stringsSize = 0; @@ -674,8 +684,12 @@ memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length); for (i = 0; i < numOfSetters; i++) - if (structPtr->orig->type == SMBSetters[i].type) + /*if (structPtr->orig->type == SMBSetters[i].type) { + if (SMBSetters[i].fieldOffset > structPtr->orig->length) + continue;*/ + if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) + { setterFound = true; setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset)); } @@ -710,6 +724,7 @@ maxStructSize = structSize; structureCount++; + } void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr) @@ -731,12 +746,15 @@ break; default: + { /* Add */ setSMBStruct(structPtr); break; + } } ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length); + for (; ((uint16_t *)ptr)[0] != 0; ptr++); if (((uint16_t *)ptr)[0] == 0) @@ -744,33 +762,37 @@ structPtr->orig = (SMBStructHeader *)ptr; } + + + addSMBFirmwareVolume(structPtr); - addSMBFirmwareVolume(structPtr); addSMBMemorySPD(structPtr); + addSMBOemProcessorType(structPtr); + addSMBOemProcessorBusSpeed(structPtr); addSMBEndOfTable(structPtr); + + } -void setupSMBIOSTable(void) +SMBEntryPoint * setupSMBIOSTable(SMBEntryPoint *origeps) { SMBStructPtrs *structPtr; uint8_t *buffer; bool setSMB = true; if (!origeps) - return; + return NULL; - neweps = origeps; - structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs)); if (!structPtr) - return; + return NULL; buffer = malloc(SMB_ALLOC_SIZE); if (!buffer) - return; + return NULL; bzero(buffer, SMB_ALLOC_SIZE); structPtr->new = (SMBStructHeader *)buffer; @@ -780,10 +802,10 @@ setDefaultSMBData(); setupNewSMBIOSTable(origeps, structPtr); - - neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint)); + + SMBEntryPoint *neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint)); if (!neweps) - return; + return NULL; bzero(neweps, sizeof(SMBEntryPoint)); neweps->anchor[0] = '_'; @@ -807,7 +829,7 @@ neweps->dmi.bcdRevision = 0x24; if (!neweps->dmi.tableAddress) - return; + return NULL; memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength); @@ -819,17 +841,13 @@ free(buffer); decodeSMBIOSTable(neweps); + + return neweps; } -void *getSmbiosPatched() -{ - return neweps; -} - /* Collect any information needed later */ void readSMBIOSInfo(SMBEntryPoint *eps) { - origeps = eps; uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress; SMBStructHeader *structHeader = (SMBStructHeader *)structPtr; @@ -842,9 +860,9 @@ { switch (structHeader->type) { - /*case kSMBTypeSystemInformation: + case kSMBTypeSystemInformation: Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid; - break;*/ + break; case kSMBTypePhysicalMemoryArray: Platform->DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices; @@ -858,6 +876,8 @@ Platform->RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed; dimmnbr++; break; + default: + break; } structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length); Index: branches/cparm/i386/modules/SMBiosGetters/mysmbios.h =================================================================== --- branches/cparm/i386/modules/SMBiosGetters/mysmbios.h (revision 1118) +++ branches/cparm/i386/modules/SMBiosGetters/mysmbios.h (revision 1119) @@ -44,33 +44,6 @@ bzero(x, sizeof(typedef struct SMBAnchor)); // -// SMBIOS structure types. -// - -enum { - kSMBTypeBIOSInformation = 0, - kSMBTypeSystemInformation = 1, - kSMBTypeBaseBoard = 2, - kSMBTypeSystemEnclosure = 3, - kSMBTypeProcessorInformation = 4, - kSMBTypeMemoryModule = 6, - kSMBTypeCacheInformation = 7, - kSMBTypeSystemSlot = 9, - kSMBTypePhysicalMemoryArray = 16, - kSMBTypeMemoryDevice = 17, - kSMBType32BitMemoryErrorInfo = 18, - kSMBType64BitMemoryErrorInfo = 33, - - kSMBTypeEndOfTable = 127, - - /* Apple Specific Structures */ - kSMBTypeFirmwareVolume = 128, - kSMBTypeMemorySPD = 130, - kSMBTypeOemProcessorType = 131, - kSMBTypeOemProcessorBusSpeed = 132 -}; - -// // BIOS Information (Type 0) // typedef struct SMBBIOSInformation { @@ -83,10 +56,10 @@ SMBQWord characteristics; // supported BIOS functions } __attribute__((packed)) SMBBIOSInformation; +#if UNUSED // // Base Board (Type 2) // - typedef struct SMBBaseBoard { SMB_STRUCT_HEADER // Type 2 SMBString manufacturer; @@ -104,6 +77,7 @@ // times sizeof(SMBWord) when computing the actual record size, // if you need it. } __attribute__((packed)) SMBBaseBoard; +#endif // Values for boardType in Type 2 records enum { @@ -382,9 +356,11 @@ } __attribute__((packed)) SMBOemProcessorBusSpeed; extern void readSMBIOSInfo(SMBEntryPoint *eps); -extern void setupSMBIOSTable(void); -extern void *getSmbiosPatched(); +extern SMBEntryPoint * setupSMBIOSTable(SMBEntryPoint *origeps); +//extern void *getSmbiosPatched(); extern void decodeSMBIOSTable(SMBEntryPoint *eps); -extern char *setDefaultSMBData(void); +//extern void setDefaultSMBData(void); +extern char *getDefaultSMBproductName(void); +extern char *getDefaultSMBBoardProduct(void); #endif /* !__LIBSAIO_MYSMBIOS_H */ Index: branches/cparm/i386/modules/SMBiosGetters/smbios_getters.c =================================================================== --- branches/cparm/i386/modules/SMBiosGetters/smbios_getters.c (revision 1118) +++ branches/cparm/i386/modules/SMBiosGetters/smbios_getters.c (revision 1119) @@ -41,27 +41,30 @@ { switch (Platform->CPU.Model) { - case 0x0D: // ? - case CPU_MODEL_YONAH: // Yonah 0x0E - case CPU_MODEL_MEROM: // Merom 0x0F - case CPU_MODEL_PENRYN: // Penryn 0x17 - case CPU_MODEL_ATOM: // Atom 45nm 0x1C + case CPUID_MODEL_BANIAS: // Banias 0x09 + case CPUID_MODEL_DOTHAN: // Dothan 0x0D + case CPUID_MODEL_YONAH: // Yonah 0x0E + case CPUID_MODEL_MEROM: // Merom 0x0F + case CPUID_MODEL_PENRYN: // Penryn 0x17 + case CPUID_MODEL_ATOM: // Atom 45nm 0x1C return false; case 0x19: // Intel Core i5 650 @3.20 Ghz - case CPU_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) - case CPU_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) - case CPU_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? - case CPU_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) - case CPU_MODEL_WESTMERE: // Intel Core i7 LGA1366 (32nm) 6 Core - case CPU_MODEL_NEHALEM_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? - case CPU_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? + case CPUID_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) + case CPUID_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) + case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? + case CPUID_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) + case CPUID_MODEL_WESTMERE: // Intel Core i7 LGA1366 (32nm) 6 Core + case CPUID_MODEL_NEHALEM_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? + case CPUID_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? + case CPUID_MODEL_SANDYBRIDGE: + case CPUID_MODEL_JAKETOWN: { // thanks to dgobe for i3/i5/i7 bus speed detection int nhm_bus = 0x3F; static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F}; unsigned long did, vid; - int i; + unsigned int i; // Nehalem supports Scrubbing // First, locate the PCI bus where the MCH is located @@ -87,8 +90,12 @@ value->word = qpibusspeed; return true; } + default: + break; //Unsupported CPU type } } + default: + break; } } return false; @@ -100,12 +107,12 @@ { return 0x0501; // Quad-Core Xeon } - else if (Platform->CPU.NoCores == 1) + if (((Platform->CPU.NoCores == 1) || (Platform->CPU.NoCores == 2)) && !(platformCPUExtFeature(CPUID_EXTFEATURE_EM64T))) { - return 0x0201; // Core Solo + return 0x0201; // Core Solo / Duo }; - return 0x0301; // Core 2 Duo + return 0x0301; // Core 2 Solo / Duo } bool getSMBOemProcessorType(returnType *value) @@ -128,52 +135,59 @@ { switch (Platform->CPU.Model) { - case 0x0D: // ? - case CPU_MODEL_YONAH: // Yonah - case CPU_MODEL_MEROM: // Merom - case CPU_MODEL_PENRYN: // Penryn - case CPU_MODEL_ATOM: // Intel Atom (45nm) + case CPUID_MODEL_BANIAS: // Banias + case CPUID_MODEL_DOTHAN: // Dothan + case CPUID_MODEL_YONAH: // Yonah + case CPUID_MODEL_MEROM: // Merom + case CPUID_MODEL_PENRYN: // Penryn + case CPUID_MODEL_ATOM: // Intel Atom (45nm) return true; - case CPU_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) + case CPUID_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) value->word = 0x0701; // Core i7 return true; - case CPU_MODEL_FIELDS: // Lynnfield, Clarksfield, Jasper + case CPUID_MODEL_FIELDS: // Lynnfield, Clarksfield, Jasper if (strstr(Platform->CPU.BrandString, "Core(TM) i5")) value->word = 0x601; // Core i5 else value->word = 0x701; // Core i7 return true; - case CPU_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale) + case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale) if (strstr(Platform->CPU.BrandString, "Core(TM) i5")) value->word = 0x601; // Core i5 else value->word = 0x0701; // Core i7 return true; - case CPU_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale) + case CPUID_MODEL_SANDYBRIDGE: + case CPUID_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale) if (strstr(Platform->CPU.BrandString, "Core(TM) i3")) value->word = 0x901; // Core i3 else if (strstr(Platform->CPU.BrandString, "Core(TM) i5")) value->word = 0x601; // Core i5 else if (strstr(Platform->CPU.BrandString, "Core(TM) i7")) value->word = 0x0701; // Core i7 - else - value->word = simpleGetSMBOemProcessorType(); + /*else + value->word = simpleGetSMBOemProcessorType();*/ return true; - case CPU_MODEL_WESTMERE: // Intel Core i7 LGA1366 (32nm) 6 Core (Gulftown, Westmere-EP, Westmere-WS) - case CPU_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? - value->word = 0x0701; // Core i7 + case CPUID_MODEL_JAKETOWN: + case CPUID_MODEL_WESTMERE: // Intel Core i7 LGA1366 (32nm) 6 Core (Gulftown, Westmere-EP, Westmere-WS) + case CPUID_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? + value->word = 0x0501; // Core i7 return true; case 0x19: // Intel Core i5 650 @3.20 Ghz value->word = 0x601; // Core i5 return true; + default: + break; //Unsupported CPU type } } + default: + break; } } @@ -183,22 +197,21 @@ bool getSMBMemoryDeviceMemoryType(returnType *value) { static int idx = -1; - if (is_module_loaded("Memory")) { - int map; + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { + int map; - idx++; - if (idx < MAX_RAM_SLOTS) - { - map = Platform->DMI.DIMM[idx]; - if (Platform->RAM.DIMM[map].InUse && Platform->RAM.DIMM[map].Type != 0) + idx++; + if (idx < MAX_RAM_SLOTS) { - DBG("RAM Detected Type = %d\n", Platform->RAM.DIMM[map].Type); - value->byte = Platform->RAM.DIMM[map].Type; - return true; + map = Platform->DMI.DIMM[idx]; + if (Platform->RAM.DIMM[map].InUse && Platform->RAM.DIMM[map].Type != 0) + { + DBG("RAM Detected Type = %d\n", Platform->RAM.DIMM[map].Type); + value->byte = Platform->RAM.DIMM[map].Type; + return true; + } } } -} - //return false; value->byte = SMB_MEM_TYPE_DDR2; return true; } @@ -206,22 +219,21 @@ bool getSMBMemoryDeviceMemorySpeed(returnType *value) { static int idx = -1; - if (is_module_loaded("Memory")) { - int map; + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { + int map; - idx++; - if (idx < MAX_RAM_SLOTS) - { - map = Platform->DMI.DIMM[idx]; - if (Platform->RAM.DIMM[map].InUse && Platform->RAM.DIMM[map].Frequency != 0) + idx++; + if (idx < MAX_RAM_SLOTS) { - DBG("RAM Detected Freq = %d Mhz\n", Platform->RAM.DIMM[map].Frequency); - value->dword = Platform->RAM.DIMM[map].Frequency; - return true; + map = Platform->DMI.DIMM[idx]; + if (Platform->RAM.DIMM[map].InUse && Platform->RAM.DIMM[map].Frequency != 0) + { + DBG("RAM Detected Freq = %d Mhz\n", Platform->RAM.DIMM[map].Frequency); + value->dword = Platform->RAM.DIMM[map].Frequency; + return true; + } } } -} - //return false; value->dword = 800; return true; } @@ -229,22 +241,21 @@ bool getSMBMemoryDeviceManufacturer(returnType *value) { static int idx = -1; - if (is_module_loaded("Memory")) { - int map; + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { + int map; - idx++; - if (idx < MAX_RAM_SLOTS) - { - map = Platform->DMI.DIMM[idx]; - if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].Vendor) > 0) + idx++; + if (idx < MAX_RAM_SLOTS) { - DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform->RAM.DIMM[map].Vendor); - value->string = Platform->RAM.DIMM[map].Vendor; - return true; + map = Platform->DMI.DIMM[idx]; + if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].Vendor) > 0) + { + DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform->RAM.DIMM[map].Vendor); + value->string = Platform->RAM.DIMM[map].Vendor; + return true; + } } } -} - //return false; value->string = "N/A"; return true; } @@ -252,23 +263,22 @@ bool getSMBMemoryDeviceSerialNumber(returnType *value) { static int idx = -1; - if (is_module_loaded("Memory")) { - int map; + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { + int map; - idx++; - if (idx < MAX_RAM_SLOTS) - { - map = Platform->DMI.DIMM[idx]; - if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].SerialNo) > 0) + idx++; + if (idx < MAX_RAM_SLOTS) { - DBG("name = %s, map=%d, RAM Detected SerialNo[%d]='%s'\n", name ? name : "", + map = Platform->DMI.DIMM[idx]; + if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].SerialNo) > 0) + { + DBG("name = %s, map=%d, RAM Detected SerialNo[%d]='%s'\n", name ? name : "", map, idx, Platform->RAM.DIMM[map].SerialNo); - value->string = Platform->RAM.DIMM[map].SerialNo; - return true; + value->string = Platform->RAM.DIMM[map].SerialNo; + return true; + } } } -} - //return false; value->string = "N/A"; return true; } @@ -276,22 +286,21 @@ bool getSMBMemoryDevicePartNumber(returnType *value) { static int idx = -1; - if (is_module_loaded("Memory")) { - int map; + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { + int map; - idx++; - if (idx < MAX_RAM_SLOTS) - { - map = Platform->DMI.DIMM[idx]; - if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].PartNo) > 0) + idx++; + if (idx < MAX_RAM_SLOTS) { - DBG("Ram Detected PartNo[%d]='%s'\n", idx, Platform->RAM.DIMM[map].PartNo); - value->string = Platform->RAM.DIMM[map].PartNo; - return true; + map = Platform->DMI.DIMM[idx]; + if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].PartNo) > 0) + { + DBG("Ram Detected PartNo[%d]='%s'\n", idx, Platform->RAM.DIMM[map].PartNo); + value->string = Platform->RAM.DIMM[map].PartNo; + return true; + } } } - } - //return false; value->string = "N/A"; return true; } Index: branches/cparm/i386/modules/SMBiosGetters/SMBiosGetters.c =================================================================== --- branches/cparm/i386/modules/SMBiosGetters/SMBiosGetters.c (revision 1118) +++ branches/cparm/i386/modules/SMBiosGetters/SMBiosGetters.c (revision 1119) @@ -9,29 +9,28 @@ #include "efi.h" #include "mysmbios.h" +#define kEnableSMBIOSGetters "EnableSMBIOSGetters" + + void getSmbiosPatched_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { - struct SMBEntryPoint *patched_smb = NULL; - + readSMBIOSInfo(getSmbiosOriginal()); + execute_hook("ScanMemory", NULL, NULL, NULL, NULL, NULL, NULL); - setupSMBIOSTable(); - smbios_p = (EFI_PTR32)getSmbiosPatched(); - - patched_smb = getSmbiosPatched(); - - if (patched_smb) - smbios_p = (EFI_PTR32)patched_smb; + SMBEntryPoint *patched_smb = setupSMBIOSTable(getSmbiosOriginal()); + + if (patched_smb != NULL) + smbios_p = ((uint64_t)((uint32_t)patched_smb)); else + { verbose("Error: Could not get patched SMBIOS, fallback to original SMBIOS !!\n"); - + + struct SMBEntryPoint *smbios_o = getSmbiosOriginal(); + smbios_p = ((uint64_t)((uint32_t)smbios_o)); + } + } -void smbios_helper_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) -{ - struct SMBEntryPoint *smbios_o = (struct SMBEntryPoint *)arg1; - readSMBIOSInfo(smbios_o); -} - void getProductName_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { setupSmbiosConfigFile("SMBIOS.plist"); @@ -41,15 +40,38 @@ if (getValueForKey("SMproductname", &val, &len, &bootInfo->smbiosConfig)) { gPlatformName = (char *)val; } else { - gPlatformName = setDefaultSMBData(); + gPlatformName = getDefaultSMBproductName(); } } +void getboardproduct_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) +{ + setupSmbiosConfigFile("SMBIOS.plist"); + int len = 0; + const char *val = 0; + + if (getValueForKey("SMboardproduct", &val, &len, &bootInfo->smbiosConfig)) { + gboardproduct = (char *)val; + } else { + gboardproduct = getDefaultSMBBoardProduct(); + } + +} + +void is_SMB_Getters_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6){} + void SMBiosGetters_start() { + bool enable = true; + getBoolForKey(kEnableSMBIOSGetters, &enable, &bootInfo->bootConfig) ; - register_hook_callback("getSmbiosPatched", &getSmbiosPatched_hook); - register_hook_callback("smbios_helper", &smbios_helper_hook); - register_hook_callback("getProductNamePatched", &getProductName_hook); + enable = (execute_hook("isSMBIOSRegistred", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS); + + if (enable) { + register_hook_callback("getSmbiosPatched", &getSmbiosPatched_hook); + register_hook_callback("getProductNamePatched", &getProductName_hook); + register_hook_callback("getboardproductPatched", &getboardproduct_hook); + register_hook_callback("isSMBIOSRegistred", &is_SMB_Getters_Registred_Hook); + } } Index: branches/cparm/i386/modules/SMBiosGetters/Makefile =================================================================== --- branches/cparm/i386/modules/SMBiosGetters/Makefile (revision 1118) +++ branches/cparm/i386/modules/SMBiosGetters/Makefile (revision 1119) @@ -27,8 +27,8 @@ -D__ARCHITECTURE__=\"i386\" -DSAIO_INTERNAL_USER \ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ - -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common + -mpreferred-stack-boundary=2 -fno-align-functions \ + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common -fno-stack-protector #-lc_kext -lc_kext -libcc_kext -fstack-protector-all DEFINES= CONFIG = hd @@ -70,25 +70,26 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/SMBiosGetters.o \ $(OBJROOT)/mysmbios.o \ + $(OBJROOT)/smbios_getters.o \ $(OBJROOT)/smbios_decode.o \ - $(OBJROOT)/smbios_getters.o \ -o $(SYMROOT)/$(MODULE_NAME).dylib SMBiosGetters.o: - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "SMBiosGetters.c" $(INC) -o "$(OBJROOT)/SMBiosGetters.o" + gcc-4.2 $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "SMBiosGetters.c" $(INC) -o "$(OBJROOT)/SMBiosGetters.o" mysmbios.o: - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "mysmbios.c" $(INC) -o "$(OBJROOT)/mysmbios.o" + gcc-4.2 $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "mysmbios.c" $(INC) -o "$(OBJROOT)/mysmbios.o" smbios_decode.o: - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "smbios_decode.c" $(INC) -o "$(OBJROOT)/smbios_decode.o" + gcc-4.2 $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "smbios_decode.c" $(INC) -o "$(OBJROOT)/smbios_decode.o" smbios_getters.o: - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "smbios_getters.c" $(INC) -o "$(OBJROOT)/smbios_getters.o" + gcc-4.2 $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "smbios_getters.c" $(INC) -o "$(OBJROOT)/smbios_getters.o" include ../../MakeInc.dir Index: branches/cparm/i386/modules/HibernateEnabler/resume.c =================================================================== --- branches/cparm/i386/modules/HibernateEnabler/resume.c (revision 1118) +++ branches/cparm/i386/modules/HibernateEnabler/resume.c (revision 1119) @@ -178,7 +178,12 @@ Unforutnaltely I cannot find a note why to switch back to text mode for nVidia cards only and because it check_vga_nvidia does not work (cards normally are behind a bridge) I will remove it completely - setVideoMode( VGA_TEXT_MODE, 0 ); +#if UNUSED + setVideoMode(VGA_TEXT_MODE, 0); +#else + setVideoMode(VGA_TEXT_MODE); +#endif + #endif } else Index: branches/cparm/i386/modules/HibernateEnabler/bmdecompress.h =================================================================== --- branches/cparm/i386/modules/HibernateEnabler/bmdecompress.h (revision 1118) +++ branches/cparm/i386/modules/HibernateEnabler/bmdecompress.h (revision 1119) @@ -21,11 +21,10 @@ */ -#include "libsa.h" - #ifndef __BMDECOMPRESS_RESUME_H #define __BMDECOMPRESS_RESUME_H +#include "libsa.h" void * DecompressData(void *srcbase, int *dw, int *dh, int *bytesPerPixel); #endif /* !__BMDECOMPRESS_RESUME_H */ Index: branches/cparm/i386/modules/HibernateEnabler/HibernateEnabler.c =================================================================== --- branches/cparm/i386/modules/HibernateEnabler/HibernateEnabler.c (revision 1118) +++ branches/cparm/i386/modules/HibernateEnabler/HibernateEnabler.c (revision 1119) @@ -16,6 +16,7 @@ #define kWake "Wake" /* boot.c */ #define kForceWake "ForceWake" /* boot.c */ #define kWakeImage "WakeImage" /* boot.c */ +#define kEnableHibernate "EnableHibernateModule" void HibernateEnabler_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { @@ -71,6 +72,11 @@ void HibernateEnabler_start() { - register_hook_callback("PreBoot", &HibernateEnabler_hook); - register_hook_callback("spinActivity_hook", &spinActivityIndicator_hook); + bool enable = true; + getBoolForKey(kEnableHibernate, &enable, &bootInfo->bootConfig) ; + + if (enable) { + register_hook_callback("PreBoot", &HibernateEnabler_hook); + register_hook_callback("spinActivity_hook", &spinActivityIndicator_hook); + } } \ No newline at end of file Index: branches/cparm/i386/modules/HibernateEnabler/Makefile =================================================================== --- branches/cparm/i386/modules/HibernateEnabler/Makefile (revision 1118) +++ branches/cparm/i386/modules/HibernateEnabler/Makefile (revision 1119) @@ -28,7 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-mdynamic-no-pic + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-mdynamic-no-pic DEFINES= CONFIG = hd Index: branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c =================================================================== --- branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c (revision 1118) +++ branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c (revision 1119) @@ -11,7 +11,7 @@ #define VIDEO(x) (bootArgs->Video.v_ ## x) -#define MIN(x, y) ((x) < (y) ? (x) : (y)) +//#define MIN(x, y) ((x) < (y) ? (x) : (y)) int previewTotalSectors = 0; uint8_t *previewSaveunder = 0; @@ -45,7 +45,9 @@ green=(val>>8)&0xff; blue=(val)&0xff; break; - } + } + default: + break; } char *ptr=(char *)output+x*(op/8)+y*or; switch (op) @@ -58,6 +60,8 @@ case 32 : *((uint32_t *)ptr) = (red << 16) | (green << 8) | blue; break; + default: + break; } } } @@ -78,7 +82,11 @@ if (src && (uncomp=DecompressData(src, &origwidth, &origheight, &origbpx))) { +#if UNUSED if (!setVESAGraphicsMode(origwidth, origheight, origbpx, 0)) +#else + if (!setVESAGraphicsMode(origwidth, origheight, origbpx)) +#endif if (initGraphicsMode () != errSuccess) return; screen = (uint8_t *) VIDEO (baseAddr); Index: branches/cparm/i386/modules/Keymapper/Makefile =================================================================== --- branches/cparm/i386/modules/Keymapper/Makefile (revision 1118) +++ branches/cparm/i386/modules/Keymapper/Makefile (revision 1119) @@ -28,7 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-mdynamic-no-pic + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-lc_kext -libcc_kext -mdynamic-no-pic DEFINES= CONFIG = hd @@ -69,6 +69,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/Keymapper.o \ -o $(SYMROOT)/$(MODULE_NAME).dylib Index: branches/cparm/i386/modules/Keymapper/Keymapper.c =================================================================== --- branches/cparm/i386/modules/Keymapper/Keymapper.c (revision 1118) +++ branches/cparm/i386/modules/Keymapper/Keymapper.c (revision 1119) @@ -12,6 +12,9 @@ #include "xml.h" #include "modules.h" +#define kEnableKeyMap "EnableKeyMapper" + + // CPARM's AZERTY_switch : A Basic QWERTY to AZERTY switcher int AZERTY_switch(int c) { @@ -191,7 +194,7 @@ char *kMatchkey = 0; sprintf(kMatchkey, "%d",c); TagPtr match_key; - if (match_key = XMLGetProperty(match_map, (const char*)kMatchkey)) + if ((match_key = XMLGetProperty(match_map, (const char*)kMatchkey))) { kMatchkey = XMLCastString(match_key); c = strtoul((const char *)kMatchkey, NULL,10); @@ -201,7 +204,7 @@ if (map_kb_type == NULL){ TagPtr match_type; - if (match_type = XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"KeyboardType")) + if ((match_type = XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"KeyboardType"))) map_kb_type = XMLCastString(match_type); else map_kb_type = "NONE"; // Default to QWERTY @@ -218,5 +221,10 @@ void Keymapper_start() { - register_hook_callback("Keymapper", &Keymapper_hook); + bool enable = true; + getBoolForKey(kEnableKeyMap, &enable, &bootInfo->bootConfig) ; + + if (enable) { + register_hook_callback("Keymapper", &Keymapper_hook); + } } \ No newline at end of file Index: branches/cparm/i386/modules/USBFix/USBFix.c =================================================================== --- branches/cparm/i386/modules/USBFix/USBFix.c (revision 1118) +++ branches/cparm/i386/modules/USBFix/USBFix.c (revision 1119) @@ -6,7 +6,9 @@ #include "libsaio.h" #include "modules.h" #include "pci.h" +#include "bootstruct.h" +#define kEnableUSBMod "EnableUSBModule" extern int usb_loop(); void notify_usb_dev(pci_dt_t *pci_dev); @@ -25,11 +27,16 @@ usb_loop(); } - void USBFix_start() { - register_hook_callback("PCIDevice", &USBFix_pci_hook); - register_hook_callback("Kernel Start", &USBFix_start_hook); + bool enable = true; + getBoolForKey(kEnableUSBMod, &enable, &bootInfo->bootConfig) ; + + if (enable) { + register_hook_callback("PCIDevice", &USBFix_pci_hook); + register_hook_callback("Kernel Start", &USBFix_start_hook); + } + } Index: branches/cparm/i386/modules/USBFix/usb.c =================================================================== --- branches/cparm/i386/modules/USBFix/usb.c (revision 1118) +++ branches/cparm/i386/modules/USBFix/usb.c (revision 1119) @@ -30,12 +30,6 @@ int usb_loop(); -struct pciList -{ - pci_dt_t* pciDev; - struct pciList* next; -}; - struct pciList* usbList = NULL; int legacy_off (pci_dt_t *pci_dev); @@ -83,8 +77,8 @@ getBoolForKey(kUHCIreset, &fix_uhci, &bootInfo->bootConfig); getBoolForKey(kLegacyOff, &fix_legacy, &bootInfo->bootConfig); } - - msglog("\n"); + + DBG("\n"); struct pciList* current = usbList; while(current) @@ -103,6 +97,8 @@ if (fix_uhci) retVal &= uhci_reset(current->pciDev); break; + default: + break; } current = current->next; @@ -116,15 +112,8 @@ // NOTE: This *must* be called after the last file is loaded from the drive in the event that we are booting form usb. // NOTE2: This should be called after any getc() call. (aka, after the Wait=y keyworkd is used) // AKA: Make this run immediatly before the kernel is called - //uint32_t capaddr, opaddr; - //uint8_t eecp; - //uint32_t usbcmd, usbsts, usbintr; - //uint32_t usblegsup, usblegctlsts; - - //int isOSowned; - //int isBIOSowned; - - verbose("Setting Legacy USB Off on controller [%04x:%04x] at %02x:%2x.%x\n", + + DBG("Setting Legacy USB Off on controller [%04x:%04x] at %02x:%2x.%x\n", pci_dev->vendor_id, pci_dev->device_id, pci_dev->dev.bits.bus, pci_dev->dev.bits.dev, pci_dev->dev.bits.func); @@ -200,17 +189,14 @@ DBG("usblegsup=%08x isOSowned=%d isBIOSowned=%d usblegctlsts=%08x\n", usblegsup, isOSowned, isBIOSowned, usblegctlsts); - verbose("Legacy USB Off Done\n"); + DBG("Legacy USB Off Done\n"); return 1; } int ehci_acquire (pci_dt_t *pci_dev) { - int j, k; - //uint32_t base; - //uint8_t eecp; + int j, k; uint8_t legacy[8]; - //bool isOwnershipConflict; bool alwaysHardBIOSReset = false; if (!getBoolForKey(kEHCIhard, &alwaysHardBIOSReset, &bootInfo->bootConfig)) { @@ -220,7 +206,7 @@ pci_config_write16(pci_dev->dev.addr, 0x04, 0x0002); uint32_t base = pci_config_read32(pci_dev->dev.addr, 0x10); - verbose("EHCI controller [%04x:%04x] at %02x:%2x.%x DMA @%x\n", + DBG("EHCI controller [%04x:%04x] at %02x:%2x.%x DMA @%x\n", pci_dev->vendor_id, pci_dev->device_id, pci_dev->dev.bits.bus, pci_dev->dev.bits.dev, pci_dev->dev.bits.func, base); @@ -250,7 +236,7 @@ //We try soft reset first - some systems hang on reboot with hard reset // Definitely needed during reboot on 10.4.6 - bool isOwnershipConflict = ((legacy[3] & 1 != 0) && (legacy[2] & 1 != 0)); + bool isOwnershipConflict = (((legacy[3] & 1) != 0) && ((legacy[2] & 1) != 0)); if (!alwaysHardBIOSReset && isOwnershipConflict) { DBG("EHCI - Ownership conflict - attempting soft reset ...\n"); DBG("EHCI - toggle OS Ownership to 0\n"); @@ -334,7 +320,7 @@ base = pci_config_read32(pci_dev->dev.addr, 0x20); port_base = (base >> 5) & 0x07ff; - verbose("UHCI controller [%04x:%04x] at %02x:%2x.%x base %x(%x)\n", + DBG("UHCI controller [%04x:%04x] at %02x:%2x.%x base %x(%x)\n", pci_dev->vendor_id, pci_dev->device_id, pci_dev->dev.bits.bus, pci_dev->dev.bits.dev, pci_dev->dev.bits.func, port_base, base); Index: branches/cparm/i386/modules/USBFix/Makefile =================================================================== --- branches/cparm/i386/modules/USBFix/Makefile (revision 1118) +++ branches/cparm/i386/modules/USBFix/Makefile (revision 1119) @@ -28,7 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-lc_kext -libcc_kext DEFINES= CONFIG = hd @@ -70,6 +70,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/USBFix.o \ $(OBJROOT)/usb.o \ -o $(SYMROOT)/$(MODULE_NAME).dylib Index: branches/cparm/i386/modules/HPET/HPET.c =================================================================== --- branches/cparm/i386/modules/HPET/HPET.c (revision 1118) +++ branches/cparm/i386/modules/HPET/HPET.c (revision 1119) @@ -31,16 +31,16 @@ if(current->class_id != PCI_CLASS_BRIDGE_ISA) return; - bool do_enable_hpet = true; - getBoolForKey(kForceHPET, &do_enable_hpet, &bootInfo->bootConfig); - - if (do_enable_hpet) - force_enable_hpet(current); + force_enable_hpet(current); } void HPET_start() { - register_hook_callback("PCIDevice", &HPET_hook); + bool enable = true; + getBoolForKey(EnableHPETModule, &enable, &bootInfo->bootConfig); + + if (enable) + register_hook_callback("PCIDevice", &HPET_hook); } /* @@ -104,6 +104,8 @@ case 0x1106: force_enable_hpet_via(lpc_dev); break; + default: + break; } @@ -116,7 +118,7 @@ void force_enable_hpet_via(pci_dt_t *lpc_dev) { uint32_t val, hpet_address = 0xFED00000; - int i; + unsigned int i; for(i = 1; i < sizeof(lpc_controllers_via) / sizeof(lpc_controllers_via[0]); i++) { @@ -154,7 +156,7 @@ void force_enable_hpet_intel(pci_dt_t *lpc_dev) { uint32_t val, hpet_address = 0xFED00000; - int i; + unsigned int i; void *rcba; /* LPC on Intel ICH is always (?) at 00:1f.0 */ @@ -170,7 +172,7 @@ lpc_controllers_intel[i].name, lpc_dev->vendor_id, lpc_dev->device_id, rcba); if (rcba == 0) - printf(" RCBA disabled; cannot force enable HPET\n"); + DBG(" RCBA disabled; cannot force enable HPET\n"); else { val = REG32(rcba, 0x3404); @@ -192,8 +194,20 @@ // verify if the job is done val = REG32(rcba, 0x3404); +#if DEBUG_HPET if (!(val & 0x80)) printf(" Failed to force enable HPET\n"); +#endif +/* +#define HPET_CONFIG 0x10 // General configuration register +#define HPET_CNF_LEG_RT 0x00000002 +#define HPET_CNF_ENABLE 0x00000001 + + val = REG32(hpet_address, HPET_CONFIG); + val &= ~HPET_CNF_LEG_RT; + val |= HPET_CNF_ENABLE; + REG32(hpet_address, HPET_CONFIG) = val; +*/ } break; Index: branches/cparm/i386/modules/HPET/hpet.h =================================================================== --- branches/cparm/i386/modules/HPET/hpet.h (revision 1118) +++ branches/cparm/i386/modules/HPET/hpet.h (revision 1119) @@ -8,7 +8,7 @@ #include "libsaio.h" #define REG32(base, reg) ((volatile uint32_t *)base)[(reg) >> 2] -#define kForceHPET "ForceHPET" +#define EnableHPETModule "EnableHPETModule" void force_enable_hpet(pci_dt_t *lpc_dev); Index: branches/cparm/i386/modules/HPET/Makefile =================================================================== --- branches/cparm/i386/modules/HPET/Makefile (revision 1118) +++ branches/cparm/i386/modules/HPET/Makefile (revision 1119) @@ -28,7 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common DEFINES= CONFIG = hd Index: branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.c =================================================================== --- branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.c (revision 1118) +++ branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.c (revision 1119) @@ -36,30 +36,30 @@ // defaults for a MacBook static const SMStrEntryPair const sm_macbook_defaults[]={ {"SMbiosvendor", "Apple Inc." }, - {"SMbiosversion", "MB41.88Z.0073.B00.0809221748" }, - {"SMbiosdate", "04/01/2008" }, + {"SMbiosversion", "MB41.88Z.00C1.B00.0802091535" }, + {"SMbiosdate", "02/09/2008" }, {"SMmanufacter", "Apple Inc." }, {"SMproductname", "MacBook4,1" }, {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, + {"SMserial", "RM83064H0P1" }, {"SMfamily", "MacBook" }, {"SMboardmanufacter", "Apple Inc." }, - {"SMboardproduct", "Mac-F42D89C8" }, + {"SMboardproduct", "Mac-F22788A9" }, { "","" } }; // defaults for a MacBook Pro static const SMStrEntryPair const sm_macbookpro_defaults[]={ {"SMbiosvendor", "Apple Inc." }, - {"SMbiosversion", "MBP41.88Z.0073.B00.0809221748" }, - {"SMbiosdate", "04/01/2008" }, + {"SMbiosversion", "MBP41.88Z.00C1.B03.0802271651" }, + {"SMbiosdate", "02/27/2008" }, {"SMmanufacter", "Apple Inc." }, {"SMproductname", "MacBookPro4,1" }, {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, + {"SMserial", "W88198N6YJX" }, {"SMfamily", "MacBookPro" }, {"SMboardmanufacter", "Apple Inc." }, - {"SMboardproduct", "Mac-F42D89C8" }, + {"SMboardproduct", "Mac-F42C89C8" }, { "","" } }; @@ -67,11 +67,11 @@ static const SMStrEntryPair const sm_macmini_defaults[]={ {"SMbiosvendor", "Apple Inc." }, {"SMbiosversion", "MM21.88Z.009A.B00.0706281359" }, - {"SMbiosdate", "04/01/2008" }, + {"SMbiosdate", "06/28/2007" }, {"SMmanufacter", "Apple Inc." }, {"SMproductname", "Macmini2,1" }, {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, + {"SMserial", "YM8054BYYL2" }, {"SMfamily", "Napa Mac" }, {"SMboardmanufacter", "Apple Inc." }, {"SMboardproduct", "Mac-F4208EAA" }, @@ -81,69 +81,102 @@ // defaults for an iMac static const SMStrEntryPair const sm_imac_defaults[]={ {"SMbiosvendor", "Apple Inc." }, - {"SMbiosversion", "IM81.88Z.00C1.B00.0802091538" }, - {"SMbiosdate", "04/01/2008" }, + {"SMbiosversion", "IM71.88Z.007A.B03.0803051705" }, + {"SMbiosdate", "03/05/2008" }, {"SMmanufacter", "Apple Inc." }, - {"SMproductname", "iMac8,1" }, + {"SMproductname", "iMac7,1" }, {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, + {"SMserial", "W87410PWX87" }, {"SMfamily", "Mac" }, {"SMboardmanufacter", "Apple Inc." }, - {"SMboardproduct", "Mac-F227BEC8" }, + {"SMboardproduct", "Mac-F4238CC8" }, { "","" } }; // defaults for a Mac Pro static const SMStrEntryPair const sm_macpro_defaults[]={ {"SMbiosvendor", "Apple Computer, Inc." }, - {"SMbiosversion", "MP31.88Z.006C.B05.0802291410" }, - {"SMbiosdate", "04/01/2008" }, + {"SMbiosversion", "MP31.88Z.006C.B02.0801021250" }, + {"SMbiosdate", "01/02/2008" }, {"SMmanufacter", "Apple Computer, Inc." }, {"SMproductname", "MacPro3,1" }, {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, + {"SMserial", "G88014V4XYK" }, {"SMfamily", "MacPro" }, {"SMboardmanufacter", "Apple Computer, Inc." }, - {"SMboardproduct", "Mac-F4208DC8" }, + {"SMboardproduct", "Mac-F42C88C8" }, { "","" } }; // defaults for an iMac11,1 core i3/i5/i7 static const SMStrEntryPair const sm_imac_core_defaults[]={ {"SMbiosvendor", "Apple Inc." }, - {"SMbiosversion", "IM111.88Z.0034.B00.0802091538" }, - {"SMbiosdate", "06/01/2009" }, + {"SMbiosversion", "IM111.88Z.0034.B00.0910301727" }, + {"SMbiosdate", "10/30/2009" }, {"SMmanufacter", "Apple Inc." }, {"SMproductname", "iMac11,1" }, {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, + {"SMserial", "W89470DZ5RU" }, {"SMfamily", "iMac" }, - {"SMboardmanufacter", "Apple Computer, Inc." }, + {"SMboardmanufacter", "Apple Inc." }, {"SMboardproduct", "Mac-F2268DAE" }, { "","" } }; +// defaults for an iMac12,1 : todo: populate correctly +static const SMStrEntryPair const sm_imac_sandy_defaults[]={ + {"SMbiosvendor", "Apple Inc." }, + {"SMbiosversion", "IM121.88Z.0047.B00.1102091756" }, + {"SMbiosdate", "10/30/2011" }, + {"SMmanufacter", "Apple Inc." }, + {"SMproductname", "iMac12,1" }, + {"SMsystemversion", "1.0" }, + {"SMserial", "W89470DZ5RU" }, + {"SMfamily", "iMac" }, + {"SMboardmanufacter", "Apple Inc." }, + {"SMboardproduct", "Mac-F2268DAE" }, + { "","" } +}; + // defaults for a Mac Pro 4,1 core i7/Xeon static const SMStrEntryPair const sm_macpro_core_defaults[]={ {"SMbiosvendor", "Apple Computer, Inc." }, - {"SMbiosversion", "MP41.88Z.0081.B04.0903051113" }, - {"SMbiosdate", "11/06/2009" }, - {"SMmanufacter", "Apple Computer, Inc." }, + {"SMbiosversion", "MP41.88Z.0081.B03.0902231259" }, + {"SMbiosdate", "02/23/2009" }, + {"SMmanufacter", "Apple Inc." }, {"SMproductname", "MacPro4,1" }, {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, + {"SMserial", "CK91601V8Q0" }, {"SMfamily", "MacPro" }, {"SMboardmanufacter", "Apple Computer, Inc." }, - {"SMboardproduct", "Mac-F4208DC8" }, + {"SMboardproduct", "Mac-F221BEC8" }, { "","" } }; +// default for a Xserve +static const SMStrEntryPair const sm_xserve_defaults[]={ + {"SMbiosvendor", "Apple Inc." }, + {"SMbiosversion", "XS21.88Z.006C.B06.0804011317" }, + {"SMbiosdate", "04/01/2008" }, + {"SMmanufacter", "Apple Inc." }, + {"SMproductname", "Xserve2,1" }, + {"SMsystemversion", "1.0" }, + {"SMserial", "CK816033X8S" }, + {"SMfamily", "Xserve" }, + {"SMboardmanufacter", "Apple Inc." }, + {"SMboardproduct", "Mac-F42289C8" }, + { "","" } +}; + /*static */const char* sm_get_defstr(const char * key, int table_num) { int i; const SMStrEntryPair* sm_defaults; - if (platformCPUFeature(CPU_FEATURE_MOBILE)) { + if (Platform->CPU.isServer == true) + { + sm_defaults=sm_xserve_defaults; + } else if (Platform->CPU.isMobile == true) { if (Platform->CPU.NoCores > 1) { sm_defaults=sm_macbookpro_defaults; } else { @@ -166,16 +199,22 @@ { switch (Platform->CPU.Model) { - case CPU_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) - case CPU_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? - case CPU_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale) + case CPUID_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) + case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? + case CPUID_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale) case 0x19: // Intel Core i5 650 @3.20 Ghz sm_defaults=sm_imac_core_defaults; break; - case CPU_MODEL_NEHALEM: - case CPU_MODEL_NEHALEM_EX: - case CPU_MODEL_WESTMERE: - case CPU_MODEL_WESTMERE_EX: + + case CPUID_MODEL_SANDYBRIDGE: + case CPUID_MODEL_JAKETOWN: + sm_defaults=sm_imac_sandy_defaults; + break; + + case CPUID_MODEL_NEHALEM: + case CPUID_MODEL_NEHALEM_EX: + case CPUID_MODEL_WESTMERE: + case CPUID_MODEL_WESTMERE_EX: sm_defaults=sm_macpro_core_defaults; break; default: @@ -225,36 +264,39 @@ { switch (Platform->CPU.Model) { - case 0x0D: // ? - case CPU_MODEL_YONAH: // Yonah 0x0E - case CPU_MODEL_MEROM: // Merom 0x0F - case CPU_MODEL_PENRYN: // Penryn 0x17 - case CPU_MODEL_ATOM: // Atom 45nm 0x1C + case CPUID_MODEL_BANIAS: // Banias 0x09 + case CPUID_MODEL_DOTHAN: // Dothan 0x0D + case CPUID_MODEL_YONAH: // Yonah 0x0E + case CPUID_MODEL_MEROM: // Merom 0x0F + case CPUID_MODEL_PENRYN: // Penryn 0x17 + case CPUID_MODEL_ATOM: // Atom 45nm 0x1C return 0; // TODO: populate bus speed for these processors -// case CPU_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) +// case CPUID_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) // if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) // return 2500; // Core i5 // return 4800; // Core i7 -// case CPU_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) -// case CPU_MODEL_NEHALEM_EX: -// case CPU_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? +// case CPUID_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) +// case CPUID_MODEL_NEHALEM_EX: +// case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? // return 4800; // GT/s / 1000 // - case CPU_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? + case CPUID_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? return 0; // TODO: populate bus speed for these processors // case 0x19: // Intel Core i5 650 @3.20 Ghz // return 2500; // why? Intel spec says 2.5GT/s case 0x19: // Intel Core i5 650 @3.20 Ghz - case CPU_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) - case CPU_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) - case CPU_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? - case CPU_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) - case CPU_MODEL_WESTMERE: // Intel Core i7 LGA1366 (32nm) 6 Core - case CPU_MODEL_NEHALEM_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? + case CPUID_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) + case CPUID_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm) + case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ??? + case CPUID_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) + case CPUID_MODEL_SANDYBRIDGE: + case CPUID_MODEL_JAKETOWN: + case CPUID_MODEL_WESTMERE: // Intel Core i7 LGA1366 (32nm) 6 Core + case CPUID_MODEL_NEHALEM_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? { // thanks to dgobe for i3/i5/i7 bus speed detection int nhm_bus = 0x3F; static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F}; @@ -297,12 +339,12 @@ { return 0x0501; // Quad-Core Xeon } - else if (Platform->CPU.NoCores == 1) + if (((Platform->CPU.NoCores == 1) || (Platform->CPU.NoCores == 2)) && !(platformCPUExtFeature(CPUID_EXTFEATURE_EM64T))) { - return 0x0201; // Core Solo + return 0x0201; // Core Solo / Duo } - return 0x0301; // Core 2 Duo + return 0x0301; // Core 2 Solo / Duo } static int sm_get_cputype (const char *name, int table_num) @@ -322,27 +364,29 @@ { switch (Platform->CPU.Model) { - case 0x0D: // ? - case CPU_MODEL_YONAH: // Yonah - case CPU_MODEL_MEROM: // Merom - case CPU_MODEL_PENRYN: // Penryn - case CPU_MODEL_ATOM: // Intel Atom (45nm) + case CPUID_MODEL_BANIAS: // Banias + case CPUID_MODEL_DOTHAN: // Dothan + case CPUID_MODEL_YONAH: // Yonah + case CPUID_MODEL_MEROM: // Merom + case CPUID_MODEL_PENRYN: // Penryn + case CPUID_MODEL_ATOM: // Intel Atom (45nm) return sm_get_simplecputype(); - case CPU_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) + case CPUID_MODEL_NEHALEM: // Intel Core i7 LGA1366 (45nm) return 0x0701; // Core i7 - case CPU_MODEL_FIELDS: // Lynnfield, Clarksfield, Jasper + case CPUID_MODEL_FIELDS: // Lynnfield, Clarksfield, Jasper if (strstr(Platform->CPU.BrandString, "Core(TM) i5")) return 0x601; // Core i5 return 0x701; // Core i7 - case CPU_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale) + case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale) if (strstr(Platform->CPU.BrandString, "Core(TM) i5")) return 0x601; // Core i5 return 0x0701; // Core i7 - case CPU_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale) + case CPUID_MODEL_SANDYBRIDGE: // Sandybridge + case CPUID_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale) if (strstr(Platform->CPU.BrandString, "Core(TM) i3")) return 0x901; // Core i3 if (strstr(Platform->CPU.BrandString, "Core(TM) i5")) @@ -351,8 +395,9 @@ return 0x0701; // Core i7 return sm_get_simplecputype(); - case CPU_MODEL_WESTMERE: // Intel Core i7 LGA1366 (32nm) 6 Core (Gulftown, Westmere-EP, Westmere-WS) - case CPU_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? + case CPUID_MODEL_JAKETOWN: + case CPUID_MODEL_WESTMERE: // Intel Core i7 LGA1366 (32nm) 6 Core (Gulftown, Westmere-EP, Westmere-WS) + case CPUID_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ??? return 0x0701; // Core i7 case 0x19: // Intel Core i5 650 @3.20 Ghz @@ -367,8 +412,7 @@ static int sm_get_memtype (const char *name, int table_num) { - if (is_module_loaded("Memory")) { - + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { int map; if (table_num < MAX_RAM_SLOTS) { @@ -385,8 +429,7 @@ static int sm_get_memspeed (const char *name, int table_num) { - if (is_module_loaded("Memory")) { - + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { int map; if (table_num < MAX_RAM_SLOTS) { @@ -402,8 +445,7 @@ static const char *sm_get_memvendor (const char *name, int table_num) { - if (is_module_loaded("Memory")) { - + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { int map; if (table_num < MAX_RAM_SLOTS) { @@ -419,8 +461,7 @@ static const char *sm_get_memserial (const char *name, int table_num) { - if (is_module_loaded("Memory")) { - + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { int map; if (table_num < MAX_RAM_SLOTS) { @@ -437,8 +478,7 @@ static const char *sm_get_mempartno (const char *name, int table_num) { - if (is_module_loaded("Memory")) { - + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) { int map; if (table_num < MAX_RAM_SLOTS) { @@ -1076,6 +1116,7 @@ } +/* char* getSmbiosProductName() { struct SMBEntryPoint *smbios; @@ -1103,8 +1144,8 @@ verbose("Actual model name is '%s'\n", tempString); return tempString; } +*/ - void scan_memory(PlatformInfo_t *p) { int i=0; Index: branches/cparm/i386/modules/SMBiosPatcher/SMBiosPatcher.c =================================================================== --- branches/cparm/i386/modules/SMBiosPatcher/SMBiosPatcher.c (revision 1118) +++ branches/cparm/i386/modules/SMBiosPatcher/SMBiosPatcher.c (revision 1119) @@ -1,5 +1,5 @@ /* - * Copyright 2011 cparm . All rights reserved. + * Copyright 2011 cparm. All rights reserved. */ #include "boot.h" #include "bootstruct.h" @@ -21,30 +21,34 @@ #define DBG(x...) #endif +#define kEnableSMBIOSPatcher "EnableSMBIOSPatcher" + + void getSmbiosPatched_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { - struct SMBEntryPoint *smbios_o = (struct SMBEntryPoint *)arg1; struct SMBEntryPoint *patched_smb = NULL; + getSmbiosTableStructure(getSmbiosOriginal()); // generate tables entry list for fast table finding + + if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) + scan_memory(Platform); + execute_hook("ScanMemory", NULL, NULL, NULL, NULL, NULL, NULL); - patched_smb = getSmbiosPatched(smbios_o); + patched_smb = getSmbiosPatched(getSmbiosOriginal()); if (patched_smb) - smbios_p = (EFI_PTR32)patched_smb; + smbios_p = ((uint64_t)((uint32_t)patched_smb)); else + { verbose("Error: Could not get patched SMBIOS, fallback to original SMBIOS !!\n"); + + struct SMBEntryPoint *smbios_o = getSmbiosOriginal(); + smbios_p = ((uint64_t)((uint32_t)smbios_o)); + } + } -void smbios_helper_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) -{ - struct SMBEntryPoint *orig = (struct SMBEntryPoint *)arg1; - getSmbiosTableStructure(orig); // generate tables entry list for fast table finding - - if (is_module_loaded("Memory")) - scan_memory(Platform); -} - void getProductName_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { setupSmbiosConfigFile("SMBIOS.plist"); @@ -62,9 +66,18 @@ } +void is_SMB_Patcher_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6){} + void SMBiosPatcher_start() { + bool enable = true; + getBoolForKey(kEnableSMBIOSPatcher, &enable, &bootInfo->bootConfig) ; + + enable = (execute_hook("isSMBIOSRegistred", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS); + + if (enable) { register_hook_callback("getSmbiosPatched", &getSmbiosPatched_hook); - register_hook_callback("smbios_helper", &smbios_helper_hook); register_hook_callback("getProductNamePatched", &getProductName_hook); + register_hook_callback("isSMBIOSRegistred", &is_SMB_Patcher_Registred_Hook); + } } Index: branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.h =================================================================== --- branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.h (revision 1118) +++ branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.h (revision 1119) @@ -44,7 +44,7 @@ extern void scan_memory(PlatformInfo_t *); extern const char* sm_get_defstr(const char * key, int table_num); extern struct SMBEntryPoint *getSmbiosPatched(struct SMBEntryPoint *orig); -extern char* getSmbiosProductName(); +//extern char* getSmbiosProductName(); extern struct DMIHeader* FindFirstDmiTableOfType(int type, int minlength); extern struct DMIHeader* FindNextDmiTableOfType(int type, int minlen); extern const char * smbiosStringAtIndex(DMIHeader*, int index, int *length ); Index: branches/cparm/i386/modules/SMBiosPatcher/Makefile =================================================================== --- branches/cparm/i386/modules/SMBiosPatcher/Makefile (revision 1118) +++ branches/cparm/i386/modules/SMBiosPatcher/Makefile (revision 1119) @@ -70,6 +70,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/SMBiosPatcher.o \ $(OBJROOT)/smbios_patcher.o \ -o $(SYMROOT)/$(MODULE_NAME).dylib Index: branches/cparm/i386/modules/Resolution/915resolution.c =================================================================== --- branches/cparm/i386/modules/Resolution/915resolution.c (revision 1118) +++ branches/cparm/i386/modules/Resolution/915resolution.c (revision 1119) @@ -8,8 +8,6 @@ * Copyright 2009. All rights reserved. * */ -#ifndef _RESOLUTION_H_ -#define _RESOLUTION_H_ #include "libsaio.h" #include "edid.h" @@ -510,6 +508,8 @@ outb(CONFIG_MECH_ONE_DATA + 1, 0x33); outb(CONFIG_MECH_ONE_DATA + 2, 0x33); break; + default: + break; } #if DEBUG @@ -563,6 +563,8 @@ outb(CONFIG_MECH_ONE_DATA + 1, map->b1); outb(CONFIG_MECH_ONE_DATA + 2, map->b2); break; + default: + break; } #if DEBUG @@ -853,9 +855,9 @@ { break; } + default: + break; } // } // } } - -#endif // _RESOLUTION_H_ \ No newline at end of file Index: branches/cparm/i386/modules/Resolution/Resolution.c =================================================================== --- branches/cparm/i386/modules/Resolution/Resolution.c (revision 1118) +++ branches/cparm/i386/modules/Resolution/Resolution.c (revision 1119) @@ -6,10 +6,20 @@ #include "libsaio.h" #include "915resolution.h" #include "modules.h" +#include "bootstruct.h" +#define kEnableResolution "EnableResolutionModule" + + void Resolution_start() { - register_hook_callback("getResolution_hook", &getResolutionHook); - patchVideoBios(); + bool enable = true; + getBoolForKey(kEnableResolution, &enable, &bootInfo->bootConfig) ; + + if (enable) { + register_hook_callback("getResolution_hook", &getResolutionHook); + patchVideoBios(); + } + } Index: branches/cparm/i386/modules/Resolution/Makefile =================================================================== --- branches/cparm/i386/modules/Resolution/Makefile (revision 1118) +++ branches/cparm/i386/modules/Resolution/Makefile (revision 1119) @@ -28,8 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common - + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common DEFINES= CONFIG = hd INC = -I. -I.. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR) -I$(LIBSAIODIR) -I$(BOOT2DIR) @@ -70,6 +69,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/edid.o \ $(OBJROOT)/915resolution.o \ $(OBJROOT)/Resolution.o \ Index: branches/cparm/i386/modules/CPUfreq/CPUfreq.c =================================================================== --- branches/cparm/i386/modules/CPUfreq/CPUfreq.c (revision 1118) +++ branches/cparm/i386/modules/CPUfreq/CPUfreq.c (revision 1119) @@ -11,6 +11,7 @@ #define kFixFSB "FixFSB" #define MSR_FSB_FREQ 0x000000cd #define AMD_10H_11H_CONFIG 0xc0010064 +#define kEnableCPUfreq "EnableCPUfreqModule" void CPUfreq_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) { @@ -34,11 +35,11 @@ uint8_t crlo, crhi = 0; switch (Platform->CPU.Model) { - case CPU_MODEL_YONAH: // Core Duo/Solo, Pentium M DC - case CPU_MODEL_MEROM: // Core Xeon, Core 2 DC, 65nm + case CPUID_MODEL_YONAH: // Core Duo/Solo, Pentium M DC + case CPUID_MODEL_MEROM: // Core Xeon, Core 2 DC, 65nm case 0x16: // Celeron, Core 2 SC, 65nm - case CPU_MODEL_PENRYN: // Core 2 Duo/Extreme, Xeon, 45nm - case CPU_MODEL_ATOM: // Atom :) + case CPUID_MODEL_PENRYN: // Core 2 Duo/Extreme, Xeon, 45nm + case CPUID_MODEL_ATOM: // Atom :) case 0x27: // Atom Lincroft, 45nm getBoolForKey(kFixFSB, &fix_fsb, &bootInfo->bootConfig); @@ -146,9 +147,9 @@ { verbose("CPU: "); // valv: mobility check - if (strstr(Platform->CPU.BrandString, "obile") == 0) + if ((strstr(Platform->CPU.BrandString, "obile") == 0) || (strstr(Platform->CPU.BrandString, "Atom") == 0)) { - Platform->CPU.Features |= CPU_FEATURE_MOBILE; + Platform->CPU.isMobile = true; } verbose("%s\n", Platform->CPU.BrandString); @@ -202,9 +203,14 @@ void CPUfreq_start() { - if (Platform->CPU.Features & CPU_FEATURE_MSR) { - register_hook_callback("PreBoot", &CPUfreq_hook); - } else { - verbose ("Unsupported CPU: CPUfreq disabled !!!\n"); - } + bool enable = true; + getBoolForKey(kEnableCPUfreq, &enable, &bootInfo->bootConfig) ; + + if (enable) { + if (Platform->CPU.Features & CPUID_FEATURE_MSR) { + register_hook_callback("PreBoot", &CPUfreq_hook); + } else { + verbose ("Unsupported CPU: CPUfreq disabled !!!\n"); + } + } } Index: branches/cparm/i386/modules/CPUfreq/Makefile =================================================================== --- branches/cparm/i386/modules/CPUfreq/Makefile (revision 1118) +++ branches/cparm/i386/modules/CPUfreq/Makefile (revision 1119) @@ -28,7 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common DEFINES= CONFIG = hd Index: branches/cparm/i386/modules/Memory/mem.c =================================================================== --- branches/cparm/i386/modules/Memory/mem.c (revision 1118) +++ branches/cparm/i386/modules/Memory/mem.c (revision 1119) @@ -101,43 +101,4 @@ } } -void scan_memory(PlatformInfo_t *p) -{ - int i=0; - struct DMIHeader * dmihdr = NULL; - - struct DMIMemoryModuleInfo* memInfo[MAX_RAM_SLOTS]; // 6 - struct DMIPhysicalMemoryArray* physMemArray; // 16 - struct DMIMemoryDevice* memDev[MAX_RAM_SLOTS]; //17 - - /* We mainly don't use obsolete tables 5,6 because most of computers don't handle it anymore */ - Platform->DMI.MemoryModules = 0; - /* Now lets peek info rom table 16,17 as for some bios, table 5 & 6 are not used */ - physMemArray = (struct DMIPhysicalMemoryArray*) FindFirstDmiTableOfType(16, 4); - Platform->DMI.MaxMemorySlots = physMemArray ? physMemArray->numberOfMemoryDevices : 0; - - i = 0; - for(dmihdr = FindFirstDmiTableOfType(17, 4); - dmihdr; - dmihdr = FindNextDmiTableOfType(17, 4) ) { - memDev[i] = (struct DMIMemoryDevice*) dmihdr; - if (memDev[i]->size !=0 ) Platform->DMI.MemoryModules++; - if (memDev[i]->speed>0) Platform->RAM.DIMM[i].Frequency = memDev[i]->speed; // take it here for now but we'll check spd and dmi table 6 as well - i++; - } - // for table 6, we only have a look at the current speed - i = 0; - for(dmihdr = FindFirstDmiTableOfType(6, 4); - dmihdr; - dmihdr = FindNextDmiTableOfType(6, 4) ) { - memInfo[i] = (struct DMIMemoryModuleInfo*) dmihdr; - if (memInfo[i]->currentSpeed > Platform->RAM.DIMM[i].Frequency) - Platform->RAM.DIMM[i].Frequency = memInfo[i]->currentSpeed; // favor real overclocked speed if any - i++; - } -#if 0 - dumpAllTablesOfType(17); - getc(); #endif -} -#endif Index: branches/cparm/i386/modules/Memory/mem.h =================================================================== --- branches/cparm/i386/modules/Memory/mem.h (revision 1118) +++ branches/cparm/i386/modules/Memory/mem.h (revision 1119) @@ -9,10 +9,8 @@ #include "platform.h" -#if UNUSED -extern void scan_memory(PlatformInfo_t *); -#endif + extern void dumpPhysAddr(const char * title, void * a, int len); #endif /* __LIBSAIO_MEM_H */ Index: branches/cparm/i386/modules/Memory/spd.c =================================================================== --- branches/cparm/i386/modules/Memory/spd.c (revision 1118) +++ branches/cparm/i386/modules/Memory/spd.c (revision 1119) @@ -25,7 +25,7 @@ #define DBG(x...) #endif -const char *spd_memory_types[] = +static const char *spd_memory_types[] = { "RAM", /* 00h Undefined */ "FPM", /* 01h FPM */ @@ -42,7 +42,7 @@ }; #define UNKNOWN_MEM_TYPE 2 -uint8_t spd_mem_to_smbios[] = +static uint8_t spd_mem_to_smbios[] = { UNKNOWN_MEM_TYPE, /* 00h Undefined */ UNKNOWN_MEM_TYPE, /* 01h FPM */ @@ -57,7 +57,7 @@ UNKNOWN_MEM_TYPE, /* 0Ah Undefined */ SMB_MEM_TYPE_DDR3 /* 0Bh SDRAM DDR 3 */ }; -#define SPD_TO_SMBIOS_SIZE (sizeof(spd_mem_to_smbios)/sizeof(uint8_t)) +//#define SPD_TO_SMBIOS_SIZE (sizeof(spd_mem_to_smbios)/sizeof(uint8_t)) #define rdtsc(low,high) \ __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)) @@ -67,26 +67,25 @@ #define SMBHSTCMD 3 #define SMBHSTADD 4 #define SMBHSTDAT 5 -#define SBMBLKDAT 7 +//#define SBMBLKDAT 7 /** Read one byte from the intel i2c, used for reading SPD on intel chipsets only. */ unsigned char smb_read_byte_intel(uint32_t base, uint8_t adr, uint8_t cmd) { - int l1 = 0; - int l2 = 0; - int h1 = 0; - int h2 = 0; + int l1, h1, l2, h2; unsigned long long t; outb(base + SMBHSTSTS, 0x1f); // reset SMBus Controller outb(base + SMBHSTDAT, 0xff); - while( inb(base + SMBHSTSTS) & 0x01) - { + rdtsc(l1, h1); + while ( inb(base + SMBHSTSTS) & 0x01) // wait until read + { rdtsc(l2, h2); t = ((h2 - h1) * 0xffffffff + (l2 - l1)) / (Platform->CPU.TSCFrequency / 100); - if(t > 50) return 0xFF; // hack, exit if unresponsive. - } + if (t > 5) + return 0xFF; // break + } outb(base + SMBHSTCMD, cmd); outb(base + SMBHSTADD, (adr << 1) | 0x01 ); @@ -124,7 +123,7 @@ static void init_spd(char * spd, uint32_t base, int slot) { int i; - for (i=0; i< SPD_INDEXES_SIZE; i++) { + for (i=0; (unsigned)i< SPD_INDEXES_SIZE; i++) { READ_SPD(spd, base, slot, spd_indexes[i]); } } @@ -141,7 +140,7 @@ if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { // DDR3 bank = (spd[SPD_DDR3_MEMORY_BANK] & 0x07f); // constructors like Patriot use b7=1 code = spd[SPD_DDR3_MEMORY_CODE]; - for (i=0; i < VEN_MAP_SIZE; i++) + for (i=0; (unsigned)i < VEN_MAP_SIZE; i++) if (bank==vendorMap[i].bank && code==vendorMap[i].code) return vendorMap[i].name; } @@ -157,7 +156,7 @@ code = spd[64]; bank = 0; } - for (i=0; i < VEN_MAP_SIZE; i++) + for (i=0; (unsigned)i < VEN_MAP_SIZE; i++) if (bank==vendorMap[i].bank && code==vendorMap[i].code) return vendorMap[i].name; } @@ -203,10 +202,11 @@ #define SLST(a) ((uint8_t)(spd[a] & 0x0f)) /** Get DDR3 or DDR2 serial number, 0 most of the times, always return a valid ptr */ -char asciiSerial[16]; +//char asciiSerial[16]; const char *getDDRSerial(const char* spd) { - + static char asciiSerial[16]; + if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) // DDR3 { sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125)); @@ -220,9 +220,10 @@ } /** Get DDR3 or DDR2 Part Number, always return a valid ptr */ -char asciiPartNo[32]; +//char asciiPartNo[32]; const char * getDDRPartNum(char* spd, uint32_t base, int slot) { + static char asciiPartNo[32]; int i, start=0, index = 0; if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { @@ -235,7 +236,7 @@ // Check that the spd part name is zero terminated and that it is ascii: bzero(asciiPartNo, sizeof(asciiPartNo)); char c; - for (i=start; i < start + sizeof(asciiPartNo); i++) { + for (i=start; (unsigned)i < start + sizeof(asciiPartNo); i++) { READ_SPD(spd, base, slot, i); // only read once the corresponding model part (ddr3 or ddr2) c = spd[i]; if (isalpha(c) || isdigit(c) || ispunct(c)) // It seems that System Profiler likes only letters and digits... @@ -245,7 +246,6 @@ } return strdup(asciiPartNo); - return NULL; } int mapping []= {0,2,1,3,4,6,5,7,8,10,9,11}; @@ -256,18 +256,25 @@ { int i, speed; uint8_t spd_size, spd_type; - uint32_t base; + uint32_t base, mmio, hostc; bool dump = false; RamSlotInfo_t* slot; + uint16_t cmd = pci_config_read16(smbus_dev->dev.addr, 0x04); + DBG("SMBus CmdReg: 0x%x\n", cmd); + pci_config_write16(smbus_dev->dev.addr, 0x04, cmd | 1); + + mmio = pci_config_read32(smbus_dev->dev.addr, 0x10);// & ~0x0f; base = pci_config_read16(smbus_dev->dev.addr, 0x20) & 0xFFFE; - DBG("Scanning smbus_dev <%04x, %04x> ...\n",smbus_dev->vendor_id, smbus_dev->device_id); + hostc = pci_config_read8(smbus_dev->dev.addr, 0x40); + DBG("Scanning SMBus [%04x:%04x], mmio: 0x%x, ioport: 0x%x, hostc: 0x%x\n", + smbus_dev->vendor_id, smbus_dev->device_id, mmio, base, hostc); getBoolForKey("DumpSPD", &dump, &bootInfo->bootConfig); bool fullBanks = // needed at least for laptops Platform->DMI.MemoryModules == Platform->DMI.MaxMemorySlots; // Search MAX_RAM_SLOTS slots - char spdbuf[256]; + char spdbuf[MAX_SPD_SIZE]; for (i = 0; i < MAX_RAM_SLOTS; i++){ DBG("Scanning slot %d\n", i); @@ -288,6 +295,9 @@ switch (slot->spd[SPD_MEMORY_TYPE]) { case SPD_MEMORY_TYPE_SDRAM_DDR2: + /*slot->ModuleSize = ((1 << (slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17) * + ((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]);*/ + slot->ModuleSize = ((1 << (slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17) * ((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]); break; @@ -309,7 +319,7 @@ // determine spd speed speed = getDDRspeedMhz(slot->spd); - if (slot->FrequencyFrequency = speed; + if (slot->Frequency<(uint32_t)speed) slot->Frequency = speed; // pci memory controller if available, is more reliable if (Platform->RAM.Frequency > 0) { @@ -350,7 +360,7 @@ } // for } -struct smbus_controllers_t smbus_controllers[] = { +static struct smbus_controllers_t smbus_controllers[] = { {0x8086, 0x269B, "ESB2", read_smb_intel }, {0x8086, 0x25A4, "6300ESB", read_smb_intel }, @@ -367,11 +377,10 @@ }; - bool is_smbus_controller(pci_dt_t* pci_dt) { int i = 0; - for ( ; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) + for ( ; (unsigned)i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) { if (pci_dt->vendor_id == smbus_controllers[i].vendor && pci_dt->device_id == smbus_controllers[i].device) @@ -381,11 +390,14 @@ } return false; } - +#if UNUSED void scan_spd(PlatformInfo_t *p, pci_dt_t* smbus_controller_dev) +#else +void scan_spd(pci_dt_t* smbus_controller_dev) +#endif { int i = 0; - for ( ; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) + for ( ; (unsigned)i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) { if (smbus_controller_dev->vendor_id == smbus_controllers[i].vendor && smbus_controller_dev->device_id == smbus_controllers[i].device) Index: branches/cparm/i386/modules/Memory/Memory.c =================================================================== --- branches/cparm/i386/modules/Memory/Memory.c (revision 1118) +++ branches/cparm/i386/modules/Memory/Memory.c (revision 1119) @@ -15,7 +15,7 @@ #include "bootstruct.h" #include "modules.h" -#define kUseMemDetect "UseMemDetect" +#define kEnableMemory "EnableMemoryModule" pci_dt_t * dram_controller_dev = NULL; pci_dt_t * smbus_controller_dev = NULL; @@ -24,12 +24,25 @@ void Memory_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6); void Memory_PCIDevice_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6); +void is_Memory_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6){} void Memory_start() { - register_hook_callback("PCIDevice", &Memory_PCIDevice_hook); - register_hook_callback("ScanMemory", &Memory_hook); + bool enable = true; + + getBoolForKey(kEnableMemory, &enable, &bootInfo->bootConfig); + + if (pci_config_read16(PCIADDR(0, 0x00, 0), 0x00) != 0x8086) + enable = false; + + enable = (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS); + + if (enable) { + register_hook_callback("PCIDevice", &Memory_PCIDevice_hook); + register_hook_callback("ScanMemory", &Memory_hook); + register_hook_callback("isMemoryRegistred", &is_Memory_Registred_Hook); + } } void Memory_PCIDevice_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) @@ -47,21 +60,19 @@ } void Memory_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) -{ - bool useAutodetection = true; - getBoolForKey(kUseMemDetect, &useAutodetection, &bootInfo->bootConfig); +{ - - if (useAutodetection) { - - if (dram_controller_dev!=NULL) { - scan_dram_controller(dram_controller_dev); // Rek: pci dev ram controller direct and fully informative scan ... - } - - if(smbus_controller_dev) - { - scan_spd(Platform, smbus_controller_dev); - } - } - + if (dram_controller_dev!=NULL) { + scan_dram_controller(dram_controller_dev); // Rek: pci dev ram controller direct and fully informative scan ... + } + + if(smbus_controller_dev) + { +#if UNUSED + scan_spd(Platform, smbus_controller_dev); +#else + scan_spd(smbus_controller_dev); +#endif + } + } \ No newline at end of file Index: branches/cparm/i386/modules/Memory/dram_controllers.c =================================================================== --- branches/cparm/i386/modules/Memory/dram_controllers.c (revision 1118) +++ branches/cparm/i386/modules/Memory/dram_controllers.c (revision 1119) @@ -45,20 +45,21 @@ } int nhm_bus = 0x3F; -long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F}; + // Setup Nehalem Integrated Memory Controller static void setup_nhm(pci_dt_t *dram_dev) { + static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F}; unsigned long did, vid; int i; // Nehalem supports Scrubbing // First, locate the PCI bus where the MCH is located - for(i = 0; i < sizeof(possible_nhm_bus); i++) + for(i = 0; (unsigned)i < sizeof(possible_nhm_bus); i++) { - vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00); - did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02); + vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_VENDOR_ID); + did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_DEVICE_ID); vid &= 0xFFFF; did &= 0xFF00; @@ -485,7 +486,7 @@ Platform->RAM.Channels = SMB_MEM_CHANNEL_DUAL; } -struct mem_controller_t dram_controllers[] = { +static struct mem_controller_t dram_controllers[] = { // Default unknown chipset { 0, 0, "", NULL, NULL, NULL }, @@ -525,7 +526,7 @@ }; -const char *memory_channel_types[] = +static const char *memory_channel_types[] = { "Unknown", "Single", "Dual", "Triple" }; @@ -533,7 +534,7 @@ void scan_dram_controller(pci_dt_t *dram_dev) { int i; - for(i = 1; i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++) + for(i = 1; (unsigned)i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++) if ((dram_controllers[i].vendor == dram_dev->vendor_id) && (dram_controllers[i].device == dram_dev->device_id)) { @@ -550,13 +551,17 @@ if (dram_controllers[i].poll_speed != NULL) dram_controllers[i].poll_speed(dram_dev); - - verbose("Frequency detected: %d MHz (%d) %s Channel %d-%d-%d-%d\n", - (uint32_t)Platform->RAM.Frequency / 1000000, - (uint32_t)Platform->RAM.Frequency / 500000, - memory_channel_types[Platform->RAM.Channels], - Platform->RAM.CAS, Platform->RAM.TRC, Platform->RAM.TRP, Platform->RAM.RAS - ); + + verbose("Frequency detected: %d MHz (%d) %s Channel \n\tCAS:%d tRC:%d tRP:%d RAS:%d (%d-%d-%d-%d)\n", + (uint32_t)Platform->RAM.Frequency / 1000000, + (uint32_t)Platform->RAM.Frequency / 500000, + memory_channel_types[Platform->RAM.Channels] + ,Platform->RAM.CAS, Platform->RAM.TRC, Platform->RAM.TRP, Platform->RAM.RAS + ,Platform->RAM.CAS, Platform->RAM.TRC, Platform->RAM.TRP, Platform->RAM.RAS + ); +#if DEBUG_DRAM + getc(); +#endif } } Index: branches/cparm/i386/modules/Memory/spd.h =================================================================== --- branches/cparm/i386/modules/Memory/spd.h (revision 1118) +++ branches/cparm/i386/modules/Memory/spd.h (revision 1119) @@ -11,8 +11,11 @@ #include "libsaio.h" bool is_smbus_controller(pci_dt_t* pci_dt); +#if UNUSED void scan_spd(PlatformInfo_t *p, pci_dt_t* smbus_controller_dev); - +#else +void scan_spd(pci_dt_t* smbus_controller_dev); +#endif struct smbus_controllers_t { uint32_t vendor; uint32_t device; Index: branches/cparm/i386/modules/Memory/Makefile =================================================================== --- branches/cparm/i386/modules/Memory/Makefile (revision 1118) +++ branches/cparm/i386/modules/Memory/Makefile (revision 1119) @@ -28,7 +28,7 @@ -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-lc_kext -libcc_kext DEFINES= CONFIG = hd @@ -70,6 +70,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/dram_controllers.o \ $(OBJROOT)/mem.o \ $(OBJROOT)/spd.o \ Index: branches/cparm/i386/modules/ACPICodec/acpi_codec.h =================================================================== --- branches/cparm/i386/modules/ACPICodec/acpi_codec.h (revision 0) +++ branches/cparm/i386/modules/ACPICodec/acpi_codec.h (revision 1119) @@ -0,0 +1,61 @@ +/* + * Copyright 2008 mackerintel + */ + +/* + * Copyright (c) 2011 cparm . All rights reserved. + * + */ + +#ifndef __LIBSAIO_ACPI_CODEC_H +#define __LIBSAIO_ACPI_CODEC_H + +#include "libsaio.h" +#include "efi.h" + +#define kOEMDSDT "oemDSDT" /* acpi_codec.c */ +#define kOEMFADT "oemFADT" /* acpi_codec.c */ + +#define kRestartFix "RestartFix" /* acpi_codec.c */ +#define kGeneratePStates "GeneratePStates" /* acpi_codec.c */ +#define kGenerateCStates "GenerateCStates" /* acpi_codec.c */ +#define kMaxRatio "MaxBusRatio" /* acpi_codec.c */ +#define kMinRatio "MinBusRatio" /* acpi_codec.c */ +#define kSpeedstep "EnableSpeedStep" /* acpi_codec.c */ +#define kEnableC4State "EnableC4State" /* acpi_codec.c */ + +#define kUpdateACPI "UpdateACPI" /* acpi_codec.c */ + +#if UNUSED +#define kGenerateFACS "GenerateFACS" /* acpi_codec.c */ +#define kOEMFACS "oemFACS" /* acpi_codec.c */ +#endif + +#define KIntelFADT "IntelFADTSpec" /* acpi_codec.c */ + +#define KResetType "ResetType" /* acpi_codec.c */ + +#define PCI_RESET_TYPE 0 // (default) +#define KEYBOARD_RESET_TYPE 1 + +#define OEMOPT_SIZE sizeof("oemXXXX") + +extern EFI_STATUS setupAcpi(); + +struct p_state +{ + union + { + uint16_t Control; + struct + { + uint8_t VID; // Voltage ID + uint8_t FID; // Frequency ID + }; + }; + + uint8_t CID; // Compare ID + uint32_t Frequency; +}; + +#endif /* !__LIBSAIO_ACPI_CODEC_H */ Property changes on: branches/cparm/i386/modules/ACPICodec/acpi_codec.h ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/modules/ACPICodec/aml_generator.c =================================================================== --- branches/cparm/i386/modules/ACPICodec/aml_generator.c (revision 0) +++ branches/cparm/i386/modules/ACPICodec/aml_generator.c (revision 1119) @@ -0,0 +1,562 @@ +/* + * aml_generator.c + * Chameleon + * + * Created by Mozodojo on 20/07/10. + * Copyright 2010 mozo. All rights reserved. + * + */ + +#include "aml_generator.h" + +bool aml_add_to_parent(struct aml_chunk* parent, struct aml_chunk* node) +{ + if (parent && node) + { + switch (parent->Type) + { + case AML_CHUNK_NONE: + case AML_CHUNK_BYTE: + case AML_CHUNK_WORD: + case AML_CHUNK_DWORD: + case AML_CHUNK_QWORD: + case AML_CHUNK_ALIAS: + verbose("aml_add_to_parent: Node isn't supports child nodes!\n"); + return false; + case AML_CHUNK_NAME: + if (parent->First) + { + verbose("aml_add_to_parent: Name node could have only one child node!\n"); + return false; + } + break; + + default: + break; + } + + if (!parent->First) + parent->First = node; + + if (parent->Last) + parent->Last->Next = node; + + parent->Last = node; + + return true; + } + + return false; +} + +struct aml_chunk* aml_create_node(struct aml_chunk* parent) +{ + struct aml_chunk* node = (struct aml_chunk*)malloc(sizeof(struct aml_chunk)); + + aml_add_to_parent(parent, node); + + return node; +} + +void aml_destroy_node(struct aml_chunk* node) +{ + // Delete child nodes + struct aml_chunk* child = node->First; + + while (child) + { + struct aml_chunk* next = child->Next; + + if (child->Buffer) + free(child->Buffer); + + free(child); + + child = next; + } + + // Free node + if (node->Buffer) + free(node->Buffer); + + free(node); +} + +struct aml_chunk* aml_add_buffer(struct aml_chunk* parent, const char* buffer, unsigned int size) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_NONE; + node->Length = size; + node->Buffer = malloc(node->Length); + memcpy(node->Buffer, buffer, node->Length); + } + + return node; +} + +struct aml_chunk* aml_add_byte(struct aml_chunk* parent, unsigned char value) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_BYTE; + + node->Length = 1; + node->Buffer = malloc(node->Length); + node->Buffer[0] = value; + } + + return node; +} + +struct aml_chunk* aml_add_word(struct aml_chunk* parent, unsigned int value) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_WORD; + node->Length = 2; + node->Buffer = malloc(node->Length); + node->Buffer[0] = value & 0xff; + node->Buffer[1] = value >> 8; + } + + return node; +} + +struct aml_chunk* aml_add_dword(struct aml_chunk* parent, unsigned long value) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_DWORD; + node->Length = 4; + node->Buffer = malloc(node->Length); + node->Buffer[0] = value & 0xff; + node->Buffer[1] = (value >> 8) & 0xff; + node->Buffer[2] = (value >> 16) & 0xff; + node->Buffer[3] = (value >> 24) & 0xff; + } + + return node; +} + +struct aml_chunk* aml_add_qword(struct aml_chunk* parent, unsigned long long value) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_QWORD; + node->Length = 8; + node->Buffer = malloc(node->Length); + node->Buffer[0] = value & 0xff; + node->Buffer[1] = (value >> 8) & 0xff; + node->Buffer[2] = (value >> 16) & 0xff; + node->Buffer[3] = (value >> 24) & 0xff; + node->Buffer[4] = (value >> 32) & 0xff; + node->Buffer[5] = (value >> 40) & 0xff; + node->Buffer[6] = (value >> 48) & 0xff; + node->Buffer[7] = (value >> 56) & 0xff; + } + + return node; +} + +unsigned int aml_fill_simple_name(char* buffer, const char* name) +{ + if (strlen(name) < 4) + { + verbose("aml_fill_simple_name: simple name %s has incorrect lengh! Must be 4\n", name); + return 0; + } + + memcpy(buffer, name, 4); + return 4; +} + +unsigned int aml_fill_name(struct aml_chunk* node, const char* name) +{ + if (!node) + return 0; + + int len = strlen(name), offset = 0, count = len / 4; + + if ((len % 4) > 1 || count == 0) + { + verbose("aml_fill_name: pathname %s has incorrect length! Must be 4, 8, 12, 16 etc.\n", name); + return 0; + } + + unsigned int root = 0; + + if ((len % 4) == 1 && name[0] == '\\') + root++; + + if (count == 1) + { + node->Length = 4 + root; + node->Buffer = malloc(node->Length); + memcpy(node->Buffer, name, 4 + root); + return node->Length; + } + + if (count == 2) + { + node->Length = 2 + 8; + node->Buffer = malloc(node->Length); + node->Buffer[offset++] = 0x5c; // Root Char + node->Buffer[offset++] = 0x2e; // Double name + memcpy(node->Buffer+offset, name + root, 8); + return node->Length; + } + + node->Length = 3 + count*4; + node->Buffer = malloc(node->Length); + node->Buffer[offset++] = 0x5c; // Root Char + node->Buffer[offset++] = 0x2f; // Multi name + node->Buffer[offset++] = count; // Names count + memcpy(node->Buffer+offset, name + root, count*4); + + return node->Length; +} + +struct aml_chunk* aml_add_scope(struct aml_chunk* parent, const char* name) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_SCOPE; + + aml_fill_name(node, name); + } + + return node; +} + +struct aml_chunk* aml_add_name(struct aml_chunk* parent, const char* name) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_NAME; + + aml_fill_name(node, name); + } + + return node; +} + +struct aml_chunk* aml_add_package(struct aml_chunk* parent) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_PACKAGE; + + node->Length = 1; + node->Buffer = malloc(node->Length); + } + + return node; +} + +struct aml_chunk* aml_add_package_with_value(struct aml_chunk* parent, uint64_t *lst, int num) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_PACKAGE; + node->Length = 1; + node->Buffer = malloc(node->Length); + aml_add_multiple_value(node,lst,num); + + } + + return node; +} + +void aml_add_value(struct aml_chunk* parent, uint64_t val) +{ + if (parent) + { + if (val > 0xffffffff) + aml_add_qword(parent,val); + else if (val > 0xffff) + aml_add_dword(parent,val); + else if (val > 0xff) + aml_add_word(parent,val); + else + aml_add_byte(parent, val); + } + +} + +void aml_add_multiple_value(struct aml_chunk* parent, uint64_t *lst, int num) +{ + if (parent) + { + int i; + for (i=0; i<(num / 8); i++) { + + aml_add_value(parent, lst[i]); + } + } + +} + +struct aml_chunk* aml_add_alias(struct aml_chunk* parent, const char* name1, const char* name2) +{ + struct aml_chunk* node = aml_create_node(parent); + + if (node) + { + node->Type = AML_CHUNK_ALIAS; + + node->Length = 8; + node->Buffer = malloc(node->Length); + aml_fill_simple_name(node->Buffer, name1); + aml_fill_simple_name(node->Buffer+4, name2); + } + + return node; +} + +unsigned char aml_get_size_length(unsigned int size) +{ + if (size + 1 <= 0x3f) + return 1; + else if (size + 2 <= 0x3fff) + return 2; + else if (size + 3 <= 0x3fffff) + return 3; + + return 4; +} + +unsigned int aml_calculate_size(struct aml_chunk* node) +{ + if (node) + { + node->Size = 0; + + // Calculate child nodes size + struct aml_chunk* child = node->First; + unsigned char child_count = 0; + + while (child) + { + child_count++; + + node->Size += aml_calculate_size(child); + + child = child->Next; + } + + switch (node->Type) + { + case AML_CHUNK_NONE: + node->Size += node->Length; + break; + case AML_CHUNK_SCOPE: + node->Size += 1 + node->Length; + node->Size += aml_get_size_length(node->Size); + break; + case AML_CHUNK_PACKAGE: + node->Buffer[0] = child_count; + node->Size += 1 + node->Length; + node->Size += aml_get_size_length(node->Size); + break; + + case AML_CHUNK_BYTE: + if (node->Buffer[0] == 0x0 || node->Buffer[0] == 0x1) + { + node->Size += node->Length; + } + else + { + node->Size += 1 + node->Length; + } + + break; + + case AML_CHUNK_WORD: + case AML_CHUNK_DWORD: + case AML_CHUNK_QWORD: + case AML_CHUNK_ALIAS: + case AML_CHUNK_NAME: + node->Size += 1 + node->Length; + break; + } + + return node->Size; + } + + return 0; +} + +unsigned int aml_write_byte(unsigned char value, char* buffer, unsigned int offset) +{ + buffer[offset++] = value; + + return offset; +} + +unsigned int aml_write_word(unsigned int value, char* buffer, unsigned int offset) +{ + buffer[offset++] = value & 0xff; + buffer[offset++] = value >> 8; + + return offset; +} + +unsigned int aml_write_dword(unsigned long value, char* buffer, unsigned int offset) +{ + buffer[offset++] = value & 0xff; + buffer[offset++] = (value >> 8) & 0xff; + buffer[offset++] = (value >> 16) & 0xff; + buffer[offset++] = (value >> 24) & 0xff; + + return offset; +} + +unsigned int aml_write_qword(unsigned long long value, char* buffer, unsigned int offset) +{ + buffer[offset++] = value & 0xff; + buffer[offset++] = (value >> 8) & 0xff; + buffer[offset++] = (value >> 16) & 0xff; + buffer[offset++] = (value >> 24) & 0xff; + buffer[offset++] = (value >> 32) & 0xff; + buffer[offset++] = (value >> 40) & 0xff; + buffer[offset++] = (value >> 48) & 0xff; + buffer[offset++] = (value >> 56) & 0xff; + + return offset; +} + +unsigned int aml_write_buffer(const char* value, unsigned int size, char* buffer, unsigned int offset) +{ + if (size > 0) + { + memcpy(buffer + offset, value, size); + } + + return offset + size; +} + +void aml_add_ressource_t_fxhw(struct aml_chunk* parent, uint64_t *lst) +{ + if (parent) { + char resource_template[] = + { + 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, + 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x79, 0x00 + }; + + char *buffer = resource_template; + unsigned int offset = aml_write_byte(lst[0], buffer, 8); + offset = aml_write_byte(lst[1], buffer, offset); + offset = aml_write_byte(lst[2], buffer, offset); + aml_write_qword(lst[3], buffer, offset); + aml_add_buffer(parent, buffer, sizeof(resource_template)); + } +} + +unsigned int aml_write_size(unsigned int size, char* buffer, unsigned int offset) +{ + if (size <= 0x3f) + { + buffer[offset++] = size; + } + else if (size <= 0x3fff) + { + buffer[offset++] = 0x40 | (size & 0xf); + buffer[offset++] = (size >> 4) & 0xff; + } + else if (size <= 0x3fffff) + { + buffer[offset++] = 0x80 | (size & 0xf); + buffer[offset++] = (size >> 4) & 0xff; + buffer[offset++] = (size >> 12) & 0xff; + } + else + { + buffer[offset++] = 0xc0 | (size & 0xf); + buffer[offset++] = (size >> 4) & 0xff; + buffer[offset++] = (size >> 12) & 0xff; + buffer[offset++] = (size >> 20) & 0xff; + } + + return offset; +} + +unsigned int aml_write_node(struct aml_chunk* node, char* buffer, unsigned int offset) +{ + if (node && buffer) + { + unsigned int old = offset; + + switch (node->Type) + { + case AML_CHUNK_NONE: + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + break; + + case AML_CHUNK_SCOPE: + case AML_CHUNK_PACKAGE: + offset = aml_write_byte(node->Type, buffer, offset); + offset = aml_write_size(node->Size-1, buffer, offset); + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + break; + + case AML_CHUNK_BYTE: + if (node->Buffer[0] == 0x0 || node->Buffer[0] == 0x1) + { + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + } + else + { + offset = aml_write_byte(node->Type, buffer, offset); + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + } + break; + + case AML_CHUNK_WORD: + case AML_CHUNK_DWORD: + case AML_CHUNK_QWORD: + case AML_CHUNK_ALIAS: + case AML_CHUNK_NAME: + offset = aml_write_byte(node->Type, buffer, offset); + offset = aml_write_buffer(node->Buffer, node->Length, buffer, offset); + break; + + default: + break; + } + + struct aml_chunk* child = node->First; + + while (child) + { + offset = aml_write_node(child, buffer, offset); + + child = child->Next; + } + + if (offset - old != node->Size) + verbose("Node size incorrect: 0x%x\n", node->Type); + } + + return offset; +} \ No newline at end of file Property changes on: branches/cparm/i386/modules/ACPICodec/aml_generator.c ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/modules/ACPICodec/acpidecode.c =================================================================== --- branches/cparm/i386/modules/ACPICodec/acpidecode.c (revision 0) +++ branches/cparm/i386/modules/ACPICodec/acpidecode.c (revision 1119) @@ -0,0 +1,913 @@ +/* +Copyright (c) 2010, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "acpi.h" +#include "acpidecode.h" + +#define DEBUG_ACPI_DECODE 0 + +#if DEBUG_ACPI_DECODE==1 +#include "libsaio.h" +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + +static U8 *parse_acpi_dataobject(const struct acpi_namespace *ns, U8 * current, U8 * end); +static U8 *parse_acpi_package(const struct acpi_namespace *ns, U8 * current, U8 * end); +static U8 *parse_acpi_termarg(const struct acpi_namespace *ns, U8 * current, U8 * end); +static U8 *parse_acpi_termarglist(const struct acpi_namespace *ns, U8 * current, U8 * end); +static U8 *parse_acpi_objectlist(const struct acpi_namespace *ns, U8 * current, U8 * end); +U8* UIDPointer = (U8*)0; + +void *decodeTableHeader(void *current, ACPI_TABLE_HEADER ** tableHeader) +{ + *tableHeader = current; + current = *tableHeader + 1; + return current; +} +void dprint_nameseg(U32 i) +{ + DBG("%c%c%c%c", + (int)(i & 0x000000ff), + (int)((i & 0x0000ff00) >> 8), + (int)((i & 0x00ff0000) >> 16), + (int)(i >> 24)); +} + +#if DEBUG_ACPI_DECODE +static void dprint_namespace(const struct acpi_namespace *ns) +{ + U32 i; + DBG( "\\"); + for (i = 0; i < ns->depth; i++) { + if (i != 0) + DBG( "."); + dprint_nameseg(ns->nameseg[i]); + } +} +#endif + +static void parsePackageLength(U8 * current, U32 * length, U32 * lengthEncoding) +{ + U32 i; + U8 len0 = *current; + U8 numBytes = len0 >> 6; + U32 total = 0; + + for (i = numBytes; i > 0; i--) { + total <<= 8; + total |= current[i]; + } + + total <<= 4; + total |= len0 & 0x3f; + *length = total; + *lengthEncoding = numBytes + 1; + DBG("Package length=0x%02x\n", *length); +} + +static bool ns_match(struct acpi_namespace *ns1, struct acpi_namespace *ns2) +{ + U32 i; + if (ns1->depth != ns2->depth) + return false; + + for (i = 0; i < ns1->depth; i++) + if (ns1->nameseg[i] != ns2->nameseg[i]) + return false; + + return true; +} + +U32 acpi_ns_found; + +static U8 *parse_acpi_namestring(const struct acpi_namespace *ns_context, struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *temp = current; + struct acpi_namespace dummy_ns; + + (void)end; + + if (!ns) + ns = &dummy_ns; + *ns = *ns_context; + + if (*current == AML_ROOT_PREFIX) { + ns->depth = 0; + current++; + } else + while (*current == AML_PARENT_PREFIX) { + if (ns->depth == 0) { + DBG( "Attempt to use parent prefix with no namespace left\n"); + return temp; + } + current++; + ns->depth--; + } + + switch (*current) { + case AML_DUAL_NAME_PREFIX: + if (ns->depth + 2 > ACPI_NAMESPACE_MAX_DEPTH) { + DBG( "Namespace got too deep\n"); + return temp; + } + current++; + ns->nameseg[ns->depth++] = *(U32 *) current; + current += 4; + ns->nameseg[ns->depth++] = *(U32 *) current; + current += 4; + break; + case AML_MULTI_NAME_PREFIX: + { + U8 nameseg_count; + current++; + nameseg_count = *current++; + if (ns->depth + nameseg_count > ACPI_NAMESPACE_MAX_DEPTH) { + DBG( "Namespace got too deep\n"); + return temp; + } + while (nameseg_count--) { + ns->nameseg[ns->depth++] = *(U32 *) current; + current += 4; + } + break; + } + case AML_NULL_NAME: + current++; + break; + default: + if (*current != '_' && (*current < 'A' || *current > 'Z')) { + DBG( "Invalid nameseg lead character: 0x%02x\n", *current); + return temp; + } + if (ns->depth + 1 > ACPI_NAMESPACE_MAX_DEPTH) { + DBG( "Namespace got too deep\n"); + return temp; + } + ns->nameseg[ns->depth++] = *(U32 *) current; + current += 4; + break; + } +#if DEBUG_ACPI_DECODE + DBG( "Found NameString: "); + dprint_namespace(ns); + DBG("\n"); +#endif + if (ns->nameseg[1] == NAMESEG("PCI0") && ns->nameseg[2] == NAMESEG("_UID")) { + UIDPointer = current; + } + + if (!acpi_ns_found) { + U32 index; + + for (index = 0; index < acpi_processor_count; index++) + if (ns_match(ns, &acpi_processors[index].ns)) { + acpi_ns_found = 1; + break; + } + } + return current; +} + +static U8 *parse_acpi_buffer(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U32 pkglen, lengthEncoding; + (void)ns; + (void)end; + if (*current != AML_BUFFER_OP) + return current; + current++; + parsePackageLength(current, &pkglen, &lengthEncoding); + current += pkglen; + return current; +} + +static U8 *parse_acpi_computationaldata(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *temp = current; + + current = parse_acpi_buffer(ns, current, end); + if (current != temp) + return current; + + switch (*current) { + case AML_BYTE_OP: + DBG("Found ByteOp\n"); + current += 1 + 1; + break; + case AML_WORD_OP: + DBG( "Found WordOp\n"); + current += 1 + 2; + break; + case AML_DWORD_OP: + DBG("Found DwordOp\n"); + current += 1 + 4; + break; + case AML_QWORD_OP: + DBG( "Found QwordOp\n"); + current += 1 + 8; + break; + case AML_STRING_OP: + DBG( "Found StringOp: \""); + current++; + while (*current) +#if DEBUG_ACPI_DECODE + if (*current < ' ' || *current > 0x7e) + printf( "\\x%02x", *current++); + else + printf( "%c", *current++); +#else + current++; +#endif + current++; /* Skip the \0 */ + DBG( "\"\n"); + break; + case AML_ZERO_OP: + DBG( "Found ZeroOp\n"); + current += 1; + break; + case AML_ONE_OP: + DBG( "Found OneOp\n"); + current += 1; + break; + case AML_ONES_OP: + DBG( "Found OneOp\n"); + current += 1; + break; + case AML_EXT_OP_PREFIX: + if (*(current + 1) == AML_REVISION_OP) + current += 2; + default: + break; + } + + return current; +} + +static U8 *parse_acpi_argobj(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + (void)ns; + (void)end; + switch (*current) { + case AML_ARG0_OP: + DBG( "Found Arg0Op\n"); + current++; + break; + case AML_ARG1_OP: + DBG( "Found Arg1Op\n"); + current++; + break; + case AML_ARG2_OP: + DBG( "Found Arg2Op\n"); + current++; + break; + case AML_ARG3_OP: + DBG( "Found Arg3Op\n"); + current++; + break; + case AML_ARG4_OP: + DBG( "Found Arg4Op\n"); + current++; + break; + case AML_ARG5_OP: + DBG( "Found Arg5Op\n"); + current++; + break; + case AML_ARG6_OP: + DBG( "Found Arg6Op\n"); + current++; + break; + default: + break; + } + return current; +} + +static U8 *parse_acpi_localobj(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + (void)ns; + (void)end; + switch (*current) { + case AML_LOCAL0_OP: + DBG( "Found Local0Op\n"); + current++; + break; + case AML_LOCAL1_OP: + DBG( "Found Local1Op\n"); + current++; + break; + case AML_LOCAL2_OP: + DBG( "Found Local2Op\n"); + current++; + break; + case AML_LOCAL3_OP: + DBG("Found Local3Op\n"); + current++; + break; + case AML_LOCAL4_OP: + DBG( "Found Local4Op\n"); + current++; + break; + case AML_LOCAL5_OP: + DBG( "Found Local5Op\n"); + current++; + break; + case AML_LOCAL6_OP: + DBG( "Found Local6Op\n"); + current++; + break; + case AML_LOCAL7_OP: + DBG( "Found Local7Op\n"); + current++; + break; + default: + break; + } + return current; +} + +static U8 *parse_acpi_debugobj(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + (void)ns; + (void)end; + if ((*current == AML_EXT_OP_PREFIX) && (*(current + 1) == AML_DEBUG_OP)) { + current += 2; + DBG( "Found DebugOp\n"); + } + + return current; +} + +static U8 *parse_acpi_datarefobject(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *temp = current; + + DBG( "Beginning datarefobject: 0x%02x at memory location %p\n", *current, current); + current = parse_acpi_dataobject(ns, current, end); + if (current != temp) + return current; + + return current; +} + +static U8 *parse_acpi_simplename(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *temp = current; + + current = parse_acpi_namestring(ns, NULL, current, end); + if (current != temp) + return current; + + current = parse_acpi_argobj(ns, current, end); + if (current != temp) + return current; + + current = parse_acpi_localobj(ns, current, end); + if (current != temp) + return current; + + return current; +} + +static U8 *parse_acpi_supername(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *temp = current; + + current = parse_acpi_simplename(ns, current, end); + if (current != temp) + return current; + + current = parse_acpi_debugobj(ns, current, end); + if (current != temp) + return current; + + return current; +} + +static U8 *parse_acpi_target(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *temp = current; + + current = parse_acpi_supername(ns, current, end); + if (current != temp) + return current; + + if (*current == AML_NULL_NAME) + current++; + + return current; +} + +static U8 *parse_acpi_method(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *new_end = current; + U8 *temp; + U32 pkglen; + U32 lengthEncoding; + struct acpi_namespace new_ns; + + (void)end; + + parsePackageLength(current, &pkglen, &lengthEncoding); + current += lengthEncoding; + new_end += pkglen; + + temp = current; + current = parse_acpi_namestring(ns, &new_ns, current, new_end); + if (current == temp) + return new_end; + +#if DEBUG_ACPI_DECODE + DBG( "Found Method: "); + dprint_namespace(&new_ns); + DBG( "\n"); +#endif + // U8 methodFlags + current++; + + parse_acpi_termlist(&new_ns, current, new_end); + +#if DEBUG_ACPI_DECODE + DBG( "End of Method: "); + dprint_namespace(&new_ns); + DBG( "\n"); +#endif + + return new_end; +} + +U32 acpi_processor_count; +struct acpi_processor acpi_processors[CPU_MAP_LIMIT]; + +static void add_processor(const struct acpi_namespace *ns, U8 id, U32 pmbase) +{ + if (acpi_processor_count == CPU_MAP_LIMIT) { + DBG( "No more room for ACPI processor structures\n"); + return; + } + acpi_processors[acpi_processor_count].ns = *ns; + acpi_processors[acpi_processor_count].id = id; + acpi_processors[acpi_processor_count].pmbase = pmbase; + acpi_processor_count++; +} + +static U8 *parse_acpi_processor(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *new_end = current; + U8 *temp; + U32 pkglen; + U32 lengthEncoding; + struct acpi_namespace new_ns; + U8 id; + U32 pmbase; + + (void)end; + + parsePackageLength(current, &pkglen, &lengthEncoding); + current += lengthEncoding; + new_end += pkglen; + + temp = current; + current = parse_acpi_namestring(ns, &new_ns, current, new_end); + if (current == temp) + return new_end; + + id = *current++; + pmbase = *(U32 *) current; + current += 4; + +#if DEBUG_ACPI_DECODE + DBG( "Found CPU object: "); + dprint_namespace(&new_ns); + DBG( " id = 0x%x pmbase = 0x%x\n", id, pmbase); +#endif + add_processor(&new_ns, id, pmbase); + + return new_end; +} + +static U8 *parse_acpi_namedobj(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + DBG( "Beginning namedobj: 0x%02x at memory location %p\n", *current, current); + switch (*current) { + case AML_EXT_OP_PREFIX: + { + if (*(current + 1) == AML_MUTEX_OP) { + struct acpi_namespace new_ns; + + current += 2; + current = parse_acpi_namestring(ns, &new_ns, current, end); +#if DEBUG_ACPI_DECODE + DBG( "Mutex: "); + dprint_namespace(&new_ns); + DBG( "\n"); +#endif + current++; /* SyncFlags */ + } else if (*(current + 1) == AML_OPREGION_OP) { + struct acpi_namespace new_ns; + + current += 2; + DBG( "OpRegion at memory location %p\n", current); + current = parse_acpi_namestring(ns, &new_ns, current, end); +#if DEBUG_ACPI_DECODE + DBG( "OpRegion name: "); + dprint_namespace(&new_ns); + DBG( "\n"); +#endif + current++; + current = parse_acpi_termarg(ns, current, end); + current = parse_acpi_termarg(ns, current, end); +#if DEBUG_ACPI_DECODE + DBG( "End OpRegion: "); + dprint_namespace(&new_ns); + DBG( "\n"); +#endif + } else if (*(current + 1) == AML_FIELD_OP) { + U32 pkglen; + U32 lengthEncoding; + + current += 2; + DBG( "FieldOp at memory location %p\n", current); + parsePackageLength(current, &pkglen, &lengthEncoding); + current += pkglen; + } else if (*(current + 1) == AML_DEVICE_OP) { + U8 *new_end; + U32 pkglen; + U32 lengthEncoding; + struct acpi_namespace new_ns; + + current += 2; + new_end = current; + DBG( "DeviceOp at memory location %p\n", current); + parsePackageLength(current, &pkglen, &lengthEncoding); + current += lengthEncoding; + new_end += pkglen; + current = parse_acpi_namestring(ns, &new_ns, current, new_end); +#if DEBUG_ACPI_DECODE + DBG( "DeviceOp name: "); + dprint_namespace(&new_ns); + DBG( "\n"); +#endif + + current = parse_acpi_objectlist(&new_ns, current, new_end); + current = new_end; + } else if (*(current + 1) == AML_PROCESSOR_OP) { + current += 2; + current = parse_acpi_processor(ns, current, end); + } else if (*(current + 1) == AML_INDEXFIELD_OP) { + U8 *new_end; + U32 pkglen; + U32 lengthEncoding; + struct acpi_namespace new_ns; + + current += 2; + new_end = current; + DBG( "IndexFieldOp at memory location %p\n", current); + parsePackageLength(current, &pkglen, &lengthEncoding); + current += lengthEncoding; + new_end += pkglen; + current = parse_acpi_namestring(ns, &new_ns, current, new_end); +#if DEBUG_ACPI_DECODE + DBG( "IndexFieldOp name: "); + dprint_namespace(&new_ns); + DBG( "\n"); +#endif + current = parse_acpi_objectlist(&new_ns, current, new_end); + current = new_end; + } + break; + } + case AML_METHOD_OP: + { + current++; + current = parse_acpi_method(ns, current, end); + break; + } + default: + break; + } + return current; +} + +static U8 *parse_acpi_type1opcode(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + DBG( "Beginning type1opcode: 0x%02x at memory location %p\n", *current, current); + switch (*current) { + case AML_IF_OP: + { + U8 *new_end; + U32 pkgLen; + U32 lengthEncoding; + + DBG( "Found IfOp\n"); + current++; + parsePackageLength(current, &pkgLen, &lengthEncoding); + new_end = current + pkgLen; + current += lengthEncoding; + + current = parse_acpi_termarg(ns, current, new_end); + parse_acpi_termlist(ns, current, new_end); + current = new_end; + break; + } + case AML_ELSE_OP: + { + U8 *new_end; + U32 pkgLen; + U32 lengthEncoding; + + DBG( "Found ElseOp\n"); + current++; + parsePackageLength(current, &pkgLen, &lengthEncoding); + new_end = current + pkgLen; + current += lengthEncoding; + + parse_acpi_termlist(ns, current, new_end); + current = new_end; + break; + } + case AML_RETURN_OP: + { + DBG( "Found ReturnOp\n"); + current++; + current = parse_acpi_termarg(ns, current, end); + break; + } + default: + break; + } + return current; +} + +static U8 *parse_acpi_type2opcode(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *temp = current; + + DBG( "Beginning type2opcode: 0x%02x at memory location %p\n", *current, current); + + current = parse_acpi_package(ns, current, end); + if (current != temp) + return current; + + switch (*current) { + case AML_LNOT_OP: + current++; + DBG( "Found logical not operator\n"); + current = parse_acpi_termarg(ns, current, end); + break; + + case AML_LAND_OP: + case AML_LOR_OP: + case AML_LEQUAL_OP: + case AML_LGREATER_OP: + case AML_LLESS_OP: + DBG( "Found logical binary operator: %c\n", "&|!=><"[*current - AML_LAND_OP]); + current++; + current = parse_acpi_termarg(ns, current, end); + current = parse_acpi_termarg(ns, current, end); + break; + + case AML_EXT_OP_PREFIX: + { + if (*(current + 1) == AML_COND_REF_OF_OP) { + DBG( "Found CondRefOf\n"); + current += 2; + current = parse_acpi_supername(ns, current, end); + current = parse_acpi_target(ns, current, end); + } + break; + } + case AML_STORE_OP: + { + DBG( "Found StoreOp\n"); + current++; + current = parse_acpi_termarg(ns, current, end); + current = parse_acpi_supername(ns, current, end); + break; + } + default: + { + current = parse_acpi_namestring(ns, NULL, current, end); + if (current == temp) + break; + current = parse_acpi_termarglist(ns, current, end); + } + } + return current; +} + +static U8 *parse_acpi_package(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + (void)ns; + (void)end; + if (*current == AML_PACKAGE_OP) { + U32 pkglen; + U32 lengthEncoding; + + DBG( "Found PackageOp\n"); + current++; + parsePackageLength(current, &pkglen, &lengthEncoding); + current += pkglen; + } + return current; +} + +static U8 *parse_acpi_dataobject(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *temp = current; + + current = parse_acpi_computationaldata(ns, current, end); + if (current != temp) + return current; + + current = parse_acpi_package(ns, current, end); + if (current != temp) + return current; + + return current; +} + +static U8 *parse_acpi_termarg(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + U8 *temp = current; + + DBG( "Beginning termarg: 0x%02x at memory location %p\n", *current, current); + + current = parse_acpi_type2opcode(ns, current, end); + if (current != temp) + return current; + + current = parse_acpi_dataobject(ns, current, end); + if (current != temp) + return current; + + current = parse_acpi_argobj(ns, current, end); + if (current != temp) + return current; + + current = parse_acpi_localobj(ns, current, end); + if (current != temp) + return current; + + return current; +} + +static U8 *parse_acpi_namespacemodifierobj(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + DBG( "Beginning namespacemodifierobj: 0x%02x at memory location %p\n", *current, current); + switch (*current) { + case AML_SCOPE_OP: + { + U8 *new_end; + struct acpi_namespace new_ns; + U32 scopeLen; + U32 lengthEncoding; + + current++; + parsePackageLength(current, &scopeLen, &lengthEncoding); + new_end = current + scopeLen; + + current = parse_acpi_namestring(ns, &new_ns, current + lengthEncoding, new_end); +#if DEBUG_ACPI_DECODE + DBG( "Found Scope: "); + dprint_namespace(&new_ns); + DBG( "\n"); +#endif + parse_acpi_termlist(&new_ns, current, new_end); +#if DEBUG_ACPI_DECODE + DBG( "End Scope: "); + dprint_namespace(&new_ns); + DBG( "\n"); +#endif + current = new_end; + break; + } + case AML_NAME_OP: + current++; + current = parse_acpi_namestring(ns, NULL, current, end); + current = parse_acpi_datarefobject(ns, current, end); + break; + case AML_ALIAS_OP: + current++; + current = parse_acpi_namestring(ns, NULL, current, end); + current = parse_acpi_namestring(ns, NULL, current, end); + break; + default: + break; + } + return current; +} + +static U8 *parse_acpi_objectlist(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + DBG( "Beginning objectlist: 0x%02x at memory location %p end=%p\n", *current, current, end); + while (current < end) { + U8 *temp = current; + + DBG( "New iteration of objectlist: 0x%02x at memory location %p end=%p\n", *current, current, end); + + current = parse_acpi_namespacemodifierobj(ns, current, end); + if (current != temp) + continue; + + current = parse_acpi_namedobj(ns, current, end); + if (current != temp) + continue; + + if (current == temp) { + DBG( "Unhandled object in object list: 0x%02x at memory location %p\n", *current, current); +#if DEBUG_ACPI_DECODE + DBG( "namespace: "); + dprint_namespace(ns); + DBG( "\n"); +#endif + break; + } + } + DBG( "Ending objectlist: 0x%02x at memory location %p\n", *current, current); + return current; +} + +static U8 *parse_acpi_termarglist(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + DBG( "Beginning termarglist: 0x%02x at memory location %p\n", *current, current); + while (current < end) { + U8 *temp = current; + + current = parse_acpi_termarg(ns, current, end); + if (current == temp) { + DBG( "Unhandled item in term arg list: 0x%02x at memory location %p\n", *current, current); +#if DEBUG_ACPI_DECODE + DBG( "namespace: "); + dprint_namespace(ns); + DBG( "\n"); +#endif + break; + } + } + return current; +} + +void parse_acpi_termlist(const struct acpi_namespace *ns, U8 * current, U8 * end) +{ + while (current < end) { + U8 *temp = current; + + DBG( "Beginning new term in term list: 0x%02x at memory location %p\n", *current, current); + + current = parse_acpi_namespacemodifierobj(ns, current, end); + if (current != temp) + continue; + + current = parse_acpi_namedobj(ns, current, end); + if (current != temp) + continue; + + current = parse_acpi_type1opcode(ns, current, end); + if (current != temp) + continue; + + current = parse_acpi_type2opcode(ns, current, end); + if (current != temp) + continue; + + switch (*current) { + default: + { + DBG( "Unhandled item in term list: 0x%02x at memory location %p\n", *current, current); +#if DEBUG_ACPI_DECODE + DBG( "namespace: "); + dprint_namespace(ns); + DBG( "\n"); +#endif + return; + } + } + } +} Property changes on: branches/cparm/i386/modules/ACPICodec/acpidecode.c ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/modules/ACPICodec/aml_generator.h =================================================================== --- branches/cparm/i386/modules/ACPICodec/aml_generator.h (revision 0) +++ branches/cparm/i386/modules/ACPICodec/aml_generator.h (revision 1119) @@ -0,0 +1,65 @@ +/* + * aml_generator.h + * Chameleon + * + * Created by Mozodojo on 20/07/10. + * Copyright 2010 mozo. All rights reserved. + * + */ + +#ifndef __LIBSAIO_AML_GENERATOR_H +#define __LIBSAIO_AML_GENERATOR_H + +#include "libsaio.h" + +#define AML_CHUNK_NONE 0xff +#define AML_CHUNK_ZERO 0x00 +#define AML_CHUNK_ONE 0x01 +#define AML_CHUNK_ALIAS 0x06 +#define AML_CHUNK_NAME 0x08 +#define AML_CHUNK_BYTE 0x0A +#define AML_CHUNK_WORD 0x0B +#define AML_CHUNK_DWORD 0x0C +#define AML_CHUNK_STRING 0x0D +#define AML_CHUNK_QWORD 0x0E +#define AML_CHUNK_SCOPE 0x10 +#define AML_CHUNK_PACKAGE 0x12 + +struct aml_chunk +{ + unsigned char Type; + unsigned int Length; + char* Buffer; + + unsigned int Size; + + struct aml_chunk* Next; + struct aml_chunk* First; + struct aml_chunk* Last; +}; + +static inline bool aml_isvalidchar(char c) +{ + return isupper(c) || isdigit(c) || c == '_'; +}; + +bool aml_add_to_parent(struct aml_chunk* parent, struct aml_chunk* node); +struct aml_chunk* aml_create_node(struct aml_chunk* parent); +void aml_destroy_node(struct aml_chunk* node); +struct aml_chunk* aml_add_buffer(struct aml_chunk* parent, const char* buffer, unsigned int size); +struct aml_chunk* aml_add_byte(struct aml_chunk* parent, unsigned char value); +struct aml_chunk* aml_add_word(struct aml_chunk* parent, unsigned int value); +struct aml_chunk* aml_add_dword(struct aml_chunk* parent, unsigned long value); +struct aml_chunk* aml_add_qword(struct aml_chunk* parent, unsigned long long value); +struct aml_chunk* aml_add_scope(struct aml_chunk* parent, const char* name); +struct aml_chunk* aml_add_name(struct aml_chunk* parent, const char* name); +struct aml_chunk* aml_add_package(struct aml_chunk* parent); +struct aml_chunk* aml_add_alias(struct aml_chunk* parent, const char* name1, const char* name2); +unsigned int aml_calculate_size(struct aml_chunk* node); +unsigned int aml_write_node(struct aml_chunk* node, char* buffer, unsigned int offset); +struct aml_chunk* aml_add_package_with_value(struct aml_chunk* parent, uint64_t *lst, int num); +void aml_add_multiple_value(struct aml_chunk* parent, uint64_t *lst, int num); +void aml_add_ressource_t_fxhw(struct aml_chunk* parent, uint64_t *lst); +void aml_add_value(struct aml_chunk* parent, uint64_t val); + +#endif /* !__LIBSAIO_AML_GENERATOR_H */ \ No newline at end of file Property changes on: branches/cparm/i386/modules/ACPICodec/aml_generator.h ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/modules/ACPICodec/acpidecode.h =================================================================== --- branches/cparm/i386/modules/ACPICodec/acpidecode.h (revision 0) +++ branches/cparm/i386/modules/ACPICodec/acpidecode.h (revision 1119) @@ -0,0 +1,67 @@ +/* +Copyright (c) 2010, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef ACPI_DECODE_H +#define ACPI_DECODE_H + +#include "acpi_tools.h" + +/* acpidecode.h contains functions needed only for decoding ACPI to produce the + * inputs to the PPM code, but not needed for encoding ACPI as done inside the + * PPM code. */ + +#define ACPI_NAMESPACE_MAX_DEPTH 10 + +struct acpi_namespace { + U32 nameseg[ACPI_NAMESPACE_MAX_DEPTH]; + U32 depth; +}; + +void dprint_nameseg(U32 i); +void *decodeTableHeader(void *current, ACPI_TABLE_HEADER ** tableHeader); +void parse_acpi_termlist(const struct acpi_namespace *ns, U8 * current, U8 * end); + +/* Globals used for retrieving ACPI processor structures from the DSDT */ + +#define CPU_MAP_LIMIT 256 /* Any bigger than 256 and we'd have to support the x2APIC structures, which we don't yet anyway. */ + +struct acpi_processor { + struct acpi_namespace ns; + U8 id; + U32 pmbase; +}; + +extern U32 acpi_processor_count; +extern struct acpi_processor acpi_processors[CPU_MAP_LIMIT]; + +/* If 0, look for a processor namespace and set to 1 if found. */ +extern U32 acpi_ns_found; + +extern U8* UIDPointer; + +#endif /* ACPI_DECODE_H */ Property changes on: branches/cparm/i386/modules/ACPICodec/acpidecode.h ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/modules/ACPICodec/acpicode.c =================================================================== --- branches/cparm/i386/modules/ACPICodec/acpicode.c (revision 0) +++ branches/cparm/i386/modules/ACPICodec/acpicode.c (revision 1119) @@ -0,0 +1,611 @@ +/* +Copyright (c) 2010, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "datatype.h" +#include "acpi.h" +#include "ppm.h" +#include "acpicode.h" + +static void setPackage(ACPI_PACKAGE * package, U8 numElements); +static void setNamePath(ACPI_NAME_PATH * namePath, U32 name); + +void SetChecksum(struct acpi_table_header *header) +{ + header->Checksum = 0; + header->Checksum = 0 - GetChecksum(header, header->Length); +} + +void setRsdpchecksum(ACPI_TABLE_RSDP *rsdp) +{ + rsdp->Checksum = 0; + rsdp->Checksum = 0 - GetChecksum(rsdp, ACPI_RSDP_REV0_SIZE); +} + +void setRsdpXchecksum(ACPI_TABLE_RSDP *rsdp) +{ + rsdp->ExtendedChecksum = 0; + rsdp->ExtendedChecksum = 0 - GetChecksum(rsdp, rsdp->Length); +} + +void update_rsdp_with_xsdt(ACPI_TABLE_RSDP *rsdp, ACPI_TABLE_XSDT *xsdt) +{ + rsdp->XsdtPhysicalAddress = ((U64)((U32)xsdt)); + + setRsdpXchecksum(rsdp); +} + +void update_rsdp_with_rsdt(ACPI_TABLE_RSDP *rsdp, ACPI_TABLE_RSDT *rsdt) +{ + rsdp->RsdtPhysicalAddress = (U32)rsdt; + + setRsdpchecksum(rsdp); + +} + +//----------------------------------------------------------------------------- +U32 ProcessMadt(ACPI_TABLE_MADT * madt, MADT_INFO * madt_info) +{ + void *current; + void *end; + + // Quick sanity check for a valid MADT + if (madt == 0ul) + return (0ul); + + madt_info->lapic_count = 0; + + // Search MADT for Sub-tables with needed data + current = madt + 1; + end = (U8 *) madt + madt->Header.Length; + + while (current < end) { + ACPI_SUBTABLE_HEADER *subtable = current; + + switch (subtable->Type) { + case ACPI_MADT_TYPE_LOCAL_APIC: + { + // Process sub-tables with Type as 0: Processor Local APIC + ACPI_MADT_LOCAL_APIC *lapic = current; + current = lapic + 1; + + if (!(lapic->LapicFlags & ACPI_MADT_ENABLED)) + continue; + + { + LAPIC_INFO *lapic_info = &madt_info->lapic[madt_info->lapic_count]; + + lapic_info->processorId = lapic->ProcessorId; + lapic_info->apicId = lapic->Id; + lapic_info->madt_type = ACPI_MADT_TYPE_LOCAL_APIC; + } + + madt_info->lapic_count++; + + // Sanity check to verify compile time limit for max logical CPU is not exceeded + if (madt_info->lapic_count > MAX_LOGICAL_CPU) + return (0); + + break; + } + case ACPI_MADT_TYPE_X2APIC: + { + // Process sub-tables with Type as 9: Processor X2APIC + ACPI_MADT_X2APIC *x2apic = current; + current = x2apic + 1; + + if (!(x2apic->x2apicFlags & ACPI_MADT_ENABLED)) + continue; + + { + LAPIC_INFO *lapic_info = &madt_info->lapic[madt_info->lapic_count]; + + lapic_info->uid = x2apic->UID; + lapic_info->apicId = x2apic->x2apicId; + lapic_info->madt_type = ACPI_MADT_TYPE_X2APIC; + } + + madt_info->lapic_count++; + + // Sanity check to verify compile time limit for max logical CPU is not exceeded + if (madt_info->lapic_count > MAX_LOGICAL_CPU) + return (0); + + break; + } + default: + { + // Process all other sub-tables + current = (U8 *) subtable + subtable->Length; + break; + } + } // switch + + } // while + + return (1); +} + +//------------------------------------------------------------------------------- +U32 ProcessDsdt(ACPI_TABLE_DSDT * DsdtPointer, U8 * PCIUIDPointer, U8 uid) +{ + // 1. Sanity check + // 2. Replace UID value with the new value + // 3. Update the checksum of the DSDT + + { + // 1. Sanity check + if ((memcmp(&uid, PCIUIDPointer, sizeof(U8)) == 0) || (PCIUIDPointer == (U8*)0) || (DsdtPointer == (void*)0ul)) + return (0); + } + + { + // 2. Replace UID value with the new value + buildOpCode((void*)PCIUIDPointer, uid); + } + + { + // 3. Update the checksum of the DSDT + SetChecksum(&DsdtPointer->Header); + } + + return (1); +} + +//------------------------------------------------------------------------------- +void MoveRsdtInsertSsdt(ACPI_TABLE_RSDP * RsdPointer, ACPI_TABLE_RSDT * OldRsdtPointer, ACPI_TABLE_RSDT * NewRsdtPointer, ACPI_TABLE_SSDT * SsdtPointer) +{ + // 1. Move the RSDT in memory to the new location + // 2. Add new pointer for the SSDT into the RSDT + // 3. Update the size of the RSDT + // 4. Update the checksum of the RSDT + // 5. Update the RSDT pointer in the RSDP + // 6. Update the checksum of the RSDP + + { + // 1. Move the RSDT in memory to the new location + memcpy(NewRsdtPointer, OldRsdtPointer, OldRsdtPointer->Header.Length); + } + + { + // 2. Add new pointer for the SSDT into the RSDT + // 3. Update the size of the RSDT + // 4. Update the checksum of the RSDT + InsertSsdt(NewRsdtPointer, SsdtPointer); + } + + { + // 5. Update the RSDT pointer in the RSDP + RsdPointer->RsdtPhysicalAddress = (U32) NewRsdtPointer; + } + + { + // 6. Update the checksum of the RSDP + setRsdpchecksum(RsdPointer); + } +} + +//------------------------------------------------------------------------------- +void InsertSsdt(ACPI_TABLE_RSDT * RsdtPointer, ACPI_TABLE_SSDT * SsdtPointer) +{ + // 1. Add new pointer for the SSDT into the RSDT + // 2. Update the size of the RSDT + // 3. Update the checksum of the RSDT + + { + // 1. Add new pointer for the SSDT into the RSDT + U32 index = get_num_tables(RsdtPointer); + RsdtPointer->TableOffsetEntry[index] = (U32) SsdtPointer; + } + + { + // 2. Update the size of the RSDT + RsdtPointer->Header.Length = RsdtPointer->Header.Length + sizeof(ACPI_TABLE_SSDT *); + } + + { + // 3. Update the checksum of the RSDT + SetChecksum(&RsdtPointer->Header); + } +} + +//------------------------------------------------------------------------------- +void InsertSsdt64(ACPI_TABLE_XSDT * XsdtPointer, ACPI_TABLE_SSDT * SsdtPointer) +{ + { + void *null = 0ul; + if (XsdtPointer == null) + return; + } + + // 1. Add new pointer for the SSDT into the XSDT + // 2. Update the size of the XSDT + // 3. Update the checksum of the XSDT + + { + // 1. Add new pointer for the SSDT into the XSDT + U32 index = get_num_tables64(XsdtPointer); + XsdtPointer->TableOffsetEntry[index] = (U64) ((U32) SsdtPointer); + } + + { + // 2. Update the size of the XSDT + XsdtPointer->Header.Length = XsdtPointer->Header.Length + sizeof(U64); + } + + { + // 3. Update the checksum of the XSDT + SetChecksum(&XsdtPointer->Header); + } +} + +//----------------------------------------------------------------------------- +void *buildNameSeg(void *current, U32 name) +{ + U32 *nameSeg = current; + current = nameSeg + 1; + + *nameSeg = name; + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildOpCode(void *current, U8 opCode) +{ + U8 *op = current; + current = op + 1; + + *op = opCode; + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildReturnPackage(void *current, U8 numElements) +{ + ACPI_RETURN_PACKAGE *returnPackage = current; + current = returnPackage + 1; + + returnPackage->returnOpcode = AML_RETURN_OP; + setPackage(&returnPackage->package, numElements); + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildReturnZero(void *current) +{ + ACPI_RETURN_ZERO *returnZero = current; + current = returnZero + 1; + + returnZero->returnOpcode = AML_RETURN_OP; + returnZero->zeroOpcode = AML_ZERO_OP; + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildReturnOpcode(void *current, U8 opcodeToReturn) +{ + ACPI_RETURN_OPCODE *returnOpcode = current; + current = returnOpcode + 1; + + returnOpcode->returnOpcode = AML_RETURN_OP; + returnOpcode->opcodeToReturn = opcodeToReturn; + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildMethod(void *current, U32 name, U8 methodFlags) +{ + ACPI_METHOD *method = current; + current = method + 1; + + method->methodOpcode = AML_METHOD_OP; + method->name = name; + method->methodFlags = methodFlags; + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildSmallMethod(void *current, U32 name, U8 methodFlags) +{ + ACPI_SMALL_METHOD *method = current; + current = method + 1; + + method->methodOpcode = AML_METHOD_OP; + method->name = name; + method->methodFlags = methodFlags; + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildNamedDword(void *current, U32 name, U32 dword) +{ + ACPI_NAMED_DWORD *namedDword = current; + current = namedDword + 1; + + setNamePath(&namedDword->namePath, name); + setDwordConst(&namedDword->dword, dword); + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildGenericRegister(void *current, const ACPI_GENERIC_ADDRESS * gas) +{ + ACPI_GENERIC_REGISTER *genReg = current; + current = genReg + 1; + + genReg->genericRegisterField = AML_GEN_REG_FIELD; + genReg->pkgLength.packageLength0 = 0x0c; + genReg->pkgLength.packageLength1 = 0; + + genReg->gas.SpaceId = gas->SpaceId; + genReg->gas.BitWidth = gas->BitWidth; + genReg->gas.BitOffset = gas->BitOffset; + genReg->gas.AccessWidth = gas->AccessWidth; + genReg->gas.Address = gas->Address; + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildSmallBuffer(void *current) +{ + ACPI_SMALL_BUFFER *buffer = current; + current = buffer + 1; + + buffer->bufferOpcode = AML_BUFFER_OP; + + return (current); +} + +//----------------------------------------------------------------------------- +void *buildEndTag(void *current) +{ + ACPI_END_TAG *endTag = current; + current = endTag + 1; + + endTag->endTagField = AML_END_TAG_OP; + endTag->checksum = 0; + + return (current); +} + +//----------------------------------------------------------------------------- +void setSmallPackage(ACPI_SMALL_PACKAGE * package, U8 numElements) +{ + package->packageOpcode = AML_PACKAGE_OP; + package->numElements = numElements; +} + +//----------------------------------------------------------------------------- +void *buildSmallPackage(void *current, U8 numElements) +{ + ACPI_SMALL_PACKAGE *package = current; + current = package + 1; + setSmallPackage(package, numElements); + return (current); +} + +//----------------------------------------------------------------------------- +static void setPackage(ACPI_PACKAGE * package, U8 numElements) +{ + package->packageOpcode = AML_PACKAGE_OP; + package->numElements = numElements; +} + +//----------------------------------------------------------------------------- +void setPackageLength(ACPI_PACKAGE_LENGTH * packageLength, U32 length) +{ + packageLength->packageLength0 = 0x40 + (U8) (length & 0xf); + packageLength->packageLength1 = (U8) (length >> 4); +} + +//----------------------------------------------------------------------------- +void *buildPackageLength(void *current, U32 length) +{ + ACPI_PACKAGE_LENGTH *packageLength = current; + current = packageLength + 1; + setPackageLength(packageLength, length); + return (current); +} + +//----------------------------------------------------------------------------- +static void setNamePath(ACPI_NAME_PATH * namePath, U32 name) +{ + namePath->nameOpcode = AML_NAME_OP; + namePath->name = name; +} + +//----------------------------------------------------------------------------- +void *buildNamePath(void *current, U32 name) +{ + ACPI_NAME_PATH *namePath = current; + current = namePath + 1; + setNamePath(namePath, name); + return (current); +} + +//----------------------------------------------------------------------------- +static void setTableHeader(ACPI_TABLE_HEADER * tableHeader, U32 signature, U64 oemTableId) +{ + *(U32 *) &tableHeader->Signature = signature; + tableHeader->Length = 0; + tableHeader->Revision = 1; + tableHeader->Checksum = 0; + memcpy(&tableHeader->OemId[0], "INTEL ", 6); + *(U64 *) (tableHeader->OemTableId) = oemTableId; + tableHeader->OemRevision = 0x80000001; + *(U32 *) tableHeader->AslCompilerId = NAMESEG("INTL"); // ASCII ASL compiler vendor ID + tableHeader->AslCompilerRevision = 0x20061109; // ASL compiler version +} + +//----------------------------------------------------------------------------- +void *buildTableHeader(void *current, U32 signature, U64 oemTableId) +{ + ACPI_TABLE_HEADER *tableHeader = current; + current = tableHeader + 1; + setTableHeader(tableHeader, signature, oemTableId); + return (current); +} + +//----------------------------------------------------------------------------- +void setByteConst(ACPI_BYTE_CONST * byteConst, U8 byteData) +{ + byteConst->byteOpcode = AML_BYTE_OP; + byteConst->byteData = byteData; +} + +//----------------------------------------------------------------------------- +void *buildByteConst(void *current, U8 byteData) +{ + ACPI_BYTE_CONST *byteConst = current; + current = byteConst + 1; + setByteConst(byteConst, byteData); + return (current); +} + +//----------------------------------------------------------------------------- +void setWordConst(ACPI_WORD_CONST * wordConst, U16 wordData) +{ + wordConst->wordOpcode = AML_WORD_OP; + wordConst->wordData = wordData; +} + +//----------------------------------------------------------------------------- +void *buildWordConst(void *current, U16 wordData) +{ + ACPI_WORD_CONST *wordConst = current; + current = wordConst + 1; + setWordConst(wordConst, wordData); + return (current); +} + +//----------------------------------------------------------------------------- +void setDwordConst(ACPI_DWORD_CONST * dwordConst, U32 dwordData) +{ + dwordConst->dwordOpcode = AML_DWORD_OP; + dwordConst->dwordData = dwordData; +} + +//----------------------------------------------------------------------------- +void *buildDwordConst(void *current, U32 dwordData) +{ + ACPI_DWORD_CONST *dwordConst = current; + current = dwordConst + 1; + setDwordConst(dwordConst, dwordData); + return (current); +} + +//------------------------------------------------------------------------------- +U32 ProcessFadt(ACPI_TABLE_FADT * FadtPointer, U32 pmbase) +{ + { + // Update fields in FADT + + // Update ACPI 1.0 fields first + + FadtPointer->Pm1aEventBlock = pmbase; + FadtPointer->Pm1aControlBlock = pmbase + 4; + FadtPointer->Pm2ControlBlock = pmbase + 0x50; + FadtPointer->PmTimerBlock = pmbase + 8; + FadtPointer->Pm1EventLength = 4; + FadtPointer->Pm1ControlLength = 2; + FadtPointer->Pm2ControlLength = 1; + FadtPointer->PmTimerLength = 4; + + // No legacy C2 + FadtPointer->C2Latency = 101; + + // No legacy C3 + FadtPointer->C3Latency = 1001; + + // C1 power state is supported on all processors + FadtPointer->BootFlags |= 1UL << 2; + + // No legacy C2 on MP systems + FadtPointer->BootFlags &= ~(1UL << 3); + + // Update ACPI 2.0+ fields if supported + if (FadtPointer->Header.Revision >= 3) { + // Address space where struct or register exists - System IO + FadtPointer->XPm1aEventBlock.SpaceId = 1; + // Size in bits of given register + FadtPointer->XPm1aEventBlock.BitWidth = 0x20; + // Bit offset within the register + FadtPointer->XPm1aEventBlock.BitOffset = 0; + // Minimum Access size (ACPI 3.0) + FadtPointer->XPm1aEventBlock.AccessWidth = 0; + // 64-bit address of struct or register + FadtPointer->XPm1aEventBlock.Address = pmbase; + + // Address space where struct or register exists - System IO + FadtPointer->XPm1aControlBlock.SpaceId = 1; + // Size in bits of given register + FadtPointer->XPm1aControlBlock.BitWidth = 0x10; + // Bit offset within the register + FadtPointer->XPm1aControlBlock.BitOffset = 0; + // Minimum Access size (ACPI 3.0) + FadtPointer->XPm1aControlBlock.AccessWidth = 0; + // 64-bit address of struct or register + FadtPointer->XPm1aControlBlock.Address = pmbase + 4; + + // Address space where struct or register exists - System IO + FadtPointer->XPm2ControlBlock.SpaceId = 1; + // Size in bits of given register + FadtPointer->XPm2ControlBlock.BitWidth = 0x08; + // Bit offset within the register + FadtPointer->XPm2ControlBlock.BitOffset = 0; + // Minimum Access size (ACPI 3.0) + FadtPointer->XPm2ControlBlock.AccessWidth = 0; + // 64-bit address of struct or register + FadtPointer->XPm2ControlBlock.Address = pmbase + 0x50; + + // Address space where struct or register exists - System IO + FadtPointer->XPmTimerBlock.SpaceId = 1; + // Size in bits of given register + FadtPointer->XPmTimerBlock.BitWidth = 0x20; + // Bit offset within the register + FadtPointer->XPmTimerBlock.BitOffset = 0; + // Minimum Access size (ACPI 3.0) + FadtPointer->XPmTimerBlock.AccessWidth = 0; + // 64-bit address of struct or register + FadtPointer->XPmTimerBlock.Address = pmbase + 8; + } + } + + // Update checksum in FADT + SetChecksum(&FadtPointer->Header); + + return (1); +} Index: branches/cparm/i386/modules/ACPICodec/acpi_codec.c =================================================================== --- branches/cparm/i386/modules/ACPICodec/acpi_codec.c (revision 0) +++ branches/cparm/i386/modules/ACPICodec/acpi_codec.c (revision 1119) @@ -0,0 +1,1921 @@ +/* + * Copyright 2008 mackerintel + */ + +/* + * Copyright (c) 2011 cparm . All rights reserved. + * + */ + +#include "libsaio.h" +#include "boot.h" +#include "bootstruct.h" +#include "acpi.h" +#include "acpidecode.h" +#include "acpicode.h" +#include "efi_tables.h" +#include "fake_efi.h" +#include "acpi_codec.h" +#include "platform.h" +#include "cpu.h" +#include "aml_generator.h" +#include "xml.h" +#include "pci_root.h" +#include "sl.h" + +U64 rsd_p; +ACPI_TABLES acpi_tables; + +#ifndef DEBUG_ACPI +#define DEBUG_ACPI 0 +#endif + +#if DEBUG_ACPI==2 +#define DBG(x...) {printf(x); sleep(1);} +#elif DEBUG_ACPI==1 +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + +extern EFI_STATUS addConfigurationTable(); + +extern EFI_GUID gEfiAcpiTableGuid; +extern EFI_GUID gEfiAcpi20TableGuid; + +#define MAX_NON_SSDT_TABLE 15 +#define MAX_SSDT_TABLE 15 // 15 additional SSDT tables +#define MAX_ACPI_TABLE MAX_NON_SSDT_TABLE + MAX_SSDT_TABLE + +// Security space for SSDT & FACP generation, +// the size can be increased +// note: the table will not placed in the reserved space if the 'normal' space is not full +#define RESERVED_AERA 3 + +#define ACPI_TABLE_LIST_FULL MAX_ACPI_TABLE + RESERVED_AERA + 1 + +#define ACPI_TABLE_LIST_FULL_NON_RESERVED MAX_ACPI_TABLE + 1 + + +ACPI_TABLE_FADT * +patch_fadt(ACPI_TABLE_FADT *fadt, ACPI_TABLE_DSDT *new_dsdt, bool UpdateFADT); + +#define __RES(s, u) \ +inline unsigned u \ +resolve_##s(unsigned u defaultentry, char *str, int base) \ +{ \ +unsigned u entry = defaultentry; \ +if (str && (strcmp(str,"Default") != 0)) { \ +entry = strtoul((const char *)str, NULL,base); \ +} \ +return entry; \ +} + +__RES(pss, long) +__RES(cst, int) + + +ACPI_TABLE_HEADER * get_new_table_in_list(U32 *new_table_list, U32 Signature, U8 *retIndex ) +{ + ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) new_table_list; + U8 index ; + *retIndex = 0; + + for (index = 0; index < (MAX_ACPI_TABLE + RESERVED_AERA); index++) { + if (*(U32 *) (table_array[index]->Signature) == Signature) { + *retIndex = index; + return table_array[index] ; + } + } + return (void*)0ul; +} + +U8 get_0ul_index_in_list(U32 *new_table_list, bool reserved ) +{ + U8 index ; + + U8 maximum = (reserved == true) ? MAX_ACPI_TABLE + RESERVED_AERA : MAX_ACPI_TABLE; + + for (index = 0; index < maximum; index++) { + if (new_table_list[index] == 0ul) { + return index ; + } + } + return (reserved == true)? ACPI_TABLE_LIST_FULL : ACPI_TABLE_LIST_FULL_NON_RESERVED; +} + +/* cparm : This time we check it by the acpi signature */ +void sanitize_new_table_list(U32 *new_table_list ) +{ + ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) new_table_list; + U8 index ; + + for (index = 0; index < MAX_ACPI_TABLE; index++) { + U32 current_sig = *(U32 *) (table_array[index]->Signature); + + if ((current_sig == NAMESEG(ACPI_SIG_FACS)/* not supported for now */) + || (current_sig == NAMESEG(ACPI_SIG_XSDT)) + || (current_sig == NAMESEG(ACPI_SIG_RSDT)) || (*(volatile U64 *)table_array[index] == NAMESEG64(ACPI_SIG_RSDP)) ) { + + void *buf = (void*)new_table_list[index]; + free(buf); + new_table_list[index] = 0ul ; + } + } +} + +/* cparm : move all table to kernel memory */ +void move_table_list_to_kmem(U32 *new_table_list ) +{ + ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) new_table_list; + U8 index ; + + for (index = 0; index < MAX_ACPI_TABLE; index++) { + if (new_table_list[index] != 0ul) { + + U32 current_sig = *(U32 *) (table_array[index]->Signature); + if ((current_sig != NAMESEG(ACPI_SIG_FACS)/* not supported for now */) + && (current_sig != NAMESEG(ACPI_SIG_XSDT)) + && (current_sig != NAMESEG(ACPI_SIG_RSDT)) && (*(volatile U64 *)table_array[index] != NAMESEG64(ACPI_SIG_RSDP)) + && (GetChecksum(table_array[index], table_array[index]->Length) == 0)) { + + void *tableAddr=(void*)AllocateKernelMemory(table_array[index]->Length); + bcopy(table_array[index], tableAddr, table_array[index]->Length); + new_table_list[index] = 0ul ; + new_table_list[index] = (U32)tableAddr ; + + } else { + + void *buf = (void*)new_table_list[index]; + free(buf); + new_table_list[index] = 0ul ; + } + } + } +} + +ACPI_TABLE_RSDP * gen_alloc_rsdp_v2_from_v1(ACPI_TABLE_RSDP *rsdp ) +{ + + ACPI_TABLE_RSDP * rsdp_conv = (ACPI_TABLE_RSDP *)AllocateKernelMemory(sizeof(ACPI_TABLE_RSDP)); + bzero(rsdp_conv, sizeof(ACPI_TABLE_RSDP)); + memcpy(rsdp_conv, rsdp, ACPI_RSDP_REV0_SIZE); + + /* Add/change fields */ + rsdp_conv->Revision = 2; /* ACPI version 3 */ + rsdp_conv->Length = sizeof(ACPI_TABLE_RSDP); + + /* Correct checksums */ + setRsdpchecksum(rsdp_conv); + setRsdpXchecksum(rsdp_conv); + + return rsdp_conv; +} + +ACPI_TABLE_RSDT * gen_alloc_rsdt_from_xsdt(ACPI_TABLE_XSDT *xsdt) +{ + U32 index; + U32 num_tables; + + num_tables= get_num_tables64(xsdt); + + ACPI_TABLE_RSDT * rsdt_conv=(ACPI_TABLE_RSDT *)AllocateKernelMemory(sizeof(ACPI_TABLE_HEADER)+(num_tables * 4)); + bzero(rsdt_conv, sizeof(ACPI_TABLE_HEADER)+(num_tables * 4)); + memcpy(&rsdt_conv->Header, &xsdt->Header, sizeof(ACPI_TABLE_HEADER)); + + rsdt_conv->Header.Signature[0] = 'R'; + rsdt_conv->Header.Signature[1] = 'S'; + rsdt_conv->Header.Signature[2] = 'D'; + rsdt_conv->Header.Signature[3] = 'T'; + rsdt_conv->Header.Length = sizeof(ACPI_TABLE_HEADER)+(num_tables * 4); + + ACPI_TABLE_HEADER *table = (ACPI_TABLE_HEADER *) xsdt->TableOffsetEntry; + + for (index=0;indexLength) == 0) + { + if (((U32) (table->Signature) == NAMESEG(ACPI_SIG_FADT))) { + ACPI_TABLE_FADT *fadt=(ACPI_TABLE_FADT *)((U32)table); + + DBG("Downgrading ACPI V%d FADT to ACPI V1 FADT \n", fadt->Header.Revision); + ACPI_TABLE_FADT *fadt_conv=(ACPI_TABLE_FADT *)malloc(0x74); + memcpy(fadt_conv, fadt, 0x74); + fadt_conv->Header.Length = 0x74; + fadt_conv->Header.Revision = 0x01; + + SetChecksum(&fadt_conv->Header); + ACPI_TABLE_FADT *fadt_mod = patch_fadt(fadt_conv, ((ACPI_TABLE_DSDT*)((U32)fadt->XDsdt)), false); + if (fadt_mod == (void*)0ul) { + printf("Error: Failed to patch FADT Table, fallback to fadt original pointer\n"); + fadt_mod = fadt; + } + + rsdt_conv->TableOffsetEntry[index] = ((U32)fadt_mod); + // Move array pointer to next 64-bit pointer + table = (ACPI_TABLE_HEADER *) ((U32) table + sizeof(U64)); + continue; + } + + rsdt_conv->TableOffsetEntry[index] = (U32)table; + } + // Move array pointer to next 64-bit pointer + table = (ACPI_TABLE_HEADER *) ((U32) table + sizeof(U64)); + + } + + SetChecksum(&rsdt_conv->Header); + + return rsdt_conv; +} + +ACPI_TABLE_XSDT * gen_alloc_xsdt_from_rsdt(ACPI_TABLE_RSDT *rsdt) +{ + + + U32 index; + U32 num_tables; + + num_tables= get_num_tables(rsdt); + + ACPI_TABLE_XSDT * xsdt_conv=(ACPI_TABLE_XSDT *)AllocateKernelMemory(sizeof(ACPI_TABLE_HEADER)+(num_tables * 8)); + bzero(xsdt_conv, sizeof(ACPI_TABLE_HEADER)+(num_tables * 8)); + memcpy(&xsdt_conv->Header, &rsdt->Header, sizeof(ACPI_TABLE_HEADER)); + + xsdt_conv->Header.Signature[0] = 'X'; + xsdt_conv->Header.Signature[1] = 'S'; + xsdt_conv->Header.Signature[2] = 'D'; + xsdt_conv->Header.Signature[3] = 'T'; + xsdt_conv->Header.Length = sizeof(ACPI_TABLE_HEADER)+(num_tables * 8); + + ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) rsdt->TableOffsetEntry; + + for (index=0;indexLength) == 0) { + + if ((*(U32 *) (table_array[index]->Signature) == NAMESEG(ACPI_SIG_FADT))){ + ACPI_TABLE_FADT *FacpPointer = ((ACPI_TABLE_FADT*)table_array[index]); + ACPI_TABLE_FADT *fadt_mod = (ACPI_TABLE_FADT *)patch_fadt(FacpPointer,((ACPI_TABLE_DSDT*)FacpPointer->Dsdt),true); + if (fadt_mod == (void*)0ul) { + printf("Error: Failed to patch (& update) FADT Table, fallback to original fadt pointer\n"); + fadt_mod = FacpPointer; + } + xsdt_conv->TableOffsetEntry[index] = ((U64)((U32)fadt_mod)); + + continue; + } + xsdt_conv->TableOffsetEntry[index] = ((U64)((U32)table_array[index])); + } + + } + + SetChecksum(&xsdt_conv->Header); + + return xsdt_conv; +} + +void *loadACPITable(char *dirspec, char *filename ) +{ + int fd = -1; + char acpi_file[512]; + + DBG("Searching for %s file ...\n", filename); + // Check booting partition + + sprintf(acpi_file, "%s%s",dirspec, filename); + + fd=open(acpi_file); + + if (fd<0) + { + DBG("Couldn't open ACPI Table: %s\n", acpi_file); + return (void *)0ul ; + } + + void *tableAddr=(void*)malloc(file_size (fd)); + + if (tableAddr) + { + if (read (fd, tableAddr, file_size (fd))!=file_size (fd)) + { + printf("Couldn't read table %s\n",acpi_file); + free (tableAddr); + close (fd); + return (void *)0ul ; + } + + close (fd); + + ACPI_TABLE_HEADER * header = (ACPI_TABLE_HEADER *)tableAddr; + + if (GetChecksum(header, header->Length) == 0) { + DBG("Found valid ACPI file : %s", filename); + DBG(", Table %s read and stored at: %x", acpi_file, tableAddr); + DBG("\n"); + return tableAddr; + } else { + printf("Warning : Incorrect cheksum for the file : %s,"); + printf(" this file will be dropped.\n"); + free(tableAddr); + return (void*)0ul; + } + } + + printf("Couldn't allocate memory for table %s\n", acpi_file); + close (fd); + + return (void *)0ul ; +} + +/* + * License for + * print_nameseg, generate_cpu_map_from_acpi, sprintf_nameseg . + * + Copyright (c) 2010, Intel Corporation + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +static U32 pmbase; +static short cpuNamespace; +PROCESSOR_NUMBER_TO_NAMESEG cpu_map[CPU_MAP_LIMIT]; +unsigned int cpu_map_count; +int cpu_map_error; + +#if DEBUG_ACPI +static void print_nameseg(U32 i) +{ + printf("%c%c%c%c", + (int)(i & 0x000000ff), + (int)((i & 0x0000ff00) >> 8), + (int)((i & 0x00ff0000) >> 16), + (int)(i >> 24)); +} + +static void sprintf_nameseg(char* dest, U32 src) +{ + sprintf(dest,"%c%c%c%c", + (int)(src & 0x000000ff), + (int)((src & 0x0000ff00) >> 8), + (int)((src & 0x00ff0000) >> 16), + (int)(src >> 24)); +} +#endif + +static int generate_cpu_map_from_acpi(ACPI_TABLE_DSDT * DsdtPointer) +{ + PROCESSOR_NUMBER_TO_NAMESEG *map = cpu_map; + U32 processor_namespace = 0; + U32 cpu; + U8 *current, *end; + ACPI_TABLE_HEADER *header; + struct acpi_namespace ns; + + if ((cpu_map_error == 1) || (DsdtPointer == (void*)0ul)) + return 1; + else if (cpu_map_count > 0) + return 0; + + DBG("Attempting to autodetect CPU map from ACPI DSDT; wish me luck\n"); + + current = (U8 *) DsdtPointer; + current = decodeTableHeader(current, &header); + end = current - sizeof(*header) + header->Length; + ns.depth = 0; + acpi_processor_count = 0; + DBG("* DSDT debug start\n"); + parse_acpi_termlist(&ns, current, end); + DBG("* DSDT debug end\n"); + + if (acpi_processor_count > CPU_MAP_LIMIT){ + verbose("Too many processors: found %u processors\n", acpi_processor_count); + return (cpu_map_error = 1); + } + if (acpi_processor_count == 0){ + verbose( "Found no processors in ACPI\n"); + return (cpu_map_error = 1); + } + for (cpu = 0; cpu < acpi_processor_count; cpu++) { + U32 nameseg; + if (acpi_processors[cpu].pmbase) { + U32 cpu_pmbase = acpi_processors[cpu].pmbase - 0x10; + if (pmbase && cpu_pmbase != pmbase){ + verbose("Found inconsistent pmbase addresses in ACPI: 0x%x and 0x%x\n", pmbase, cpu_pmbase); + return (cpu_map_error = 1); + } + pmbase = cpu_pmbase; + } + if (acpi_processors[cpu].ns.depth > MAX_SUPPORTED_CPU_NAMESEGS + 1){ + verbose("Processor path too deep: depth %u\n", acpi_processors[cpu].ns.depth); + return (cpu_map_error = 1); + } + if (processor_namespace && acpi_processors[cpu].ns.nameseg[0] != processor_namespace){ + verbose("Processor namespaces inconsistent\n"); + return (cpu_map_error = 1); + } + processor_namespace = acpi_processors[cpu].ns.nameseg[0]; + map->acpi_processor_number = acpi_processors[cpu].id; + map->seg_count = acpi_processors[cpu].ns.depth - 1; + for (nameseg = 0; nameseg < map->seg_count; nameseg++) + map->nameseg[nameseg] = acpi_processors[cpu].ns.nameseg[nameseg + 1]; + map++; + } + if (!pmbase){ + verbose("No pmbase found in ACPI\n"); + return (cpu_map_error = 1); + } + if (processor_namespace == NAMESEG("_PR_")) + cpuNamespace = CPU_NAMESPACE_PR; + else if (processor_namespace == NAMESEG("_SB_")) + cpuNamespace = CPU_NAMESPACE_SB; + else { + verbose("Found processors in invalid namespace; not _PR_ or _SB_\n"); + return (cpu_map_error = 1); + } + cpu_map_count = map - cpu_map; + +#if DEBUG_ACPI + char pns[3]; + sprintf_nameseg(pns,processor_namespace); + verbose("Found %d processors in ACPI, pmbase : 0x%x, cpu_map_count : %d, namespace : %s \n",acpi_processor_count, pmbase, cpu_map_count ,pns ); + + getc(); + U32 i; + verbose("Found processors name : \n" ); + for ( i = 0; iCPU.Vendor != 0x756E6547) { + verbose ("Not an Intel platform: C-States will not be generated !!!\n"); + return (void *)0ul; + } + + if (fadt == (void *)0ul) { + verbose ("FACP not exists: C-States will not be generated !!!\n"); + return (void *)0ul; + } + + ACPI_TABLE_DSDT* dsdt = ((fadt->Header.Revision >= 3) && (fadt->XDsdt != 0)) ? (ACPI_TABLE_DSDT*)((U32)fadt->XDsdt):(ACPI_TABLE_DSDT*)fadt->Dsdt; + if (dsdt == (void *)0ul) { + verbose ("DSDT not found: C-States will not be generated !!!\n"); + return (void *)0ul; + } + + if (generate_cpu_map_from_acpi(dsdt) == 0) + { + bool c2_enabled = fadt->C2Latency < 100; + bool c3_enabled = fadt->C3Latency < 1000; + bool c4_enabled = false; + + getBoolForKey(kEnableC4State, &c4_enabled, &bootInfo->bootConfig); + + unsigned char cstates_count = 1 + (c2_enabled ? 1 : 0) + ((c3_enabled || c4_enabled) ? 1 : 0); + char *Lat = NULL, *Pw = NULL, *tmpstr =NULL; + int base = 16; + TagPtr personality = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"C-States")); + + if ((tmpstr = XMLCastString(XMLGetProperty(personality, (const char*)"Base")))) { + + int mybase = strtol(tmpstr, NULL, 10); + + if (mybase == 8 || mybase == 10 || mybase == 16 ) + base = mybase; + } + + struct aml_chunk* root = aml_create_node(NULL); + aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header + struct aml_chunk* scop; + if (cpuNamespace == CPU_NAMESPACE_PR) + scop = aml_add_scope(root, "\\_PR_"); + else if (cpuNamespace == CPU_NAMESPACE_SB) + scop = aml_add_scope(root, "\\_SB_"); + else + { + aml_destroy_node(root); + goto out; + } + 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); + TagPtr match_Status = XMLGetProperty(personality, (const char*)"C1"); + if (match_Status) { + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency")); + } + 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, (unsigned char)resolve_cst(0x01, Lat, base)); // Latency + aml_add_word(tmpl, resolve_cst(0x03e8, Pw, base)); // Power + // C2 + if (c2_enabled) + { + tmpl = aml_add_package(pack); + Lat = NULL; + Pw = NULL; + match_Status = XMLGetProperty(personality, (const char*)"C2"); + if (match_Status) { + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency")); + } + + 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_word(tmpl, resolve_cst(fadt->C2Latency, Lat, base)); // Latency + aml_add_word(tmpl, resolve_cst(0x01f4, Pw, base)); // Power + } + + // C4 + if (c4_enabled) + { + tmpl = aml_add_package(pack); + Lat = NULL; + Pw = NULL; + match_Status = XMLGetProperty(personality, (const char*)"C4"); + if (match_Status) { + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency")); + } + 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, resolve_cst(fadt->C3Latency / 2, Lat, base)); // TODO: right latency for C4 + aml_add_word(tmpl, resolve_cst(0xfa, Pw, base)); // Power + + } + // C3 + else if (c3_enabled) + { + tmpl = aml_add_package(pack); + Lat = NULL; + Pw = NULL; + match_Status = XMLGetProperty(personality, (const char*)"C3"); + if (match_Status) { + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency")); + } + 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, resolve_cst(fadt->C3Latency , Lat, base)); + aml_add_word(tmpl, resolve_cst(0x015e, Pw, base)); // Power + + } + + // Aliaces + unsigned int i; + for (i = 0; i < cpu_map_count; i++) + { + char name[9]; + U32 nseg = *(U32*)cpu_map[i].nameseg; + if (cpuNamespace == CPU_NAMESPACE_PR) { + sprintf(name, "_PR_%c%c%c%c", + (int)(nseg & 0x000000ff), + (int)((nseg & 0x0000ff00) >> 8), + (int)((nseg & 0x00ff0000) >> 16), + (int)(nseg >> 24)); + } else if (cpuNamespace == CPU_NAMESPACE_SB) { + sprintf(name, "_SB_%c%c%c%c", + (int)(nseg & 0x000000ff), + (int)((nseg & 0x0000ff00) >> 8), + (int)((nseg & 0x00ff0000) >> 16), + (int)(nseg >> 24)); + } else { + aml_destroy_node(root); + goto out; + } + + scop = aml_add_scope(root, name); + aml_add_alias(scop, "CST_", "_CST"); + } + + aml_calculate_size(root); + + ACPI_TABLE_SSDT *ssdt = (ACPI_TABLE_SSDT *)AllocateKernelMemory(root->Size); + + aml_write_node(root, (void*)ssdt, 0); + + ssdt->Header.Length = root->Size; + + SetChecksum(&ssdt->Header); + + aml_destroy_node(root); + + verbose ("SSDT with CPU C-States generated successfully\n"); + + return ssdt; + } + else + { +out: + verbose ("ACPI CPUs not found: C-States will not be generated !!!\n"); + } + + return (void *)0ul; +} + +ACPI_TABLE_SSDT *generate_pss_ssdt(ACPI_TABLE_DSDT* dsdt) +{ + + char ssdt_header[] = + { + 0x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */ + 0x01, 0x6A, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x00, /* ..PmRef. */ + 0x43, 0x70, 0x75, 0x50, 0x6D, 0x00, 0x00, 0x00, /* CpuPm... */ + 0x00, 0x30, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* .0..INTL */ + 0x31, 0x03, 0x10, 0x20, /* 1.._ */ + }; + + if (Platform->CPU.Vendor != 0x756E6547) { + verbose ("Not an Intel platform: P-States will not be generated !!!\n"); + return (void *)0ul; + } + + if (!(Platform->CPU.Features & CPUID_FEATURE_MSR)) { + verbose ("Unsupported CPU: P-States will not be generated !!!\n"); + return (void *)0ul; + } + + if (dsdt == (void *)0ul) { + verbose ("DSDT not found: P-States will not be generated !!!\n"); + return (void *)0ul; + } + + if (generate_cpu_map_from_acpi(dsdt) == 0 ) + { + struct p_state initial, maximum, minimum, p_states[32]; + U8 p_states_count = 0; + + // Retrieving P-States, ported from code by superhai (c) + switch (Platform->CPU.Family) { + case 0x06: + { + switch (Platform->CPU.Model) + { + case CPUID_MODEL_DOTHAN: + case CPUID_MODEL_YONAH: // Yonah + case CPUID_MODEL_MEROM: // Merom + case CPUID_MODEL_PENRYN: // Penryn + case CPUID_MODEL_ATOM: // Intel Atom (45nm) + { + bool cpu_dynamic_fsb = false; + + if (rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 27)) + { + wrmsr64(MSR_IA32_EXT_CONFIG, (rdmsr64(MSR_IA32_EXT_CONFIG) | (1 << 28))); + delay(1); + cpu_dynamic_fsb = rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 28); + } + + bool cpu_noninteger_bus_ratio = (rdmsr64(MSR_IA32_PERF_STATUS) & (1ULL << 46)); + + initial.Control = rdmsr64(MSR_IA32_PERF_STATUS); + + maximum.Control = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 32) & 0x1F3F) | (0x4000 * cpu_noninteger_bus_ratio); + maximum.CID = ((maximum.FID & 0x1F) << 1) | cpu_noninteger_bus_ratio; + + minimum.FID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 24) & 0x1F) | (0x80 * cpu_dynamic_fsb); + minimum.VID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 48) & 0x3F); + + if (minimum.FID == 0) + { + U64 msr; + U8 i; + // Probe for lowest fid + for (i = maximum.FID; i >= 0x6; i--) + { + msr = rdmsr64(MSR_IA32_PERF_CONTROL); + wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (i << 8) | minimum.VID); + intel_waitforsts(); + minimum.FID = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0x1F; + delay(1); + } + + msr = rdmsr64(MSR_IA32_PERF_CONTROL); + wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID); + intel_waitforsts(); + } + + if (minimum.VID == maximum.VID) + { + U64 msr; + U8 i; + // Probe for lowest vid + for (i = maximum.VID; i > 0xA; i--) + { + msr = rdmsr64(MSR_IA32_PERF_CONTROL); + wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (minimum.FID << 8) | i); + intel_waitforsts(); + minimum.VID = rdmsr64(MSR_IA32_PERF_STATUS) & 0x3F; + delay(1); + } + + msr = rdmsr64(MSR_IA32_PERF_CONTROL); + wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID); + intel_waitforsts(); + } + + minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb; + + // Sanity check + if (maximum.CID < minimum.CID) + { + DBG("Insane FID values!"); + p_states_count = 0; + } + else + { + // Finalize P-States + // Find how many P-States machine supports + p_states_count = maximum.CID - minimum.CID + 1; + + if (p_states_count > 32) + p_states_count = 32; + + U8 vidstep; + U8 i = 0, u, invalid = 0; + + vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1); + + for (u = 0; u < p_states_count; u++) + { + i = u - invalid; + + p_states[i].CID = maximum.CID - u; + p_states[i].FID = (p_states[i].CID >> 1); + + 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) + { + 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) + invalid++; + + p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2; + + U32 multiplier = p_states[i].FID & 0x1f; // = 0x08 + bool half = p_states[i].FID & 0x40; // = 0x01 + bool dfsb = p_states[i].FID & 0x80; // = 0x00 + U32 fsb = Platform->CPU.FSBFrequency / 1000000; // = 400 + U32 halffsb = (fsb + 1) >> 1; // = 200 + U32 frequency = (multiplier * fsb); // = 3200 + + p_states[i].Frequency = (frequency + (half * halffsb)) >> dfsb; // = 3200 + 200 = 3400 + } + + p_states_count -= invalid; + } + break; + } + case CPUID_MODEL_FIELDS: + case CPUID_MODEL_DALES: + case CPUID_MODEL_DALES_32NM: + case CPUID_MODEL_NEHALEM: + case CPUID_MODEL_NEHALEM_EX: + case CPUID_MODEL_WESTMERE: + case CPUID_MODEL_WESTMERE_EX: + case CPUID_MODEL_SANDYBRIDGE: + case CPUID_MODEL_JAKETOWN: + { + maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff; // Seems it always contains maximum multiplier value (with turbo, that's we need)... + minimum.Control = (rdmsr64(MSR_PLATFORM_INFO) >> 40) & 0xff; + + verbose("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control); + + // Sanity check + if (maximum.Control < minimum.Control) + { + DBG("Insane control values!"); + p_states_count = 0; + } + else + { + U8 i; + p_states_count = 0; + + 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; + p_states_count++; + } + } + + break; + } + default: + verbose ("Unsupported CPU: P-States will not be generated !!!\n"); + break; + } + } + default: + break; + } + + // Generating SSDT + if (p_states_count) + { + unsigned 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; + if (cpuNamespace == CPU_NAMESPACE_PR) + scop = aml_add_scope(root, "\\_PR_"); + else if (cpuNamespace == CPU_NAMESPACE_SB) + scop = aml_add_scope(root, "\\_SB_"); + else + { + aml_destroy_node(root); + goto out; + } + struct aml_chunk* name = aml_add_name(scop, "PSS_"); + struct aml_chunk* pack = aml_add_package(name); + + U8 minPSratio = (p_states[p_states_count-1].Frequency / (Platform->CPU.FSBFrequency / 10000000 )); + U8 maxPSratio = (p_states[0].Frequency / (Platform->CPU.FSBFrequency / 10000000 )); + + U8 cpu_div = Platform->CPU.CurrDiv; + U8 cpu_ratio = 0; + + if (cpu_div) + cpu_ratio = (Platform->CPU.CurrCoef * 10) + 5; + else + cpu_ratio = Platform->CPU.CurrCoef * 10; + + + int user_max_ratio = 0; + getIntForKey(kMaxRatio, &user_max_ratio, &bootInfo->bootConfig); + if (user_max_ratio >= minPSratio && maxPSratio >= user_max_ratio) { + + U8 maxcurrdiv = 0, maxcurrcoef = (int)(user_max_ratio / 10); + + U8 maxdiv = user_max_ratio - (maxcurrcoef * 10); + if (maxdiv > 0) + maxcurrdiv = 1; + + if (maxcurrdiv) + cpu_ratio = (maxcurrcoef * 10) + 5; + else + cpu_ratio = maxcurrcoef * 10; + } + + int user_min_ratio = 0; + getIntForKey(kMinRatio, &user_min_ratio, &bootInfo->bootConfig); + if (user_min_ratio >= minPSratio && cpu_ratio >= user_min_ratio) { + + U8 mincurrdiv = 0, mincurrcoef = (int)(user_min_ratio / 10); + + U8 mindiv = user_min_ratio - (mincurrcoef * 10); + + if (mindiv > 0) + mincurrdiv = 1; + + if (mincurrdiv) + minPSratio = (mincurrcoef * 10) + 5; + else + minPSratio = mincurrcoef * 10; + + } + + if (maxPSratio >= cpu_ratio && cpu_ratio >= minPSratio) maxPSratio = cpu_ratio; + + TagPtr personality = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"P-States")); + char* MatchStat = 0; + int dropPSS = 0, Pstatus = 0, base = 16; + int expert = 0;/* Default: 0 , mean mixed mode | expert mode : 1 , mean add only p-states found in boot.plist*/ + char *tmpstr = XMLCastString(XMLGetProperty(personality, (const char*)"Mode")); + + if (strcmp(tmpstr,"Expert") == 0) { + p_states_count = (XMLTagCount(personality)) - 1 ; // - 1 = - ("Mode" tag) + expert = 1; + } + + + if ((tmpstr = XMLCastString(XMLGetProperty(personality, (const char*)"Base")))) { + + if (expert) p_states_count--; // -= ("Base" tag) + + int mybase = strtol(tmpstr, NULL, 10); + + if (mybase == 8 || mybase == 10 || mybase == 16 ) + base = mybase; + } + + for (i = 0; i < p_states_count; i++) + { + sprintf(MatchStat, "%d",i); + TagPtr match_Status = XMLGetProperty(personality, (const char*)MatchStat); + + char *Lat1 = NULL, *clk = NULL, *Pw = NULL, *Lat2 = NULL, *Ctrl = NULL ; + + if (match_Status) { + + clk = XMLCastString(XMLGetProperty(match_Status, (const char*)"CoreFreq")); + Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power")); + Lat1 = XMLCastString(XMLGetProperty(match_Status, (const char*)"Transition Latency")); + Lat2 = XMLCastString(XMLGetProperty(match_Status, (const char*)"Bus Master Latency")); + Ctrl = XMLCastString(XMLGetProperty(match_Status, (const char*)"Control")); + + + } else if (expert) + continue; + + + unsigned long Frequency = 0x00000000; + + if (!expert) Frequency = p_states[i].Frequency; + + if (clk) + Frequency = strtoul((const char *)clk, NULL,base); + + if (!Frequency || Frequency > p_states[0].Frequency ) continue; + + U8 curr_ratio = (Frequency / (Platform->CPU.FSBFrequency / 10000000 )); + + if (curr_ratio > maxPSratio || minPSratio > curr_ratio) + goto dropPstate; + + struct aml_chunk* pstt = aml_add_package(pack); + aml_add_dword(pstt, Frequency); // CoreFreq (in MHz). + aml_add_dword(pstt, resolve_pss(0x00000000, Pw, base)); // Power (in milliWatts) + aml_add_dword(pstt, resolve_pss(0x0000000A, Lat1, base)); // Transition Latency (in microseconds). + aml_add_dword(pstt, resolve_pss(0x0000000A, Lat2, base)); // Bus Master Latency (in microseconds). + unsigned long Control = 0x00000000; + if (!expert) Control = p_states[i].Control; + aml_add_dword(pstt, resolve_pss(Control, Ctrl, base)); // Control + Pstatus++; + aml_add_dword(pstt, Pstatus); // Status + continue; + dropPstate: + + DBG("state with cpu frequency :%d and ratio :%d will be dropped\n",p_states[i].Frequency,curr_ratio); + + dropPSS++; + + + } + + + // Add aliaces + for (i = 0; i < cpu_map_count; i++) + { + char name[9]; + U32 nseg = *(U32*)cpu_map[i].nameseg; + if (cpuNamespace == CPU_NAMESPACE_PR) { + sprintf(name, "_PR_%c%c%c%c", + (int)(nseg & 0x000000ff), + (int)((nseg & 0x0000ff00) >> 8), + (int)((nseg & 0x00ff0000) >> 16), + (int)(nseg >> 24)); + } else if (cpuNamespace == CPU_NAMESPACE_SB) { + sprintf(name, "_SB_%c%c%c%c", + (int)(nseg & 0x000000ff), + (int)((nseg & 0x0000ff00) >> 8), + (int)((nseg & 0x00ff0000) >> 16), + (int)(nseg >> 24)); + } else { + aml_destroy_node(root); + goto out; + } + + scop = aml_add_scope(root, name); + aml_add_alias(scop, "PSS_", "_PSS"); + } + + aml_calculate_size(root); + + ACPI_TABLE_SSDT *ssdt = (ACPI_TABLE_SSDT *)AllocateKernelMemory(root->Size); + + aml_write_node(root, (void*)ssdt, 0); + + ssdt->Header.Length = root->Size; + + SetChecksum(&ssdt->Header); + + aml_destroy_node(root); + + verbose ("SSDT with CPU P-States generated successfully"); + + if (dropPSS) + verbose(", %d P-state(s) dropped",dropPSS); + + verbose("\n"); + + return ssdt; + } + } + else + { +out: + verbose("ACPI CPUs not found: P-States will not be generated !!!\n"); + } + + return (void *)0ul; +} +#if UNUSED +ACPI_TABLE_FACS* generate_facs(bool updatefacs ) +{ + ACPI_TABLE_FACS* facs_mod=(ACPI_TABLE_FACS *)AllocateKernelMemory(sizeof(ACPI_TABLE_FACS)); + bzero(facs_mod, sizeof(ACPI_TABLE_FACS)); + + ACPI_TABLE_FACS * FacsPointer =(acpi_tables.FacsPointer64 != (void *)0ul) ? + (ACPI_TABLE_FACS *)acpi_tables.FacsPointer64 : (ACPI_TABLE_FACS *)acpi_tables.FacsPointer; + + memcpy(facs_mod, FacsPointer , FacsPointer->Length); + facs_mod->Length = sizeof(ACPI_TABLE_FACS); + + if (FacsPointer->Length < sizeof(ACPI_TABLE_FACS)) { + facs_mod->FirmwareWakingVector = 0; + facs_mod->GlobalLock = 0; + facs_mod->Flags = 0; + } + + if (updatefacs && FacsPointer->Version < 2) { + if (FacsPointer->Version > 0) { + facs_mod->XFirmwareWakingVector = FacsPointer->XFirmwareWakingVector; + } else { + facs_mod->XFirmwareWakingVector = (U64)facs_mod->FirmwareWakingVector; + } + + facs_mod->Version = 2; /* ACPI 1.0: 0, ACPI 2.0/3.0: 1, ACPI 4.0: 2 */ + + } + + return facs_mod; +} +#endif + +ACPI_GENERIC_ADDRESS FillGASStruct(U32 Address, U8 Length) +{ + ACPI_GENERIC_ADDRESS TmpGAS; + + TmpGAS.SpaceId = 1; /* I/O Address */ + + if (Address == 0) + { + TmpGAS.BitWidth = 0; + } else { + TmpGAS.BitWidth = Length * 8; + } + + TmpGAS.BitOffset = 0; + TmpGAS.AccessWidth = 0; /* Not set for Legacy reasons... */ + TmpGAS.Address = (U64)Address; + + return (TmpGAS); +} + +ACPI_TABLE_FADT * +patch_fadt(ACPI_TABLE_FADT *fadt, ACPI_TABLE_DSDT *new_dsdt, bool UpdateFADT) +{ + ACPI_TABLE_FADT *fadt_mod = (void*)0; + bool fadt_rev2_needed = false; + bool fix_restart = false; + const char * value; + + // Restart Fix + if (Platform->CPU.Vendor == 0x756E6547) { /* Intel */ + fix_restart = true; + getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig); + + } else { + verbose ("Not an Intel platform: Restart Fix disabled !!!\n"); + } + + if (fix_restart) + fadt_rev2_needed = true; + + // Allocate new fadt table + if (UpdateFADT) + { + if (fadt->Header.Length < 0xF4) + { + fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(0xF4); + bzero(fadt_mod, 0xF4); + memcpy(fadt_mod, fadt, fadt->Header.Length); + fadt_mod->Header.Length = 0xF4; + } + else + { + fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(fadt->Header.Length); + memcpy(fadt_mod, fadt, fadt->Header.Length); + } + + + //fadt_mod->Header.Revision = 0x04; // FADT rev 4 + fadt_mod->ResetRegister = FillGASStruct(0, 0); + fadt_mod->ResetValue = 0; + fadt_mod->Reserved4[0] = 0; + fadt_mod->Reserved4[1] = 0; + fadt_mod->Reserved4[2] = 0; + + fadt_mod->XPm1aEventBlock = FillGASStruct(fadt_mod->Pm1aEventBlock, fadt_mod->Pm1EventLength); + fadt_mod->XPm1bEventBlock = FillGASStruct(fadt_mod->Pm1bEventBlock, fadt_mod->Pm1EventLength); + fadt_mod->XPm1aControlBlock = FillGASStruct(fadt_mod->Pm1aControlBlock, fadt_mod->Pm1ControlLength); + fadt_mod->XPm1bControlBlock = FillGASStruct(fadt_mod->Pm1bControlBlock, fadt_mod->Pm1ControlLength); + fadt_mod->XPm2ControlBlock = FillGASStruct(fadt_mod->Pm2ControlBlock, fadt_mod->Pm2ControlLength); + fadt_mod->XPmTimerBlock = FillGASStruct(fadt_mod->PmTimerBlock, fadt_mod->PmTimerLength); + fadt_mod->XGpe0Block = FillGASStruct(fadt_mod->Gpe0Block, fadt_mod->Gpe0BlockLength); + fadt_mod->XGpe1Block = FillGASStruct(fadt_mod->Gpe1Block, fadt_mod->Gpe1BlockLength); + if (fadt->Header.Revision < 4) { + fadt_mod->Header.Revision = 0x04; // FADT rev 4 + verbose("Converted ACPI V%d FADT to ACPI V4 FADT\n", fadt->Header.Revision); + + } + } else { + + if (fadt_rev2_needed) + { + if (fadt->Header.Length < 0x84 ) + { + fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(0x84); + bzero(fadt_mod, 0x84); + memcpy(fadt_mod, fadt, fadt->Header.Length); + fadt_mod->Header.Length = 0x84; + } else { + fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(fadt->Header.Length); + memcpy(fadt_mod, fadt, fadt->Header.Length); + } + + if (fadt->Header.Revision < 2) { + fadt_mod->Header.Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions) + verbose("Converted ACPI V%d FADT to ACPI V2 FADT\n", fadt->Header.Revision ); + } + } else { + if (fadt->Header.Length < 0x74 ) + { + fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(0x74); + bzero(fadt_mod, 0x74); + memcpy(fadt_mod, fadt, fadt->Header.Length); + fadt_mod->Header.Length = 0x74; + fadt_mod->Header.Revision = 0x01; + verbose("Warning: ACPI FADT length was < 0x74 which is the minimum for the ACPI FADT V1 specification, \n", fadt->Header.Revision ); + verbose(" trying to convert it to Version 1. \n"); + + } else { + fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(fadt->Header.Length); + memcpy(fadt_mod, fadt, fadt->Header.Length); + } + } + } + bool intelfadtspec = true; + U8 Type = PMProfileError; + // Determine system type / PM_Model + + // Fix System-type if needed (should never happen) + if (Platform->Type > MaxSupportedPMProfile) + { + if(fadt_mod->PreferredProfile <= MaxSupportedPMProfile) + Platform->Type = fadt_mod->PreferredProfile; // get the fadt if correct + else + Platform->Type = 1; /* Set a fixed value (Desktop) */ + } + + // If needed, set System-type from PM_Profile (if valid) else set PM_Profile with a fixed the System-type + // Give prior to the FADT pm profile, allow to also control this value with a patched FADT table + if (fadt_mod->PreferredProfile != Platform->Type) + { + bool val = false; + getBoolForKey("PreferInternalProfileDetect", &val, &bootInfo->bootConfig); // if true Give prior to the profile resolved trought the CPU model + + val = Platform->CPU.isServer ; + + if (fadt_mod->PreferredProfile <= MaxSupportedPMProfile && !val) { + Platform->Type = fadt_mod->PreferredProfile; + } else { + fadt_mod->PreferredProfile = Platform->Type; + } + + } + + // Set PM_Profile and System-type if user wanted this value to be forced + if ( (value=getStringForKey("SystemType", &bootInfo->bootConfig))!=NULL) { + if ((Type = (unsigned char) strtoul(value, NULL, 10) ) <= MaxSupportedPMProfile) + { + verbose("FADT: changing Preferred_PM_Profile from %d to %d\n", fadt->PreferredProfile, Type); + fadt_mod->PreferredProfile = Platform->Type = Type; + } else verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform->Type); + } + + getBoolForKey(KIntelFADT, &intelfadtspec, &bootInfo->bootConfig); + if ((pmbase == 0) && (cpu_map_error == 0) && (intelfadtspec == true)) + { + ACPI_TABLE_DSDT *DsdtPointer ; + if (new_dsdt != (void*)0ul) + DsdtPointer = new_dsdt; + else if ((fadt_mod->Header.Revision >= 3) && (fadt_mod->XDsdt != 0ul)) + DsdtPointer = (ACPI_TABLE_DSDT *)((U32)fadt_mod->XDsdt); + else + DsdtPointer = (ACPI_TABLE_DSDT *)fadt_mod->Dsdt; + + generate_cpu_map_from_acpi(DsdtPointer); + } + + // Patch DSDT Address if we have loaded a DSDT table + if(new_dsdt != (void*)0ul) + fadt_mod->Dsdt=(U32)new_dsdt; + + fadt_mod->Facs= fadt->Facs; + //fadt_mod->Facs=(U32)generate_facs(false); + + // Patch FADT to fix restart + if (fadt_mod->Header.Revision >= 2 && fix_restart) + { + fadt_mod->Flags|= 0x400; + + int type = PCI_RESET_TYPE; + getIntForKey(KResetType, &type, &bootInfo->bootConfig); + if (type == KEYBOARD_RESET_TYPE) { + //Azi: keyboard reset; http://forum.voodooprojects.org/index.php/topic,1056.msg9802.html#msg9802 + fadt_mod->ResetRegister = FillGASStruct(0x64, 1); + fadt_mod->ResetValue = 0xfe; + } else { + fadt_mod->ResetRegister = FillGASStruct(0x0cf9, 1); + fadt_mod->ResetValue = 0x06; + } + verbose("FADT: Restart Fix applied (Type : %s) !\n", (type == 0) ? "PCI": "KEYBOARD"); + } + + if (fadt_mod->Header.Revision >= 3) { + + + if (UpdateFADT) { + + //fadt_mod->XFacs= (U64)((U32)generate_facs(true)); + fadt_mod->XFacs=(U64)fadt->Facs; + + } else { + fadt_mod->XFacs=(U64)fadt->XFacs; + } + + + if(new_dsdt != (void*)0ul) + fadt_mod->XDsdt=((U64)(U32)new_dsdt); + else if (UpdateFADT) + fadt_mod->XDsdt=(U64)fadt_mod->Dsdt; + + + Platform->hardware_signature = ((ACPI_TABLE_FACS *)((U32)fadt_mod->XFacs))->HardwareSignature; + + } else { + + Platform->hardware_signature = ((ACPI_TABLE_FACS *)fadt_mod->Facs)->HardwareSignature; + + } + + + DBG("setting hardware_signature to %x \n",Platform->hardware_signature); + + + + if (pmbase && (intelfadtspec == true)) + ProcessFadt(fadt_mod, pmbase); // The checksum correction will be done by ProcessFadt + else + SetChecksum(&fadt_mod->Header); // Correct the checksum + + return fadt_mod; +} + +void process_xsdt (ACPI_TABLE_RSDP *rsdp_mod , U32 *new_table_list){ + TagPtr DropTables_p = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"ACPIDropTables")); + U32 new_table = 0ul; + U8 new_table_index = 0, table_added = 0; + ACPI_TABLE_XSDT *xsdt = (void*)0ul, *xsdt_mod = (void*)0ul; + ACPI_TABLE_RSDT *rsdt_conv = (void *)0ul; + + // FIXME: handle 64-bit address correctly + + xsdt=(ACPI_TABLE_XSDT *)acpi_tables.XsdtPointer; + + verbose("* Processing XSDT: \n"); + + DBG("XSDT @%x, Length=%d\n", (U32)xsdt, + xsdt->Header.Length); + + if (xsdt != (void *)0ul) + { + U32 dropoffset=0, index; + table_added = 0; + + xsdt_mod=(ACPI_TABLE_XSDT *)AllocateKernelMemory(xsdt->Header.Length); + bzero(xsdt_mod, xsdt->Header.Length); + memcpy(&xsdt_mod->Header, &xsdt->Header, sizeof(ACPI_TABLE_HEADER)); + + U32 num_tables=get_num_tables64(xsdt); + + ACPI_TABLE_HEADER *table = (ACPI_TABLE_HEADER *) xsdt->TableOffsetEntry; + + for (index = 0; index < num_tables; index++) { + if (GetChecksum(table, table->Length) == 0) { + + xsdt_mod->TableOffsetEntry[index-dropoffset]=xsdt->TableOffsetEntry[index]; + + char tableSig[4]; + bool oem = false; + char oemOption[OEMOPT_SIZE]; + + strlcpy(tableSig, (char*)((U32)(xsdt->TableOffsetEntry[index])), sizeof(tableSig)+1); + + sprintf(oemOption, "oem%s",tableSig ); + if (getBoolForKey(oemOption, &oem, &bootInfo->bootConfig) && oem) { // This method don't work for DSDT and FACS + + if (get_new_table_in_list(new_table_list,((U32) (table->Signature)), &new_table_index) != (void*)0ul) + new_table_list[new_table_index] = 0ul; // This way new table will not be added to the new rsdt list !! + + continue; + } + + TagPtr match_drop = XMLGetProperty(DropTables_p, (const char*)tableSig); + if ( match_drop ) { + char *tmp = XMLCastString(match_drop); + if (strcmp(tmp,"No") != 0) { + dropoffset++; + DBG("%s table dropped\n",tableSig); + continue; + } + } + + if ((new_table = (U32)get_new_table_in_list(new_table_list,((U32) (table->Signature)), &new_table_index)) != 0ul) + { + xsdt_mod->TableOffsetEntry[index-dropoffset]=(U64)new_table; + new_table_list[new_table_index] = 0ul; // table replaced !! + continue; + } + } + // Move array pointer to next 64-bit pointer + table = (ACPI_TABLE_HEADER *) ((U32) table + sizeof(U64)); + } + + + { + U8 i; + for (i = 0; i< (MAX_ACPI_TABLE + RESERVED_AERA); i++) { + if (new_table_list[i] != 0ul) { + xsdt_mod->TableOffsetEntry[index-dropoffset]=(U64)new_table_list[i]; + table_added++; + index++; + } + } + } + + // Correct the checksum of XSDT + xsdt_mod->Header.Length-=8*dropoffset; + xsdt_mod->Header.Length+=8*table_added; + + SetChecksum(&xsdt_mod->Header); + + update_rsdp_with_xsdt(rsdp_mod, xsdt_mod); + + verbose("* Creating new RSDT from XSDT table\n"); + + rsdt_conv = (ACPI_TABLE_RSDT *)gen_alloc_rsdt_from_xsdt(xsdt_mod); + update_rsdp_with_rsdt(rsdp_mod, rsdt_conv); + + + + } + else + { + 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->XsdtPhysicalAddress=0xffffffffffffffffLL; + verbose("XSDT not found or XSDT incorrect\n"); + } + +} + +void process_rsdt(ACPI_TABLE_RSDP *rsdp_mod , bool gen_xsdt, U32 *new_table_list) +{ + TagPtr DropTables_p = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"ACPIDropTables")); + U32 new_table = 0ul; + U8 new_table_index = 0, table_added = 0; + U32 dropoffset=0, index; + ACPI_TABLE_RSDT *rsdt = (void *)0ul, *rsdt_mod = (void *)0ul; + ACPI_TABLE_XSDT *xsdt_conv = (void *)0ul; + + rsdt=(ACPI_TABLE_RSDT *)acpi_tables.RsdtPointer; + + DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Header.Length); + + rsdt_mod=(ACPI_TABLE_RSDT *)AllocateKernelMemory(rsdt->Header.Length); + bzero(rsdt_mod, rsdt->Header.Length); + memcpy (&rsdt_mod->Header, &rsdt->Header, sizeof(ACPI_TABLE_HEADER)); + + U32 num_tables = get_num_tables(rsdt); + + verbose("* Processing RSDT: \n"); + ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) rsdt->TableOffsetEntry; + + // Compute number of table pointers included in RSDT + num_tables = get_num_tables(rsdt); + + for (index = 0; index < num_tables; index++) { + if (GetChecksum(table_array[index], table_array[index]->Length) == 0) { + + rsdt_mod->TableOffsetEntry[index-dropoffset]=rsdt->TableOffsetEntry[index]; + + char tableSig[4]; + bool oem = false; + char oemOption[OEMOPT_SIZE]; + + strlcpy(tableSig, (char*)(rsdt->TableOffsetEntry[index]), sizeof(tableSig)+1); + + sprintf(oemOption, "oem%s",tableSig ); + if (getBoolForKey(oemOption, &oem, &bootInfo->bootConfig) && oem) { // This method don't work for DSDT and FACS + + if (get_new_table_in_list(new_table_list,(*(U32 *) (table_array[index]->Signature)), &new_table_index) != (void*)0ul ) + new_table_list[new_table_index] = 0ul; // This way new table will not be added to the new rsdt list !! + + continue; + } + + TagPtr match_drop = XMLGetProperty(DropTables_p, (const char*)tableSig); + if ( match_drop ) { + char *tmp = XMLCastString(match_drop); + if (strcmp(tmp,"No") != 0) { + dropoffset++; + DBG("%s table dropped\n",tableSig); + continue; + } + } + + if ((new_table = (U32)get_new_table_in_list(new_table_list,(*(U32 *) (table_array[index]->Signature)), &new_table_index)) != 0ul) + { + rsdt_mod->TableOffsetEntry[index-dropoffset]=new_table; + new_table_list[new_table_index] = 0ul; // table replaced !! + continue; + } + + } + } + DBG("\n"); + + { + U8 i; + for (i = 0; i< (MAX_ACPI_TABLE + RESERVED_AERA); i++) { + if (new_table_list[i] != 0ul) { + rsdt_mod->TableOffsetEntry[index-dropoffset]=new_table_list[i]; + table_added++; + index++; + } + } + } + + // Correct the checksum of RSDT + rsdt_mod->Header.Length-=4*dropoffset; + rsdt_mod->Header.Length+=4*table_added; + + DBG("RSDT: Original checksum %d\n", rsdt_mod->Header.Checksum); + + SetChecksum(&rsdt_mod->Header); + + DBG("New checksum %d at %x\n", rsdt_mod->Header.Checksum,rsdt_mod); + + update_rsdp_with_rsdt(rsdp_mod, rsdt_mod); + + if (gen_xsdt) + { + verbose("* Creating new XSDT from RSDT table\n"); + xsdt_conv = (ACPI_TABLE_XSDT *)gen_alloc_xsdt_from_rsdt(rsdt_mod); + update_rsdp_with_xsdt(rsdp_mod, xsdt_conv); + + } +} + + + +EFI_STATUS setupAcpi(void) +{ + U8 Revision = 0; + + cpu_map_error = 0; + cpu_map_count = 0; + pmbase = 0; + + EFI_STATUS Status = EFI_ABORTED; + + U32 new_table_list[MAX_ACPI_TABLE + RESERVED_AERA]; //max table + reserved aera + U8 new_table_index = 0; + + ACPI_TABLE_DSDT* DsdtPtr = (void *)0ul; // a Pointer to the dsdt table present in fadt_mod + + ACPI_TABLE_DSDT *new_dsdt = (void *)0ul; // a Pointer to the dsdt file + ACPI_TABLE_FADT *fadt_mod = (void *)0ul; // a Pointer to the patched FACP table + ACPI_TABLE_FADT *fadt_file = (void *)0ul; // a Pointer to the (non-patched) fadt file + ACPI_TABLE_FADT *FacpPointer = (void *)0ul; // a Pointer to the non-patched FACP table, it can be a file or the FACP table found in the RSDT/XSDT + ACPI_TABLE_RSDP *rsdp_mod = (void *)0ul, *rsdp_conv = (void *)0ul; + + + U32 rsdplength; + + bool update_acpi=false, gen_xsdt=false; + + bool gen_csta=false, gen_psta=false, speed_step=false; + + bool oem_dsdt=false, oem_fadt=false; + + // Find original rsdp + if (!FindAcpiTables(&acpi_tables)){ + printf("Error: AcpiCodec Failed to detect ACPI tables.\n"); + getc(); + return EFI_NOT_FOUND; + } + + { + U8 i; + + for (i=0; i<(MAX_ACPI_TABLE + RESERVED_AERA); i++) { + new_table_list[i] = 0ul; + } + bool tmpval; + + oem_dsdt=getBoolForKey(kOEMDSDT, &tmpval, &bootInfo->bootConfig)&&tmpval; + oem_fadt=getBoolForKey(kOEMFADT, &tmpval, &bootInfo->bootConfig)&&tmpval; + + + gen_csta=getBoolForKey(kGenerateCStates, &tmpval, &bootInfo->bootConfig)&&tmpval; + gen_psta=getBoolForKey(kGeneratePStates, &tmpval, &bootInfo->bootConfig)&&tmpval; + + update_acpi=getBoolForKey(kUpdateACPI, &tmpval, &bootInfo->bootConfig)&&tmpval; + + speed_step=getBoolForKey(kSpeedstep, &tmpval, &bootInfo->bootConfig)&&tmpval; + + } + + { + char* name; + long flags; + long time; + long ret = -1; + U8 i = 0; + char dirspec[512]; + bool acpidir_found = false; + + ret = GetFileInfo("/Extra/", "Acpi", &flags, &time); + if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) { + sprintf(dirspec, "/Extra/Acpi/"); + acpidir_found = true; + + } else { + ret = GetFileInfo("bt(0,0)/Extra/", "Acpi", &flags, &time); + if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) { + sprintf(dirspec, "bt(0,0)/Extra/Acpi/"); + acpidir_found = true; + + } + } + + if (acpidir_found == true) { + struct dirstuff* moduleDir = opendir(dirspec); + while(readdir(moduleDir, (const char**)&name, &flags, &time) >= 0) + { + if((strcmp(&name[strlen(name) - sizeof("aml")], ".aml") == 0) && ((strlen(dirspec)+strlen(name)) < 512)) + { + // Some simple verifications to save time in case of those tables simply named as follow: + if ((strncmp(name, "RSDT", 4) == 0) || (strncmp(name, "rsdt", 4) == 0) || + (strncmp(name, "XSDT", 4) == 0) || (strncmp(name, "xsdt", 4) == 0) || + (strncmp(name, "RSDP", 4) == 0) || (strncmp(name, "rsdp", 4) == 0)) + { + continue; + } + + if ((strncmp(name, "FACS", 4) == 0) || (strncmp(name, "facs", 4) == 0)) { // For now FACS is not supported + continue; + } + + char* tmp = malloc(strlen(name) + 1); + strcpy(tmp, name); + + DBG("* Attempting to load acpi table: %s\n", tmp); + if( (new_table_list[i]=(U32)loadACPITable(dirspec,tmp))) + { + if (i < MAX_ACPI_TABLE) { + i++; + } else { + break; + } + + + } else { + free(tmp); + } + + } +#if DEBUG_ACPI + else + { + DBG("Ignoring %s\n", name); + } +#endif + + } + + if (i) { + //sanitize the new tables list + sanitize_new_table_list(new_table_list); + + //move to kernel memory + move_table_list_to_kmem(new_table_list); + + DBG("New ACPI tables Loaded in memory\n"); + } + } + + } + + // TODO : Add an option for that + //cpuNamespace = CPU_NAMESPACE_PR; //Default + + + if (speed_step) { + gen_psta= true; + gen_csta= true; + } + + + ACPI_TABLE_RSDP *rsdp=(ACPI_TABLE_RSDP *)acpi_tables.RsdPointer; + + if (rsdp == (void*)0ul || (GetChecksum(rsdp, (rsdp->Revision == 0) ? ACPI_RSDP_REV0_SIZE:sizeof(ACPI_TABLE_RSDP)) != 0) ) { + printf("Error : ACPI RSD PTR Revision %d checksum is incorrect or table not found \n",rsdp->Revision ); + return EFI_UNSUPPORTED; + } + + if ((update_acpi) && (rsdp->Revision == 0)) + { + + rsdp_conv = (ACPI_TABLE_RSDP *)gen_alloc_rsdp_v2_from_v1(rsdp); + if (rsdp_conv != (void *)0ul) { + gen_xsdt = true; + rsdp = rsdp_conv; + verbose("Converted ACPI RSD PTR Revision 0 to Revision 2\n"); + } + + } + + Revision = rsdp->Revision ; + rsdplength=(Revision == 2)?rsdp->Length:ACPI_RSDP_REV0_SIZE; + + DBG("RSDP Revision %d found @%x. Length=%d\n",Revision,rsdp,rsdplength); + + /* FIXME: no check that memory allocation succeeded + * Copy and patch RSDP,RSDT, XSDT and FADT + * For more info see ACPI Specification pages 110 and following + */ + + if (gen_xsdt) + { + rsdp_mod=rsdp_conv; + } else { + rsdp_mod=(ACPI_TABLE_RSDP *) AllocateKernelMemory(rsdplength); + memcpy(rsdp_mod, rsdp, rsdplength); + } + + + if ((fadt_file = (ACPI_TABLE_FADT *)get_new_table_in_list(new_table_list, NAMESEG("FACP"), &new_table_index)) != (void *)0ul) { + + if (oem_fadt == false) + FacpPointer = (ACPI_TABLE_FADT *)fadt_file; + + new_table_list[new_table_index] = 0ul; // This way, the non-patched table will not be added in our new rsdt/xsdt table list + + } else + FacpPointer = (acpi_tables.FacpPointer64 != (void *)0ul) ? + (ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer; + +#if DEBUG_ACPI + if ((FacpPointer != (void *)0ul) || (oem_fadt == false)) { + printf("FADT found @%x, Length %d\n",FacpPointer, FacpPointer->Header.Length); + printf("Attempting to patch FADT entry of %s\n",(acpi_tables.FacpPointer64 != (void *)0ul) ? ACPI_SIG_XSDT : ACPI_SIG_RSDT); + } +#endif + + if ((new_dsdt = (ACPI_TABLE_DSDT *)get_new_table_in_list(new_table_list, NAMESEG("DSDT"), &new_table_index)) != (void*)0ul ) { + new_table_list[new_table_index] = 0ul; // This way, the DSDT file will not be added in our new rsdt/xsdt table list, and it shouldn't be anyway + } + + if (oem_fadt == false) { + + fadt_mod = patch_fadt(FacpPointer, (oem_dsdt == false) ? new_dsdt : (void*)0ul , (acpi_tables.FacpPointer64 != (void *)0ul )); + + + DsdtPtr = ((fadt_mod->Header.Revision >= 3) && (fadt_mod->XDsdt != 0)) ? (ACPI_TABLE_DSDT*)((U32)fadt_mod->XDsdt):(ACPI_TABLE_DSDT*)fadt_mod->Dsdt; + + if (fadt_mod != (void*)0ul) { + + U8 empty = get_0ul_index_in_list(new_table_list,true); + if (empty != ACPI_TABLE_LIST_FULL) { + new_table_list[empty] = (U32)fadt_mod; // add the patched table to the list + } else { + printf("Error: not enought reserved space in the new acpi list for the Patched FACP table,\n "); + printf(" please increase the RESERVED_AERA\n"); + } + + } else { + printf("Error: Failed to patch the FADT Table, trying fallback to the FADT original pointer\n"); + fadt_mod = (acpi_tables.FacpPointer64 != (void *)0ul) ? + (ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer; + + U8 empty = get_0ul_index_in_list(new_table_list,true); + if (empty != ACPI_TABLE_LIST_FULL) { + new_table_list[empty] = (U32)fadt_mod; + } else { + printf("Error: not enought reserved space in the new acpi list for the FACP table,\n "); + printf(" please increase the RESERVED_AERA\n"); + } + } + + if (oem_dsdt == false) { + if (generate_cpu_map_from_acpi(DsdtPtr) == 0){ + U8 new_uid = (U8)getPciRootUID(); + + /* WARNING: THIS METHOD WORK PERFECTLY BUT IT CAN RESULT TO AN INCORRECT CHECKSUM */ + + if (ProcessDsdt(DsdtPtr, UIDPointer, new_uid)) { + printf("PCI0 _UID patched to %d in the DSDT table\n", new_uid); + } + + } + } + + + } else { + + // here we use the variable fadt_mod only for SSDT Generation + + fadt_mod = (acpi_tables.FacpPointer64 != (void *)0ul) ? + (ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer; + + DsdtPtr = ((fadt_mod->Header.Revision >= 3) && (fadt_mod->XDsdt != 0)) ? (ACPI_TABLE_DSDT*)((U32)fadt_mod->XDsdt) + :(ACPI_TABLE_DSDT*)fadt_mod->Dsdt; + } + + if (speed_step || gen_csta || gen_psta) { + U8 empty = get_0ul_index_in_list(new_table_list, true); + + // Generate _CST SSDT + if ( speed_step || gen_csta) + { + if (empty != ACPI_TABLE_LIST_FULL) { + if (new_table_list[empty] =(U32)generate_cst_ssdt(fadt_mod)) + { + if (speed_step || gen_psta) + empty = get_0ul_index_in_list(new_table_list,true); + } + } else { + printf("Error: not enought reserved space in the new acpi list for the _CST SSDT table,\n "); + printf(" please increase the RESERVED_AERA\n"); + } + } + + + // Generating _PSS SSDT + if (speed_step || gen_psta) + { + if (empty != ACPI_TABLE_LIST_FULL) { + + new_table_list[empty] =(U32)generate_pss_ssdt(DsdtPtr); + + } else { + printf("Error: not enought reserved space in the new acpi list for the _PSS SSDT table,\n "); + printf(" please increase the RESERVED_AERA\n"); + } + } + } + + if ((rsdp_mod != (void *)0ul) && (rsdp_mod->Length >= ACPI_RSDP_REV0_SIZE) ) + { + if ((rsdp_mod->Revision == 0) || (gen_xsdt == true)) { + process_rsdt(rsdp_mod, gen_xsdt, new_table_list); + goto out; + } + + } else { + printf("Error: Incorect ACPI RSD PTR or not found \n"); + return EFI_UNSUPPORTED; + } + + if ((GetChecksum(rsdp_mod, sizeof(ACPI_TABLE_RSDP)) == 0) && + (Revision == 2) && + (rsdplength == sizeof(ACPI_TABLE_RSDP))) + { + process_xsdt(rsdp_mod, new_table_list); + } else { + printf("Warning : ACPI RSD PTR Revision 2 is incorrect, \n"); + printf(" trying to fallback to Revision 1\n"); + if ((rsdp_mod != (void *)0ul) && (rsdp_mod->Length >= ACPI_RSDP_REV0_SIZE) ) + { + process_rsdt(rsdp_mod, false, new_table_list); + + } else { + printf("Error: Incorect ACPI RSD PTR or not found \n"); + return EFI_UNSUPPORTED; + } + } + +out: + // Correct the checksum of RSDP + + DBG("RSDP: Original checksum %d\n", rsdp_mod->Checksum); + + setRsdpchecksum(rsdp_mod); + + DBG("New checksum %d\n", rsdp_mod->Checksum); + + if (Revision == 2) + { + DBG("RSDP: Original extended checksum %d\n", rsdp_mod->ExtendedChecksum); + + setRsdpXchecksum(rsdp_mod); + + DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum); + + } + + verbose("ACPI Revision %d successfully patched\n", Revision); + + if (Revision == 2) + { + rsd_p = ((U64)((U32)rsdp_mod)); + if (rsd_p) + Status = addConfigurationTable(&gEfiAcpi20TableGuid, &rsd_p, "ACPI_20"); + } + else + { + rsd_p = ((U64)((U32)rsdp_mod)); + if (rsd_p) + Status = addConfigurationTable(&gEfiAcpiTableGuid, &rsd_p, "ACPI"); + + } + +#if DEBUG_ACPI + printf("Press a key to continue... (DEBUG_DSDT)\n"); + getc(); +#endif + return Status; +} Property changes on: branches/cparm/i386/modules/ACPICodec/acpi_codec.c ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/modules/ACPICodec/ACPICodec.c =================================================================== --- branches/cparm/i386/modules/ACPICodec/ACPICodec.c (revision 0) +++ branches/cparm/i386/modules/ACPICodec/ACPICodec.c (revision 1119) @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010 cparm . All rights reserved. + * + */ + +#include "libsaio.h" +#include "modules.h" +#include "boot.h" +#include "bootstruct.h" +#include "pci_root.h" +#include "acpi_codec.h" + +#define kEnableAcpi "EnableAcpiModule" + +void ACPICodec_setupEfiConfigurationTable_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) +{ + EFI_STATUS *ret = (EFI_STATUS *)arg1; + + // Setup ACPI (mackerintel's patch) + *ret = setupAcpi(); + +} + +void is_ACPI_Codec_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6){} + +void ACPICodec_start() +{ + bool enable = true; + getBoolForKey(kEnableAcpi, &enable, &bootInfo->bootConfig) ; + + /* + * This method is not perfect (symbols collisions between two modules with that provide the same service is still possible, + * (as well as two module with a different service but there is more chance of collisions if dthey do the same thing) + * even if one of them have been disabled by this method and have no hook registred), will be deprecated soon. + * + * Possible solutions: + * + * 1 - check the symbols list each time a symbols is loaded to avoid double symbol (slow, may be buggy) + * + * 2 - categorize all symbols by callers (hard to implement) + * + * 3 - ????, will work great at least for modules with the same service + * + * + * + */ + enable = (execute_hook("isACPIRegistred", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS); + + if (enable) { + register_hook_callback("setupEfiConfigurationTable", &ACPICodec_setupEfiConfigurationTable_hook); + register_hook_callback("isACPIRegistred", &is_ACPI_Codec_Registred_Hook); + + } +} \ No newline at end of file Property changes on: branches/cparm/i386/modules/ACPICodec/ACPICodec.c ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/modules/ACPICodec/Makefile =================================================================== --- branches/cparm/i386/modules/ACPICodec/Makefile (revision 0) +++ branches/cparm/i386/modules/ACPICodec/Makefile (revision 1119) @@ -0,0 +1,99 @@ + +MODULE_NAME = ACPICodec +MODULE_VERSION = "1.0.0" +MODULE_COMPAT_VERSION = "1.0.0" +MODULE_START = _$(MODULE_NAME)_start +MODULE_DEPENDENCIES = + +DIR = ACPICodec + +include ../../MakePaths.dir + +OBJROOT=../../../obj/i386/modules/$(DIR) +SYMROOT=../../../sym/i386/modules/ +DSTROOT=../../../dst/i386/modules/ + + +UTILDIR = ../../util +LIBSADIR = ../../libsa +LIBSAIODIR = ../../libsaio +BOOT2DIR = ../../boot2 + +INSTALLDIR = $(DSTROOT)/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/standalone + +OPTIM = -Os -Oz +DEBUG = -DNOTHING +CFLAGS = $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost \ + -D__ARCHITECTURE__=\"i386\" -DSAIO_INTERNAL_USER \ + -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ + -fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \ + -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ + -march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common #-lc_kext #-mdynamic-no-pic -Wextra -Wpacked -Wpadded -Wunreachable-code -Winline -Wunsafe-loop-optimizations -funsafe-loop-optimizations -Wconversion + +DEFINES= +CONFIG = hd +INC = -I. -I.. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR) -I$(LIBSAIODIR) -I$(BOOT2DIR) +ifneq "" "$(wildcard /bin/mkdirs)" + MKDIRS = /bin/mkdirs +else + MKDIRS = /bin/mkdir -p +endif +AS = as +LD = ld +# LIBS= -lc_static +LIBS= + +VPATH = $(OBJROOT):$(SYMROOT) + +ACPI_CODEC_OBJS = ACPICodec.o acpicode.o acpidecode.o aml_generator.o acpi_codec.o + + +SFILES = +CFILES = +HFILES = +EXPORTED_HFILES = +INSTALLED_HFILES = +OTHERFILES = Makefile +ALLSRC = $(SFILES) $(CFILES) \ + $(HFILES) $(OTHERFILES) +DIRS_NEEDED = $(OBJROOT) $(SYMROOT) + +all embedtheme: ${ACPI_CODEC_OBJS} dylib + + +dylib: + ld -arch i386 \ + -undefined dynamic_lookup \ + -alias $(MODULE_START) start \ + -dylib -read_only_relocs suppress \ + -S -x -Z -dead_strip_dylibs \ + -no_uuid \ + -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ + -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ + $(OBJROOT)/acpicode.o \ + $(OBJROOT)/acpidecode.o \ + $(OBJROOT)/ACPICodec.o \ + $(OBJROOT)/aml_generator.o \ + $(OBJROOT)/acpi_codec.o \ + -o $(SYMROOT)/$(MODULE_NAME).dylib + +ACPICodec.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "ACPICodec.c" $(INC) -o "$(OBJROOT)/ACPICodec.o" + +aml_generator.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "aml_generator.c" $(INC) -o "$(OBJROOT)/aml_generator.o" + +acpi_patcher.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "acpi_codec.c" $(INC) -o "$(OBJROOT)/acpi_codec.o" + +acpi_decode.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "acpidecode.c" $(INC) -o "$(OBJROOT)/acpidecode.o" + +acpi_code.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "acpicode.c" $(INC) -o "$(OBJROOT)/acpicode.o" + +include ../../MakeInc.dir + +# dependencies +-include $(OBJROOT)/Makedep Property changes on: branches/cparm/i386/modules/ACPICodec/Makefile ___________________________________________________________________ Added: svn:executable + * Index: branches/cparm/i386/modules/ACPICodec/acpicode.h =================================================================== --- branches/cparm/i386/modules/ACPICodec/acpicode.h (revision 0) +++ branches/cparm/i386/modules/ACPICodec/acpicode.h (revision 1119) @@ -0,0 +1,75 @@ +/* +Copyright (c) 2010, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef acpi_code_h +#define acpi_code_h + +#include "datatype.h" +#include "acpi.h" +#include "ppm.h" + +void setRsdpchecksum(ACPI_TABLE_RSDP *rsdp); +void setRsdpXchecksum(ACPI_TABLE_RSDP *rsdp); +void update_rsdp_with_xsdt(ACPI_TABLE_RSDP *rsdp, ACPI_TABLE_XSDT *xsdt); +void update_rsdp_with_rsdt(ACPI_TABLE_RSDP *rsdp, ACPI_TABLE_RSDT *rsdt); + +void SetChecksum(struct acpi_table_header *header); +U32 ProcessMadt(ACPI_TABLE_MADT * madt, MADT_INFO * madt_info); +void MoveRsdtInsertSsdt(ACPI_TABLE_RSDP * RsdPointer, ACPI_TABLE_RSDT * OldRsdtPointer, ACPI_TABLE_RSDT * NewRsdtPointer, ACPI_TABLE_SSDT * SsdtPointer); +void InsertSsdt(ACPI_TABLE_RSDT * RsdtPointer, ACPI_TABLE_SSDT * SsdtPointer); +void InsertSsdt64(ACPI_TABLE_XSDT * XsdtPointer, ACPI_TABLE_SSDT * SsdtPointer); +U32 ProcessFadt(ACPI_TABLE_FADT * FadtPointer, U32 pmbase); +U32 ProcessDsdt(ACPI_TABLE_DSDT * DsdtPointer, U8 * PCIUIDPointer, U8 uid); + +void setByteConst(ACPI_BYTE_CONST * byteConst, U8 byteData); +void *buildByteConst(void *current, U8 byteData); +void setWordConst(ACPI_WORD_CONST * wordConst, U16 wordData); +void *buildWordConst(void *current, U16 wordData); +void setDwordConst(ACPI_DWORD_CONST * dwordConst, U32 dwordData); +void *buildDwordConst(void *current, U32 dwordData); +void *buildSmallBuffer(void *current); +void *buildEndTag(void *current); +void *buildGenericRegister(void *current, const ACPI_GENERIC_ADDRESS * gas); + +void *buildSmallMethod(void *current, U32 name, U8 methodFlags); +void *buildMethod(void *current, U32 name, U8 methodFlags); +void *buildReturnZero(void *current); +void *buildReturnOpcode(void *current, U8 opcodeToReturn); +void *buildReturnPackage(void *current, U8 numElements); +void *buildNamedDword(void *current, U32 name, U32 dword); +void *buildOpCode(void *current, U8 opCode); + +void *buildNameSeg(void *current, U32 name); +void setSmallPackage(ACPI_SMALL_PACKAGE * package, U8 numElements); +void *buildSmallPackage(void *current, U8 numElements); +void setPackageLength(ACPI_PACKAGE_LENGTH * packageLength, U32 length); +void *buildPackageLength(void *current, U32 Length); +void *buildNamePath(void *current, U32 name); +void *buildTableHeader(void *current, U32 signature, U64 oemTableId); + +#endif // acpi_code_h Index: branches/cparm/i386/modules/HelloWorld/HelloWorld.c =================================================================== --- branches/cparm/i386/modules/HelloWorld/HelloWorld.c (revision 1118) +++ branches/cparm/i386/modules/HelloWorld/HelloWorld.c (revision 1119) @@ -24,6 +24,5 @@ { register_hook_callback("ExecKernel", &helloWorld2); register_hook_callback("PreBoot", &helloWorld); - } Index: branches/cparm/i386/modules/HelloWorld/Makefile =================================================================== --- branches/cparm/i386/modules/HelloWorld/Makefile (revision 1118) +++ branches/cparm/i386/modules/HelloWorld/Makefile (revision 1119) @@ -70,6 +70,7 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ + "/usr/lib/gcc/i686-apple-darwin10/4.2.1/libcc_kext.a" \ $(OBJROOT)/HelloWorld.o -o $(SYMROOT)/$(MODULE_NAME).dylib Index: branches/cparm/i386/modules/Makefile =================================================================== --- branches/cparm/i386/modules/Makefile (revision 1118) +++ branches/cparm/i386/modules/Makefile (revision 1119) @@ -26,7 +26,7 @@ VPATH = $(OBJROOT):$(SYMROOT) # The order of building is important. -SUBDIRS = Resolution KernelPatcher KextPatcher GUI GraphicsEnabler HPET USBFix Memory Networking ACPIPatcher NetbookInstaller CPUfreq Keymapper RamDiskLoader HibernateEnabler SMBiosPatcher SMBiosGetters HelloWorld +SUBDIRS = Resolution KernelPatcher KextPatcher GUI GraphicsEnabler HPET USBFix Memory Networking ACPICodec ACPIPatcher Bits NetbookInstaller CPUfreq Keymapper OSXInstall RamDiskLoader HibernateEnabler SMBiosPatcher SMBiosGetters HelloWorld all embedtheme tags debug install installhdrs: @rm -rf $(OBJROOT) @mkdir $(OBJROOT) Index: branches/cparm/i386/cdboot/cdboot.s =================================================================== --- branches/cparm/i386/cdboot/cdboot.s (revision 1118) +++ branches/cparm/i386/cdboot/cdboot.s (revision 1119) @@ -406,7 +406,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: branches/cparm/i386/cdboot/cdboothdd.s =================================================================== --- branches/cparm/i386/cdboot/cdboothdd.s (revision 1118) +++ branches/cparm/i386/cdboot/cdboothdd.s (revision 1119) @@ -320,7 +320,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: branches/cparm/i386/libsa/libsa.h =================================================================== --- branches/cparm/i386/libsa/libsa.h (revision 1118) +++ branches/cparm/i386/libsa/libsa.h (revision 1119) @@ -145,14 +145,14 @@ extern void free(void * start); extern void * realloc(void * ptr, size_t size); -//#ifdef SAFE_MALLOC -#define malloc(size) safe_malloc(size, __FILE__, __LINE__) -extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int)); -extern void * safe_malloc(size_t size, const char *file, int line); -extern size_t zalloced_size; +//#if SAFE_MALLOC +//#define malloc(size) safe_malloc(size, __FILE__, __LINE__) +//extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int)); +//extern void * safe_malloc(size_t size, const char *file, int line); +//extern size_t zalloced_size; //#else -//extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t)); -//extern void * malloc(size_t size); +extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t)); +extern void * malloc(size_t size); //#endif /* Index: branches/cparm/i386/libsa/string.c =================================================================== --- branches/cparm/i386/libsa/string.c (revision 1118) +++ branches/cparm/i386/libsa/string.c (revision 1119) @@ -56,6 +56,11 @@ memset(dst, 0, len); } +void __bzero(void * dst, size_t len) +{ + memset(dst, 0, len); +} + #else void * memcpy(void * dst, const void * src, size_t len) { @@ -101,13 +106,27 @@ : "c" (len), "D" (dst) : "memory", "%eax" ); } + +void __bzero(void * dst, size_t len) +{ + asm volatile ( "xorl %%eax, %%eax \n\t" + "cld \n\t" + "movl %%ecx, %%edx \n\t" + "shrl $2, %%ecx \n\t" + "rep; stosl \n\t" + "movl %%edx, %%ecx \n\t" + "andl $3, %%ecx \n\t" + "rep; stosb \n\t" + : + : "c" (len), "D" (dst) + : "memory", "%eax" ); +} #endif /* #if DONT_USE_GCC_BUILT_IN_STRLEN */ -#define tolower(c) ((int)((c) & ~0x20)) -#define toupper(c) ((int)((c) | 0x20)) + int strlen(const char * s) { int n = 0; @@ -151,7 +170,7 @@ strcpy(char * s1, const char * s2) { register char *ret = s1; - while (*s1++ = *s2++) + while ((*s1++ = *s2++)) continue; return ret; } @@ -247,6 +266,10 @@ } #if STRNCASECMP + +#define tolower(c) ((int)((c) & ~0x20)) +#define toupper(c) ((int)((c) | 0x20)) + int strncasecmp(const char *s1, const char *s2, size_t len) { register int n = len; Index: branches/cparm/i386/libsa/prf.c =================================================================== --- branches/cparm/i386/libsa/prf.c (revision 1118) +++ branches/cparm/i386/libsa/prf.c (revision 1119) @@ -151,7 +151,7 @@ break; case 's': s = (char *)*adx; - while (c = *s++) { + while ((c = *s++)) { (*putfn_p)(c, putfn_arg); width++; } @@ -161,6 +161,8 @@ case 'c': (*putfn_p)((char)*adx, putfn_arg); break; + default: + break; } adx++; goto loop; Index: branches/cparm/i386/libsa/strtol.c =================================================================== --- branches/cparm/i386/libsa/strtol.c (revision 1118) +++ branches/cparm/i386/libsa/strtol.c (revision 1119) @@ -148,7 +148,7 @@ break; if (c >= base) break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) any = -1; else { any = 1; @@ -220,7 +220,7 @@ break; if (c >= base) break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) any = -1; else { any = 1; @@ -291,7 +291,7 @@ break; if (c >= base) break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) any = -1; else { any = 1; Index: branches/cparm/i386/libsa/Makefile =================================================================== --- branches/cparm/i386/libsa/Makefile (revision 1118) +++ branches/cparm/i386/libsa/Makefile (revision 1119) @@ -11,7 +11,7 @@ CFLAGS = $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost -Werror \ -fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ - -march=pentium4 -msse2 -mfpmath=sse -msoft-float + -march=pentium4 -msse2 -mfpmath=sse -msoft-float INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSAIODIR) ifneq "" "$(wildcard /bin/mkdirs)" @@ -29,11 +29,13 @@ SA_OBJS = prf.o printf.o zalloc.o \ string.o strtol.o error.o \ setjmp.o qsort.o efi_tables.o + SFILES = setjmp.s CFILES = prf.c printf.c zalloc.c \ string.c strtol.c error.c \ qsort.c efi_tables.c + HFILES = memory.h EXPORTED_HFILES = libsa.h memory.h INSTALLED_SA_HFILES = libsa.h @@ -42,7 +44,7 @@ LIBS = libsa.a DIRS_NEEDED = $(OBJROOT) $(SYMROOT) -CFLAGS += -DSAFE_MALLOC +#CFLAGS += -DSAFE_MALLOC all embedtheme: $(DIRS_NEEDED) $(LIBS)