diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2008-07-08 21:58:43 +1000 |
---|---|---|
committer | Dave Airlie <airlied@linux.ie> | 2008-07-08 21:58:43 +1000 |
commit | 61f82ace0210251beb0bcc492218a75a193e1deb (patch) | |
tree | ce52271828fe27cab43cabc7b5adeba421bde1d7 /src/AtomBios | |
parent | b4d1a47b5c6eafda5e274398eebe2701b030f22e (diff) |
atombios: add support for other endians.
This is a cleaned up (in as much as atombios can be..) of benh's patch.
airlied - removed benh's debugging for now, it might need to be put back later..
Diffstat (limited to 'src/AtomBios')
-rw-r--r-- | src/AtomBios/CD_Operations.c | 61 | ||||
-rw-r--r-- | src/AtomBios/Decoder.c | 108 | ||||
-rw-r--r-- | src/AtomBios/hwserv_drv.c | 14 | ||||
-rw-r--r-- | src/AtomBios/includes/CD_Common_Types.h | 12 | ||||
-rw-r--r-- | src/AtomBios/includes/CD_Definitions.h | 3 | ||||
-rw-r--r-- | src/AtomBios/includes/CD_Structs.h | 24 | ||||
-rw-r--r-- | src/AtomBios/includes/Decoder.h | 24 | ||||
-rw-r--r-- | src/AtomBios/includes/atombios.h | 24 |
8 files changed, 184 insertions, 86 deletions
diff --git a/src/AtomBios/CD_Operations.c b/src/AtomBios/CD_Operations.c index 509aa0c4..58c4ae9c 100644 --- a/src/AtomBios/CD_Operations.c +++ b/src/AtomBios/CD_Operations.c @@ -44,7 +44,6 @@ Revision History: #include "xorg-server.h" #include "Decoder.h" -#include "atombios.h" VOID PutDataRegister(PARSER_TEMP_DATA STACK_BASED * pParserTempData); VOID PutDataPS(PARSER_TEMP_DATA STACK_BASED * pParserTempData); @@ -231,7 +230,7 @@ UINT32 IndirectInputOutput(PARSER_TEMP_DATA STACK_BASED * pParserTempData) IndirectIOParserCommands[*pParserTempData->IndirectIOTablePointer].func(pParserTempData); pParserTempData->IndirectIOTablePointer+=IndirectIOParserCommands[*pParserTempData->IndirectIOTablePointer].csize; } - pParserTempData->IndirectIOTablePointer-=*(UINT16*)(pParserTempData->IndirectIOTablePointer+1); + pParserTempData->IndirectIOTablePointer-=UINT16LE_TO_CPU(*(UINT16*)(pParserTempData->IndirectIOTablePointer+1)); pParserTempData->IndirectIOTablePointer++; return pParserTempData->IndirectData; } else pParserTempData->IndirectIOTablePointer+=IndirectIOParserCommands[*pParserTempData->IndirectIOTablePointer].csize; @@ -243,7 +242,7 @@ UINT32 IndirectInputOutput(PARSER_TEMP_DATA STACK_BASED * pParserTempData) VOID PutDataRegister(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { - pParserTempData->Index=(UINT32)pParserTempData->pCmd->Parameters.WordXX.PA_Destination; + pParserTempData->Index=(UINT32)UINT16LE_TO_CPU(pParserTempData->pCmd->Parameters.WordXX.PA_Destination); pParserTempData->Index+=pParserTempData->CurrentRegBlock; switch(pParserTempData->Multipurpose.CurrentPort){ case ATI_RegsPort: @@ -269,16 +268,16 @@ VOID PutDataRegister(PARSER_TEMP_DATA STACK_BASED * pParserTempData) VOID PutDataPS(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { *(pParserTempData->pDeviceData->pParameterSpace+pParserTempData->pCmd->Parameters.ByteXX.PA_Destination)= - pParserTempData->DestData32; + CPU_TO_UINT32LE(pParserTempData->DestData32); } VOID PutDataWS(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { if (pParserTempData->pCmd->Parameters.ByteXX.PA_Destination < WS_QUOTIENT_C) - *(pParserTempData->pWorkingTableData->pWorkSpace+pParserTempData->pCmd->Parameters.ByteXX.PA_Destination) = pParserTempData->DestData32; + *(pParserTempData->pWorkingTableData->pWorkSpace+pParserTempData->pCmd->Parameters.ByteXX.PA_Destination) = pParserTempData->DestData32; else - switch (pParserTempData->pCmd->Parameters.ByteXX.PA_Destination) - { + switch (pParserTempData->pCmd->Parameters.ByteXX.PA_Destination) + { case WS_REMINDER_C: pParserTempData->MultiplicationOrDivision.Division.Reminder32=pParserTempData->DestData32; break; @@ -339,7 +338,7 @@ VOID SkipParameters16(PARSER_TEMP_DATA STACK_BASED * pParserTempData) UINT32 GetParametersRegister(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { - pParserTempData->Index=*(UINT16*)pParserTempData->pWorkingTableData->IP; + pParserTempData->Index=UINT16LE_TO_CPU(*(UINT16*)pParserTempData->pWorkingTableData->IP); pParserTempData->pWorkingTableData->IP+=sizeof(UINT16); pParserTempData->Index+=pParserTempData->CurrentRegBlock; switch(pParserTempData->Multipurpose.CurrentPort) @@ -361,9 +360,11 @@ UINT32 GetParametersRegister(PARSER_TEMP_DATA STACK_BASED * pParserTempData) UINT32 GetParametersPS(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { + UINT32 data; pParserTempData->Index=*pParserTempData->pWorkingTableData->IP; pParserTempData->pWorkingTableData->IP+=sizeof(UINT8); - return *(pParserTempData->pDeviceData->pParameterSpace+pParserTempData->Index); + data = UINT32LE_TO_CPU(*(pParserTempData->pDeviceData->pParameterSpace+pParserTempData->Index)); + return data; } UINT32 GetParametersWS(PARSER_TEMP_DATA STACK_BASED * pParserTempData) @@ -419,9 +420,12 @@ UINT32 GetParametersMC(PARSER_TEMP_DATA STACK_BASED * pParserTempData) UINT32 GetParametersIndirect(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { - pParserTempData->Index=*(UINT16*)pParserTempData->pWorkingTableData->IP; + UINT32 ret; + + pParserTempData->Index=UINT16LE_TO_CPU(*(UINT16*)pParserTempData->pWorkingTableData->IP); pParserTempData->pWorkingTableData->IP+=sizeof(UINT16); - return *(UINT32*)(RELATIVE_TO_BIOS_IMAGE(pParserTempData->Index)+pParserTempData->CurrentDataBlock); + ret = UINT32LE_TO_CPU(*(UINT32*)(RELATIVE_TO_BIOS_IMAGE(pParserTempData->Index)+pParserTempData->CurrentDataBlock)); + return ret; } UINT32 GetParametersDirect8(PARSER_TEMP_DATA STACK_BASED * pParserTempData) @@ -435,7 +439,7 @@ UINT32 GetParametersDirect8(PARSER_TEMP_DATA STACK_BASED * pParserTempData) UINT32 GetParametersDirect16(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { pParserTempData->CD_Mask.SrcAlignment=alignmentLowerWord; - pParserTempData->Index=*(UINT16*)pParserTempData->pWorkingTableData->IP; + pParserTempData->Index=UINT16LE_TO_CPU(*(UINT16*)pParserTempData->pWorkingTableData->IP); pParserTempData->pWorkingTableData->IP+=sizeof(UINT16); return pParserTempData->Index; } @@ -443,7 +447,7 @@ UINT32 GetParametersDirect16(PARSER_TEMP_DATA STACK_BASED * pParserTempData) UINT32 GetParametersDirect32(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { pParserTempData->CD_Mask.SrcAlignment=alignmentDword; - pParserTempData->Index=*(UINT32*)pParserTempData->pWorkingTableData->IP; + pParserTempData->Index=UINT32LE_TO_CPU(*(UINT32*)pParserTempData->pWorkingTableData->IP); pParserTempData->pWorkingTableData->IP+=sizeof(UINT32); return pParserTempData->Index; } @@ -474,7 +478,7 @@ VOID ProcessMove(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { if (pParserTempData->CD_Mask.SrcAlignment!=alignmentDword) { - pParserTempData->DestData32=GetDestination[pParserTempData->ParametersType.Destination](pParserTempData); + pParserTempData->DestData32=GetDestination[pParserTempData->ParametersType.Destination](pParserTempData); } else { SkipDestination[pParserTempData->ParametersType.Destination](pParserTempData); @@ -664,7 +668,8 @@ VOID ProcessSwitch(PARSER_TEMP_DATA STACK_BASED * pParserTempData){ pParserTempData->SourceData32=GetSource[pParserTempData->ParametersType.Source](pParserTempData); pParserTempData->SourceData32 >>= SourceAlignmentShift[pParserTempData->CD_Mask.SrcAlignment]; pParserTempData->SourceData32 &= AlignmentMask[pParserTempData->CD_Mask.SrcAlignment]; - while ( *(UINT16*)pParserTempData->pWorkingTableData->IP != (((UINT16)NOP_OPCODE << 8)+NOP_OPCODE)) + + while ( UINT16LE_TO_CPU(*(UINT16*)pParserTempData->pWorkingTableData->IP) != (((UINT16)NOP_OPCODE << 8)+NOP_OPCODE)) { if (*pParserTempData->pWorkingTableData->IP == 'c') { @@ -673,7 +678,7 @@ VOID ProcessSwitch(PARSER_TEMP_DATA STACK_BASED * pParserTempData){ pParserTempData->Index=GetParametersDirect16(pParserTempData); if (pParserTempData->SourceData32 == pParserTempData->DestData32) { - pParserTempData->pWorkingTableData->IP= RELATIVE_TO_TABLE(pParserTempData->Index); + pParserTempData->pWorkingTableData->IP= RELATIVE_TO_TABLE(pParserTempData->Index); return; } } @@ -695,7 +700,7 @@ VOID cmdSetDataBlock(PARSER_TEMP_DATA STACK_BASED * pParserTempData) } else { pMasterDataTable = GetDataMasterTablePointer(pParserTempData->pDeviceData); - pParserTempData->CurrentDataBlock= (TABLE_UNIT_TYPE)((PTABLE_UNIT_TYPE)pMasterDataTable)[value]; + pParserTempData->CurrentDataBlock= UINT16LE_TO_CPU((TABLE_UNIT_TYPE)((PTABLE_UNIT_TYPE)pMasterDataTable)[value]); } } pParserTempData->pWorkingTableData->IP+=sizeof(COMMAND_TYPE_OPCODE_VALUE_BYTE); @@ -704,13 +709,13 @@ VOID cmdSetDataBlock(PARSER_TEMP_DATA STACK_BASED * pParserTempData) VOID cmdSet_ATI_Port(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { pParserTempData->Multipurpose.CurrentPort=ATI_RegsPort; - pParserTempData->CurrentPortID = (UINT8)((COMMAND_TYPE_1*)pParserTempData->pWorkingTableData->IP)->Parameters.WordXX.PA_Destination; + pParserTempData->CurrentPortID = (UINT8)UINT16LE_TO_CPU(((COMMAND_TYPE_1*)pParserTempData->pWorkingTableData->IP)->Parameters.WordXX.PA_Destination); pParserTempData->pWorkingTableData->IP+=sizeof(COMMAND_TYPE_OPCODE_OFFSET16); } VOID cmdSet_Reg_Block(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { - pParserTempData->CurrentRegBlock = ((COMMAND_TYPE_1*)pParserTempData->pWorkingTableData->IP)->Parameters.WordXX.PA_Destination; + pParserTempData->CurrentRegBlock = UINT16LE_TO_CPU(((COMMAND_TYPE_1*)pParserTempData->pWorkingTableData->IP)->Parameters.WordXX.PA_Destination); pParserTempData->pWorkingTableData->IP+=sizeof(COMMAND_TYPE_OPCODE_OFFSET16); } @@ -754,19 +759,23 @@ VOID ProcessDebug(PARSER_TEMP_DATA STACK_BASED * pParserTempData) VOID ProcessDS(PARSER_TEMP_DATA STACK_BASED * pParserTempData) { - pParserTempData->pWorkingTableData->IP+=((COMMAND_TYPE_1*)pParserTempData->pWorkingTableData->IP)->Parameters.WordXX.PA_Destination+sizeof(COMMAND_TYPE_OPCODE_OFFSET16); + pParserTempData->pWorkingTableData->IP+=UINT16LE_TO_CPU(((COMMAND_TYPE_1*)pParserTempData->pWorkingTableData->IP)->Parameters.WordXX.PA_Destination)+sizeof(COMMAND_TYPE_OPCODE_OFFSET16); } -VOID cmdCall_Table(PARSER_TEMP_DATA STACK_BASED * pParserTempData){ +VOID cmdCall_Table(PARSER_TEMP_DATA STACK_BASED * pParserTempData) +{ UINT16* MasterTableOffset; pParserTempData->pWorkingTableData->IP+=sizeof(COMMAND_TYPE_OPCODE_VALUE_BYTE); MasterTableOffset = GetCommandMasterTablePointer(pParserTempData->pDeviceData); if(((PTABLE_UNIT_TYPE)MasterTableOffset)[((COMMAND_TYPE_OPCODE_VALUE_BYTE*)pParserTempData->pCmd)->Value]!=0 ) // if the offset is not ZERO { + ATOM_TABLE_ATTRIBUTE lTableAttr; + pParserTempData->CommandSpecific.IndexInMasterTable=GetTrueIndexInMasterTable(pParserTempData,((COMMAND_TYPE_OPCODE_VALUE_BYTE*)pParserTempData->pCmd)->Value); - pParserTempData->Multipurpose.PS_SizeInDwordsUsedByCallingTable = - (((ATOM_COMMON_ROM_COMMAND_TABLE_HEADER *)pParserTempData->pWorkingTableData->pTableHead)->TableAttribute.PS_SizeInBytes>>2); + + lTableAttr = GetCommandTableAttribute(pParserTempData->pWorkingTableData->pTableHead); + pParserTempData->Multipurpose.PS_SizeInDwordsUsedByCallingTable = (lTableAttr.PS_SizeInBytes >>2); pParserTempData->pDeviceData->pParameterSpace+= pParserTempData->Multipurpose.PS_SizeInDwordsUsedByCallingTable; pParserTempData->Status=CD_CALL_TABLE; @@ -792,7 +801,7 @@ VOID ProcessJump(PARSER_TEMP_DATA STACK_BASED * pParserTempData) (pParserTempData->ParametersType.Destination == pParserTempData->CompareFlags )) { - pParserTempData->pWorkingTableData->IP= RELATIVE_TO_TABLE(((COMMAND_TYPE_OPCODE_OFFSET16*)pParserTempData->pWorkingTableData->IP)->CD_Offset16); + pParserTempData->pWorkingTableData->IP= RELATIVE_TO_TABLE(UINT16LE_TO_CPU(((COMMAND_TYPE_OPCODE_OFFSET16*)pParserTempData->pWorkingTableData->IP)->CD_Offset16)); } else { pParserTempData->pWorkingTableData->IP+=sizeof(COMMAND_TYPE_OPCODE_OFFSET16); @@ -805,7 +814,7 @@ VOID ProcessJumpE(PARSER_TEMP_DATA STACK_BASED * pParserTempData) (pParserTempData->CompareFlags == pParserTempData->ParametersType.Destination)) { - pParserTempData->pWorkingTableData->IP= RELATIVE_TO_TABLE(((COMMAND_TYPE_OPCODE_OFFSET16*)pParserTempData->pWorkingTableData->IP)->CD_Offset16); + pParserTempData->pWorkingTableData->IP= RELATIVE_TO_TABLE(UINT16LE_TO_CPU(((COMMAND_TYPE_OPCODE_OFFSET16*)pParserTempData->pWorkingTableData->IP)->CD_Offset16)); } else { pParserTempData->pWorkingTableData->IP+=sizeof(COMMAND_TYPE_OPCODE_OFFSET16); @@ -817,7 +826,7 @@ VOID ProcessJumpNE(PARSER_TEMP_DATA STACK_BASED * pParserTempData) if (pParserTempData->CompareFlags != Equal) { - pParserTempData->pWorkingTableData->IP= RELATIVE_TO_TABLE(((COMMAND_TYPE_OPCODE_OFFSET16*)pParserTempData->pWorkingTableData->IP)->CD_Offset16); + pParserTempData->pWorkingTableData->IP= RELATIVE_TO_TABLE(UINT16LE_TO_CPU(((COMMAND_TYPE_OPCODE_OFFSET16*)pParserTempData->pWorkingTableData->IP)->CD_Offset16)); } else { pParserTempData->pWorkingTableData->IP+=sizeof(COMMAND_TYPE_OPCODE_OFFSET16); diff --git a/src/AtomBios/Decoder.c b/src/AtomBios/Decoder.c index e8b3b6ee..73aac94a 100644 --- a/src/AtomBios/Decoder.c +++ b/src/AtomBios/Decoder.c @@ -40,12 +40,9 @@ Revision History: #endif #include <X11/Xos.h> - +#include "xorg-server.h" #include "Decoder.h" -#include "atombios.h" -#include "CD_binding.h" -#include "CD_Common_Types.h" #ifndef DISABLE_EASF #include "easf.h" @@ -77,13 +74,13 @@ UINT16* GetCommandMasterTablePointer(DEVICE_DATA STACK_BASED* pDeviceData) /* make MasterTableOffset point to EASF_ASIC_SETUP_TABLE structure, including usSize. */ - MasterTableOffset = (UINT16 *) (pDeviceData->pBIOS_Image+((EASF_ASIC_DESCRIPTOR*)pDeviceData->pBIOS_Image)->usAsicSetupTable_Offset); + MasterTableOffset = (UINT16 *) (pDeviceData->pBIOS_Image+(UINT16LE_TO_CPU(((EASF_ASIC_DESCRIPTOR*)pDeviceData->pBIOS_Image)->usAsicSetupTable_Offset)); } else #endif { #ifndef UEFI_BUILD - MasterTableOffset = (UINT16 *)(*(UINT16 *)(pDeviceData->pBIOS_Image+OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER) + pDeviceData->pBIOS_Image); - MasterTableOffset = (UINT16 *)((ULONG)((ATOM_ROM_HEADER *)MasterTableOffset)->usMasterCommandTableOffset + pDeviceData->pBIOS_Image ); + MasterTableOffset = (UINT16 *)(UINT16LE_TO_CPU(*(UINT16 *)(pDeviceData->pBIOS_Image+OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER)) + pDeviceData->pBIOS_Image); + MasterTableOffset = (UINT16 *)((ULONG)UINT16LE_TO_CPU(((ATOM_ROM_HEADER *)MasterTableOffset)->usMasterCommandTableOffset) + pDeviceData->pBIOS_Image ); MasterTableOffset =(UINT16 *) &(((ATOM_MASTER_COMMAND_TABLE *)MasterTableOffset)->ListOfCommandTables); #else MasterTableOffset = (UINT16 *)(&(GetCommandMasterTable( )->ListOfCommandTables)); @@ -97,8 +94,8 @@ UINT16* GetDataMasterTablePointer(DEVICE_DATA STACK_BASED* pDeviceData) UINT16 *MasterTableOffset; #ifndef UEFI_BUILD - MasterTableOffset = (UINT16 *)(*(UINT16 *)(pDeviceData->pBIOS_Image+OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER) + pDeviceData->pBIOS_Image); - MasterTableOffset = (UINT16 *)((ULONG)((ATOM_ROM_HEADER *)MasterTableOffset)->usMasterDataTableOffset + pDeviceData->pBIOS_Image ); + MasterTableOffset = (UINT16 *)(UINT16LE_TO_CPU(*(UINT16 *)(pDeviceData->pBIOS_Image+OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER)) + pDeviceData->pBIOS_Image); + MasterTableOffset = (UINT16 *)((ULONG)(UINT16LE_TO_CPU(((ATOM_ROM_HEADER *)MasterTableOffset)->usMasterDataTableOffset)) + pDeviceData->pBIOS_Image ); MasterTableOffset =(UINT16 *) &(((ATOM_MASTER_DATA_TABLE *)MasterTableOffset)->ListOfDataTables); #else MasterTableOffset = (UINT16 *)(&(GetDataMasterTable( )->ListOfDataTables)); @@ -129,11 +126,29 @@ UINT8 GetTrueIndexInMasterTable(PARSER_TEMP_DATA STACK_BASED * pParserTempData, } } +ATOM_TABLE_ATTRIBUTE GetCommandTableAttribute(UINT8 *pTableHeader) +{ + ATOM_TABLE_ATTRIBUTE_ACCESS lTableAccess; + + /* It's unclear whether this union trick breaks C aliasing rules, + * however, it's explicitely permitted by gcc, and we have other + * case where the code relies on a union being accessed by either + * of the "ways" and stay consistent so if a compiler breaks this + * assumption, it will probably need us to compile without strict + * aliasing enforcement + */ + lTableAccess.sbfAccess = ((ATOM_COMMON_ROM_COMMAND_TABLE_HEADER *)pTableHeader)->TableAttribute; + lTableAccess.susAccess = UINT16LE_TO_CPU(lTableAccess.susAccess); + + return lTableAccess.sbfAccess; +} + CD_STATUS ParseTable(DEVICE_DATA STACK_BASED* pDeviceData, UINT8 IndexInMasterTable) { PARSER_TEMP_DATA ParserTempData; WORKING_TABLE_DATA STACK_BASED* prevWorkingTableData; + memset(&ParserTempData, 0, sizeof(PARSER_TEMP_DATA)); ParserTempData.pDeviceData=(DEVICE_DATA*)pDeviceData; #ifndef DISABLE_EASF if (pDeviceData->format == TABLE_FORMAT_EASF) @@ -143,7 +158,7 @@ CD_STATUS ParseTable(DEVICE_DATA STACK_BASED* pDeviceData, UINT8 IndexInMasterTa #endif { ParserTempData.pCmd=(GENERIC_ATTRIBUTE_COMMAND*)GetDataMasterTablePointer(pDeviceData); - ParserTempData.IndirectIOTablePointer=(UINT8*)((ULONG)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[INDIRECT_IO_TABLE]) + pDeviceData->pBIOS_Image); + ParserTempData.IndirectIOTablePointer=(UINT8*)((ULONG)(UINT16LE_TO_CPU(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[INDIRECT_IO_TABLE])) + pDeviceData->pBIOS_Image); ParserTempData.IndirectIOTablePointer+=sizeof(ATOM_COMMON_TABLE_HEADER); } @@ -160,65 +175,66 @@ CD_STATUS ParseTable(DEVICE_DATA STACK_BASED* pDeviceData, UINT8 IndexInMasterTa ParserTempData.Status=CD_CALL_TABLE; do{ - + if (ParserTempData.Status==CD_CALL_TABLE) - { + { IndexInMasterTable=ParserTempData.CommandSpecific.IndexInMasterTable; if(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]!=0) // if the offset is not ZERO - { + { + ATOM_TABLE_ATTRIBUTE lTableAttr; + lTableAttr = GetCommandTableAttribute(UINT16LE_TO_CPU(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable])+pDeviceData->pBIOS_Image); #ifndef UEFI_BUILD ParserTempData.pWorkingTableData =(WORKING_TABLE_DATA STACK_BASED*) AllocateWorkSpace(pDeviceData, - ((ATOM_COMMON_ROM_COMMAND_TABLE_HEADER*)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]+pDeviceData->pBIOS_Image))->TableAttribute.WS_SizeInBytes+sizeof(WORKING_TABLE_DATA)); + lTableAttr.WS_SizeInBytes+sizeof(WORKING_TABLE_DATA)); #else - ParserTempData.pWorkingTableData =(WORKING_TABLE_DATA STACK_BASED*) AllocateWorkSpace(pDeviceData, - ((ATOM_COMMON_ROM_COMMAND_TABLE_HEADER*)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]))->TableAttribute.WS_SizeInBytes+sizeof(WORKING_TABLE_DATA)); + ParserTempData.pWorkingTableData =(WORKING_TABLE_DATA STACK_BASED*) AllocateWorkSpace(pDeviceData, + lTableAttr.WS_SizeInBytes+sizeof(WORKING_TABLE_DATA)); #endif - if (ParserTempData.pWorkingTableData!=NULL) - { - ParserTempData.pWorkingTableData->pWorkSpace=(WORKSPACE_POINTER STACK_BASED*)((UINT8*)ParserTempData.pWorkingTableData+sizeof(WORKING_TABLE_DATA)); + if (ParserTempData.pWorkingTableData!=NULL) + { + ParserTempData.pWorkingTableData->pWorkSpace=(WORKSPACE_POINTER STACK_BASED*)((UINT8*)ParserTempData.pWorkingTableData+sizeof(WORKING_TABLE_DATA)); #ifndef UEFI_BUILD - ParserTempData.pWorkingTableData->pTableHead = (UINT8 *)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]+pDeviceData->pBIOS_Image); + ParserTempData.pWorkingTableData->pTableHead = (UINT8 *)(UINT16LE_TO_CPU(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable])+pDeviceData->pBIOS_Image); #else - ParserTempData.pWorkingTableData->pTableHead = (UINT8 *)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]); + ParserTempData.pWorkingTableData->pTableHead = (UINT8 *)(UINT16LE_TO_CPU(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable])); #endif - ParserTempData.pWorkingTableData->IP=((UINT8*)ParserTempData.pWorkingTableData->pTableHead)+sizeof(ATOM_COMMON_ROM_COMMAND_TABLE_HEADER); - ParserTempData.pWorkingTableData->prevWorkingTableData=prevWorkingTableData; - prevWorkingTableData=ParserTempData.pWorkingTableData; - ParserTempData.Status = CD_SUCCESS; - } else ParserTempData.Status = CD_UNEXPECTED_BEHAVIOR; - } else ParserTempData.Status = CD_EXEC_TABLE_NOT_FOUND; + ParserTempData.pWorkingTableData->IP=((UINT8*)ParserTempData.pWorkingTableData->pTableHead)+sizeof(ATOM_COMMON_ROM_COMMAND_TABLE_HEADER); + ParserTempData.pWorkingTableData->prevWorkingTableData=prevWorkingTableData; + prevWorkingTableData=ParserTempData.pWorkingTableData; + ParserTempData.Status = CD_SUCCESS; + } else ParserTempData.Status = CD_UNEXPECTED_BEHAVIOR; + } else ParserTempData.Status = CD_EXEC_TABLE_NOT_FOUND; } if (!CD_ERROR(ParserTempData.Status)) { - ParserTempData.Status = CD_SUCCESS; + ParserTempData.Status = CD_SUCCESS; while (!CD_ERROR_OR_COMPLETED(ParserTempData.Status)) - { - + { if (IS_COMMAND_VALID(((COMMAND_HEADER*)ParserTempData.pWorkingTableData->IP)->Opcode)) - { + { ParserTempData.pCmd = (GENERIC_ATTRIBUTE_COMMAND*)ParserTempData.pWorkingTableData->IP; - + if (IS_END_OF_TABLE(((COMMAND_HEADER*)ParserTempData.pWorkingTableData->IP)->Opcode)) { ParserTempData.Status=CD_COMPLETED; - prevWorkingTableData=ParserTempData.pWorkingTableData->prevWorkingTableData; - + prevWorkingTableData=ParserTempData.pWorkingTableData->prevWorkingTableData; + FreeWorkSpace(pDeviceData, ParserTempData.pWorkingTableData); - ParserTempData.pWorkingTableData=prevWorkingTableData; - if (prevWorkingTableData!=NULL) - { - ParserTempData.pDeviceData->pParameterSpace-= - (((ATOM_COMMON_ROM_COMMAND_TABLE_HEADER*)ParserTempData.pWorkingTableData-> - pTableHead)->TableAttribute.PS_SizeInBytes>>2); - } - // if there is a parent table where to return, then restore PS_pointer to the original state + ParserTempData.pWorkingTableData=prevWorkingTableData; + if (prevWorkingTableData!=NULL) + { + ATOM_TABLE_ATTRIBUTE lTableAttr; + lTableAttr = GetCommandTableAttribute(ParserTempData.pWorkingTableData->pTableHead); + ParserTempData.pDeviceData->pParameterSpace-=(lTableAttr.PS_SizeInBytes>>2); + } + // if there is a parent table where to return, then restore PS_pointer to the original state } else { - IndexInMasterTable=ProcessCommandProperties((PARSER_TEMP_DATA STACK_BASED *)&ParserTempData); + IndexInMasterTable=ProcessCommandProperties((PARSER_TEMP_DATA STACK_BASED *)&ParserTempData); (*CallTable[IndexInMasterTable].function)((PARSER_TEMP_DATA STACK_BASED *)&ParserTempData); #if (PARSER_TYPE!=DRIVER_TYPE_PARSER) - BIOS_STACK_MODIFIER(); + BIOS_STACK_MODIFIER(); #endif } } @@ -227,13 +243,13 @@ CD_STATUS ParseTable(DEVICE_DATA STACK_BASED* pDeviceData, UINT8 IndexInMasterTa ParserTempData.Status=CD_INVALID_OPCODE; break; } - + } // while } // if else break; } while (prevWorkingTableData!=NULL); - if (ParserTempData.Status == CD_COMPLETED) return CD_SUCCESS; + if (ParserTempData.Status == CD_COMPLETED) return CD_SUCCESS; return ParserTempData.Status; } else return CD_SUCCESS; } diff --git a/src/AtomBios/hwserv_drv.c b/src/AtomBios/hwserv_drv.c index a5f5a5b8..9f2b6b92 100644 --- a/src/AtomBios/hwserv_drv.c +++ b/src/AtomBios/hwserv_drv.c @@ -34,8 +34,14 @@ Revision History: NEG:27.09.2002 Initiated. --*/ -#include "CD_binding.h" -#include "CD_hw_services.h" +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <X11/Xos.h> +#include "xorg-server.h" + +#include "Decoder.h" //trace settings #if DEBUG_OUTPUT_DEVICE & 1 @@ -249,12 +255,12 @@ VOID WriteReg32(PARSER_TEMP_DATA STACK_BASED * pWorkingTableData) VOID ReadIndReg32 (PARSER_TEMP_DATA STACK_BASED * pWorkingTableData) { - pWorkingTableData->IndirectData = CailReadATIRegister(pWorkingTableData->pDeviceData->CAIL,*(UINT16*)(pWorkingTableData->IndirectIOTablePointer+1)); + pWorkingTableData->IndirectData = CailReadATIRegister(pWorkingTableData->pDeviceData->CAIL,UINT16LE_TO_CPU(*(UINT16*)(pWorkingTableData->IndirectIOTablePointer+1))); } VOID WriteIndReg32(PARSER_TEMP_DATA STACK_BASED * pWorkingTableData) { - CailWriteATIRegister(pWorkingTableData->pDeviceData->CAIL,*(UINT16*)(pWorkingTableData->IndirectIOTablePointer+1),pWorkingTableData->IndirectData ); + CailWriteATIRegister(pWorkingTableData->pDeviceData->CAIL,UINT16LE_TO_CPU(*(UINT16*)(pWorkingTableData->IndirectIOTablePointer+1)),pWorkingTableData->IndirectData); } #endif diff --git a/src/AtomBios/includes/CD_Common_Types.h b/src/AtomBios/includes/CD_Common_Types.h index c60b652c..071b8fd4 100644 --- a/src/AtomBios/includes/CD_Common_Types.h +++ b/src/AtomBios/includes/CD_Common_Types.h @@ -155,6 +155,18 @@ typedef unsigned long ULONG_PTR; #ifndef FGL_LINUX #pragma warning ( default : 4142 ) #endif + +#ifndef ATOM_BIG_ENDIAN +#ifdef X_BYTE_ORDER +#if X_BYTE_ORDER == X_BIG_ENDIAN +#define ATOM_BIG_ENDIAN 1 +#endif +#endif +#endif +#ifndef ATOM_BIG_ENDIAN +#define ATOM_BIG_ENDIAN 0 +#endif + #endif // _COMMON_TYPES_H_ // EOF diff --git a/src/AtomBios/includes/CD_Definitions.h b/src/AtomBios/includes/CD_Definitions.h index 98fd4954..c00e93e8 100644 --- a/src/AtomBios/includes/CD_Definitions.h +++ b/src/AtomBios/includes/CD_Definitions.h @@ -39,11 +39,12 @@ NEG:27.08.2002 Initiated. #ifndef _CD_DEFINITIONS_H #define _CD_DEFINITIONS_H_ #ifdef DRIVER_PARSER -VOID *AllocateMemory(VOID *, UINT16); +VOID *AllocateMemory(DEVICE_DATA *, UINT16); VOID ReleaseMemory(DEVICE_DATA * , WORKING_TABLE_DATA* ); #endif CD_STATUS ParseTable(DEVICE_DATA* pDeviceData, UINT8 IndexInMasterTable); //CD_STATUS CD_MainLoop(PARSER_TEMP_DATA_POINTER pParserTempData); CD_STATUS Main_Loop(DEVICE_DATA* pDeviceData,UINT16 *MasterTableOffset,UINT8 IndexInMasterTable); UINT16* GetCommandMasterTablePointer(DEVICE_DATA* pDeviceData); +ATOM_TABLE_ATTRIBUTE GetCommandTableAttribute(UINT8 *pTableHeader); #endif //CD_DEFINITIONS diff --git a/src/AtomBios/includes/CD_Structs.h b/src/AtomBios/includes/CD_Structs.h index c43f81db..01fb80ec 100644 --- a/src/AtomBios/includes/CD_Structs.h +++ b/src/AtomBios/includes/CD_Structs.h @@ -35,10 +35,18 @@ Revision History: NEG:26.08.2002 Initiated. --*/ -#include "CD_binding.h" #ifndef _CD_STRUCTS_H_ #define _CD_STRUCTS_H_ +#include "CD_binding.h" + +/* Endaianness should be specified before inclusion, + * default to little endian + */ +#ifndef ATOM_BIG_ENDIAN +#error Endian not specified +#endif + #ifdef UEFI_BUILD typedef UINT16** PTABLE_UNIT_TYPE; typedef UINTN TABLE_UNIT_TYPE; @@ -304,9 +312,15 @@ typedef union _PARAMETER_ACCESS { }PARAMETER_ACCESS; typedef struct _COMMAND_ATTRIBUTE { +#if ATOM_BIG_ENDIAN + UINT8 DestinationAlignment:2; + UINT8 SourceAlignment:3; + UINT8 Source:3; +#else UINT8 Source:3; UINT8 SourceAlignment:3; UINT8 DestinationAlignment:2; +#endif }COMMAND_ATTRIBUTE; typedef struct _SOURCE_DESTINATION_ALIGNMENT{ @@ -363,11 +377,19 @@ typedef union _COMMAND_SPECIFIC_UNION{ typedef struct _CD_GENERIC_BYTE{ +#if ATOM_BIG_ENDIAN + UINT16 PS_SizeInDwordsUsedByCallingTable:5; + UINT16 CurrentPort:2; + UINT16 CommandAccessType:3; + UINT16 CurrentParameterSize:3; + UINT16 CommandType:3; +#else UINT16 CommandType:3; UINT16 CurrentParameterSize:3; UINT16 CommandAccessType:3; UINT16 CurrentPort:2; UINT16 PS_SizeInDwordsUsedByCallingTable:5; +#endif }CD_GENERIC_BYTE; typedef UINT8 COMMAND_TYPE_OPCODE_ONLY; diff --git a/src/AtomBios/includes/Decoder.h b/src/AtomBios/includes/Decoder.h index 24c25fc2..1e143f02 100644 --- a/src/AtomBios/includes/Decoder.h +++ b/src/AtomBios/includes/Decoder.h @@ -47,12 +47,32 @@ NEG:27.08.2002 Initiated. #define PARSER_VERSION_MAJOR 0x00000000 #define PARSER_VERSION_MINOR 0x0000000E #define PARSER_VERSION (PARSER_VERSION_MAJOR | PARSER_VERSION_MINOR) -#include "CD_binding.h" + #include "CD_Common_Types.h" + +#include "atombios.h" + +/* these depends on some struct defined in atombios.h */ +#include "CD_binding.h" #include "CD_hw_services.h" #include "CD_Structs.h" -#include "CD_Definitions.h" #include "CD_Opcodes.h" +#include "CD_Definitions.h" + +#if ATOM_BIG_ENDIAN +extern UINT16 ATOM_BSWAP16(UINT16 x); +extern UINT32 ATOM_BSWAP32(UINT32 x); + +#define CPU_TO_UINT16LE(x) ATOM_BSWAP16(x) +#define CPU_TO_UINT32LE(x) ATOM_BSWAP32(x) +#define UINT16LE_TO_CPU(x) ATOM_BSWAP16(x) +#define UINT32LE_TO_CPU(x) ATOM_BSWAP32(x) +#else +#define CPU_TO_UINT16LE(x) (x) +#define CPU_TO_UINT32LE(x) (x) +#define UINT16LE_TO_CPU(x) (x) +#define UINT32LE_TO_CPU(x) (x) +#endif #define SOURCE_ONLY_CMD_TYPE 0//0xFE #define SOURCE_DESTINATION_CMD_TYPE 1//0xFD diff --git a/src/AtomBios/includes/atombios.h b/src/AtomBios/includes/atombios.h index 17483a60..2e7dc6c2 100644 --- a/src/AtomBios/includes/atombios.h +++ b/src/AtomBios/includes/atombios.h @@ -34,6 +34,12 @@ #define ATOM_HEADER_VERSION (ATOM_VERSION_MAJOR | ATOM_VERSION_MINOR) +/* Endianness should be specified before inclusion, + * default to little endian + */ +#ifndef ATOM_BIG_ENDIAN +#error Endian not specified +#endif #ifdef _H2INC #ifndef ULONG @@ -304,7 +310,7 @@ typedef struct _ATOM_MASTER_COMMAND_TABLE typedef struct _ATOM_TABLE_ATTRIBUTE { -#if X_BYTE_ORDER == X_BIG_ENDIAN +#if ATOM_BIG_ENDIAN USHORT UpdatedByUtility:1; //[15]=Table updated by utility flag USHORT PS_SizeInBytes:7; //[14:8]=Size of parameter space in Bytes (multiple of a dword), USHORT WS_SizeInBytes:8; //[7:0]=Size of workspace in Bytes (in multiple of a dword), @@ -315,6 +321,12 @@ typedef struct _ATOM_TABLE_ATTRIBUTE #endif }ATOM_TABLE_ATTRIBUTE; +typedef union _ATOM_TABLE_ATTRIBUTE_ACCESS +{ + ATOM_TABLE_ATTRIBUTE sbfAccess; + USHORT susAccess; +}ATOM_TABLE_ATTRIBUTE_ACCESS; + // Common header for all command tables. //Every table pointed by _ATOM_MASTER_COMMAND_TABLE has this common header. //And the pointer actually points to this header. @@ -1258,7 +1270,7 @@ typedef struct _ATOM_MULTIMEDIA_CONFIG_INFO //Please don't add or expand this bitfield structure below, this one will retire soon.! typedef struct _ATOM_FIRMWARE_CAPABILITY { -#if X_BYTE_ORDER == X_BIG_ENDIAN +#if ATOM_BIG_ENDIAN USHORT Reserved:3; USHORT HyperMemory_Size:4; USHORT HyperMemory_Support:1; @@ -1767,7 +1779,7 @@ for Griffin or Greyhound. SBIOS needs to convert to actual time by: typedef struct _ATOM_I2C_ID_CONFIG { -#if X_BYTE_ORDER == X_BIG_ENDIAN +#if ATOM_BIG_ENDIAN UCHAR bfHW_Capable:1; UCHAR bfHW_EngineID:3; UCHAR bfI2C_LineMux:4; @@ -1820,7 +1832,7 @@ typedef struct _ATOM_GPIO_I2C_INFO //Please don't add or expand this bitfield structure below, this one will retire soon.! typedef struct _ATOM_MODE_MISC_INFO { -#if X_BYTE_ORDER == X_BIG_ENDIAN +#if ATOM_BIG_ENDIAN USHORT Reserved:6; USHORT RGB888:1; USHORT DoubleClock:1; @@ -3426,7 +3438,7 @@ typedef struct _ATOM_MEMORY_VENDOR_BLOCK{ typedef struct _ATOM_MEMORY_SETTING_ID_CONFIG{ -#if X_BYTE_ORDER == X_BIG_ENDIAN +#if ATOM_BIG_ENDIAN ULONG ucMemBlkId:8; ULONG ulMemClockRange:24; #else @@ -4072,7 +4084,7 @@ typedef struct _COMPASSIONATE_DATA typedef struct _ATOM_CONNECTOR_INFO { -#if X_BYTE_ORDER == X_BIG_ENDIAN +#if ATOM_BIG_ENDIAN UCHAR bfConnectorType:4; UCHAR bfAssociatedDAC:4; #else |