Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2006-2007 Advanced Micro Devices, Inc.  
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice shall be included in
  12.  * all copies or substantial portions of the Software.
  13.  *
  14.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17.  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20.  * OTHER DEALINGS IN THE SOFTWARE.
  21.  */
  22.  
  23. /**
  24.  
  25. Module Name:
  26.  
  27.     Decoder.c
  28.    
  29. Abstract:
  30.  
  31.                 Commands Decoder
  32.  
  33. Revision History:
  34.  
  35.         NEG:24.09.2002  Initiated.
  36. --*/
  37. //#include "AtomBios.h"
  38. #include "Decoder.h"
  39. #include "atombios.h"
  40. #include "CD_binding.h"
  41. #include "CD_Common_Types.h"
  42.  
  43. #ifndef DISABLE_EASF
  44.         #include "easf.h"
  45. #endif
  46.  
  47.  
  48.  
  49. #define INDIRECT_IO_TABLE (((UINT16)&((ATOM_MASTER_LIST_OF_DATA_TABLES*)0)->IndirectIOAccess)/sizeof(TABLE_UNIT_TYPE) )
  50. extern COMMANDS_PROPERTIES CallTable[];
  51.  
  52.  
  53. UINT8 ProcessCommandProperties(PARSER_TEMP_DATA STACK_BASED *   pParserTempData)
  54. {
  55.   UINT8 opcode=((COMMAND_HEADER*)pParserTempData->pWorkingTableData->IP)->Opcode;
  56.   pParserTempData->pWorkingTableData->IP+=CallTable[opcode].headersize;
  57.   pParserTempData->ParametersType.Destination=CallTable[opcode].destination;
  58.   pParserTempData->ParametersType.Source = pParserTempData->pCmd->Header.Attribute.Source;
  59.   pParserTempData->CD_Mask.SrcAlignment=pParserTempData->pCmd->Header.Attribute.SourceAlignment;
  60.   pParserTempData->CD_Mask.DestAlignment=pParserTempData->pCmd->Header.Attribute.DestinationAlignment;
  61.   return opcode;
  62. }
  63.  
  64. UINT16* GetCommandMasterTablePointer(DEVICE_DATA STACK_BASED*  pDeviceData)
  65. {
  66.         UINT16          *MasterTableOffset;
  67. #ifndef DISABLE_EASF
  68.         if (pDeviceData->format == TABLE_FORMAT_EASF)
  69.         {
  70.     /*
  71.     make MasterTableOffset point to EASF_ASIC_SETUP_TABLE structure, including usSize.
  72.     */
  73.                 MasterTableOffset = (UINT16 *) (pDeviceData->pBIOS_Image+((EASF_ASIC_DESCRIPTOR*)pDeviceData->pBIOS_Image)->usAsicSetupTable_Offset);
  74.         } else
  75. #endif
  76.         {
  77. #ifndef         UEFI_BUILD
  78.                 MasterTableOffset = (UINT16 *)(*(UINT16 *)(pDeviceData->pBIOS_Image+OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER) + pDeviceData->pBIOS_Image);
  79.                 MasterTableOffset = (UINT16 *)((ULONG)((ATOM_ROM_HEADER *)MasterTableOffset)->usMasterCommandTableOffset + pDeviceData->pBIOS_Image );
  80.                 MasterTableOffset =(UINT16 *) &(((ATOM_MASTER_COMMAND_TABLE *)MasterTableOffset)->ListOfCommandTables);
  81. #else
  82.         MasterTableOffset = (UINT16 *)(&(GetCommandMasterTable( )->ListOfCommandTables));
  83. #endif
  84.         }
  85.         return MasterTableOffset;
  86. }
  87.  
  88. UINT16* GetDataMasterTablePointer(DEVICE_DATA STACK_BASED*  pDeviceData)
  89. {
  90.         UINT16          *MasterTableOffset;
  91.        
  92. #ifndef         UEFI_BUILD
  93.         MasterTableOffset = (UINT16 *)(*(UINT16 *)(pDeviceData->pBIOS_Image+OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER) + pDeviceData->pBIOS_Image);
  94.         MasterTableOffset = (UINT16 *)((ULONG)((ATOM_ROM_HEADER *)MasterTableOffset)->usMasterDataTableOffset + pDeviceData->pBIOS_Image );
  95.         MasterTableOffset =(UINT16 *) &(((ATOM_MASTER_DATA_TABLE *)MasterTableOffset)->ListOfDataTables);
  96. #else
  97.         MasterTableOffset = (UINT16 *)(&(GetDataMasterTable( )->ListOfDataTables));
  98. #endif
  99.         return MasterTableOffset;
  100. }
  101.  
  102.  
  103. UINT8 GetTrueIndexInMasterTable(PARSER_TEMP_DATA STACK_BASED * pParserTempData, UINT8 IndexInMasterTable)
  104. {
  105. #ifndef DISABLE_EASF
  106.         UINT16 i;
  107.         if ( pParserTempData->pDeviceData->format == TABLE_FORMAT_EASF)
  108.         {
  109. /*
  110.                 Consider EASF_ASIC_SETUP_TABLE structure pointed by pParserTempData->pCmd as UINT16[]
  111.                 ((UINT16*)pParserTempData->pCmd)[0] = EASF_ASIC_SETUP_TABLE.usSize;
  112.                 ((UINT16*)pParserTempData->pCmd)[1+n*4] = usFunctionID;
  113.                 usFunctionID has to be shifted left by 2 before compare it to the value provided by caller.
  114. */
  115.                 for (i=1; (i < ((UINT16*)pParserTempData->pCmd)[0] >> 1);i+=4)
  116.                         if ((UINT8)(((UINT16*)pParserTempData->pCmd)[i] << 2)==(IndexInMasterTable & EASF_TABLE_INDEX_MASK)) return (i+1+(IndexInMasterTable & EASF_TABLE_ATTR_MASK));
  117.                 return 1;
  118.         } else
  119. #endif
  120.         {
  121.                 return IndexInMasterTable;
  122.         }
  123. }
  124.  
  125. CD_STATUS ParseTable(DEVICE_DATA STACK_BASED* pDeviceData, UINT8 IndexInMasterTable)
  126. {
  127.         PARSER_TEMP_DATA        ParserTempData;
  128.   WORKING_TABLE_DATA STACK_BASED* prevWorkingTableData;
  129.  
  130.   ParserTempData.pDeviceData=(DEVICE_DATA*)pDeviceData;
  131. #ifndef DISABLE_EASF
  132.   if (pDeviceData->format == TABLE_FORMAT_EASF)
  133.   {
  134.       ParserTempData.IndirectIOTablePointer = 0;
  135.   } else
  136. #endif
  137.   {
  138.     ParserTempData.pCmd=(GENERIC_ATTRIBUTE_COMMAND*)GetDataMasterTablePointer(pDeviceData);
  139.     ParserTempData.IndirectIOTablePointer=(UINT8*)((ULONG)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[INDIRECT_IO_TABLE]) + pDeviceData->pBIOS_Image);
  140.     ParserTempData.IndirectIOTablePointer+=sizeof(ATOM_COMMON_TABLE_HEADER);
  141.   }
  142.  
  143.         ParserTempData.pCmd=(GENERIC_ATTRIBUTE_COMMAND*)GetCommandMasterTablePointer(pDeviceData);
  144.     IndexInMasterTable=GetTrueIndexInMasterTable((PARSER_TEMP_DATA STACK_BASED *)&ParserTempData,IndexInMasterTable);
  145.         if(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]!=0 )  // if the offset is not ZERO
  146.         {
  147.                 ParserTempData.CommandSpecific.IndexInMasterTable=IndexInMasterTable;
  148.                 ParserTempData.Multipurpose.CurrentPort=ATI_RegsPort;
  149.                 ParserTempData.CurrentPortID=INDIRECT_IO_MM;
  150.                 ParserTempData.CurrentRegBlock=0;
  151.                 ParserTempData.CurrentFB_Window=0;
  152.     prevWorkingTableData=NULL;
  153.                 ParserTempData.Status=CD_CALL_TABLE;
  154.  
  155.                 do{
  156.  
  157.                         if (ParserTempData.Status==CD_CALL_TABLE)
  158.       {
  159.                                 IndexInMasterTable=ParserTempData.CommandSpecific.IndexInMasterTable;
  160.                                 if(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]!=0)  // if the offset is not ZERO
  161.                                         {
  162. #ifndef         UEFI_BUILD
  163.                                         ParserTempData.pWorkingTableData =(WORKING_TABLE_DATA STACK_BASED*) AllocateWorkSpace(pDeviceData,
  164.                                                                 ((ATOM_COMMON_ROM_COMMAND_TABLE_HEADER*)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]+pDeviceData->pBIOS_Image))->TableAttribute.WS_SizeInBytes+sizeof(WORKING_TABLE_DATA));
  165. #else
  166.                                         ParserTempData.pWorkingTableData =(WORKING_TABLE_DATA STACK_BASED*) AllocateWorkSpace(pDeviceData,
  167.                                                                 ((ATOM_COMMON_ROM_COMMAND_TABLE_HEADER*)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]))->TableAttribute.WS_SizeInBytes+sizeof(WORKING_TABLE_DATA));
  168. #endif
  169.             if (ParserTempData.pWorkingTableData!=NULL)
  170.             {
  171.                                                   ParserTempData.pWorkingTableData->pWorkSpace=(WORKSPACE_POINTER STACK_BASED*)((UINT8*)ParserTempData.pWorkingTableData+sizeof(WORKING_TABLE_DATA));
  172. #ifndef         UEFI_BUILD
  173.                                                   ParserTempData.pWorkingTableData->pTableHead  = (UINT8 *)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]+pDeviceData->pBIOS_Image);
  174. #else
  175.                                                   ParserTempData.pWorkingTableData->pTableHead  = (UINT8 *)(((PTABLE_UNIT_TYPE)ParserTempData.pCmd)[IndexInMasterTable]);
  176. #endif
  177.                                                   ParserTempData.pWorkingTableData->IP=((UINT8*)ParserTempData.pWorkingTableData->pTableHead)+sizeof(ATOM_COMMON_ROM_COMMAND_TABLE_HEADER);
  178.               ParserTempData.pWorkingTableData->prevWorkingTableData=prevWorkingTableData;
  179.               prevWorkingTableData=ParserTempData.pWorkingTableData;
  180.               ParserTempData.Status = CD_SUCCESS;
  181.             } else ParserTempData.Status = CD_UNEXPECTED_BEHAVIOR;
  182.                                         } else ParserTempData.Status = CD_EXEC_TABLE_NOT_FOUND;
  183.                         }
  184.                         if (!CD_ERROR(ParserTempData.Status))
  185.                         {
  186.         ParserTempData.Status = CD_SUCCESS;
  187.                                 while (!CD_ERROR_OR_COMPLETED(ParserTempData.Status))  
  188.         {
  189.  
  190.                                         if (IS_COMMAND_VALID(((COMMAND_HEADER*)ParserTempData.pWorkingTableData->IP)->Opcode))
  191.           {
  192.                                                 ParserTempData.pCmd = (GENERIC_ATTRIBUTE_COMMAND*)ParserTempData.pWorkingTableData->IP;
  193.  
  194.                                                 if (IS_END_OF_TABLE(((COMMAND_HEADER*)ParserTempData.pWorkingTableData->IP)->Opcode))
  195.                                                 {
  196.                                                         ParserTempData.Status=CD_COMPLETED;
  197.               prevWorkingTableData=ParserTempData.pWorkingTableData->prevWorkingTableData;
  198.  
  199.                                                         FreeWorkSpace(pDeviceData, ParserTempData.pWorkingTableData);
  200.               ParserTempData.pWorkingTableData=prevWorkingTableData;
  201.               if (prevWorkingTableData!=NULL)
  202.               {
  203.                                                           ParserTempData.pDeviceData->pParameterSpace-=
  204.                                                                                 (((ATOM_COMMON_ROM_COMMAND_TABLE_HEADER*)ParserTempData.pWorkingTableData->
  205.                                                                                         pTableHead)->TableAttribute.PS_SizeInBytes>>2);
  206.               }
  207.                                                 // if there is a parent table where to return, then restore PS_pointer to the original state
  208.                                                 }
  209.                                                 else
  210.                                                 {
  211.               IndexInMasterTable=ProcessCommandProperties((PARSER_TEMP_DATA STACK_BASED *)&ParserTempData);
  212.                                                         (*CallTable[IndexInMasterTable].function)((PARSER_TEMP_DATA STACK_BASED *)&ParserTempData);
  213. #if (PARSER_TYPE!=DRIVER_TYPE_PARSER)
  214.               BIOS_STACK_MODIFIER();
  215. #endif
  216.                                                 }
  217.                                         }
  218.                                         else
  219.                                         {
  220.                                                 ParserTempData.Status=CD_INVALID_OPCODE;
  221.                                                 break;
  222.                                         }
  223.  
  224.                                 }       // while
  225.                         }       // if
  226.                         else
  227.                                 break;
  228.                 } while (prevWorkingTableData!=NULL);
  229.     if (ParserTempData.Status == CD_COMPLETED) return CD_SUCCESS;
  230.                 return ParserTempData.Status;
  231.         } else return CD_SUCCESS;
  232. }
  233.  
  234. // EOF
  235.  
  236.