📄 rinit.c
字号:
printf("\nCannot find table pointer because parent table doesn't exist!");
return NULL;
}
/*Same for Memory Reset Table. It's located after Memory config table*/
unsigned char* look_for_mem_res_table(unsigned char** parent_table)
{
unsigned char* table = *parent_table;
if (table != NULL)
{
while (*table++);
return(table + 2);
// 2 bytes are given for table revision and high byte mask after memory config table space
}
printf("\nCannot find table pointer because parent table doesn't exist!");
return NULL;
}
/*And Short Memory reset table is located at address stored in (Memory config table - 3bytes) */
unsigned char* look_for_short_mem_res_table(unsigned char** parent_table)
{
unsigned char* table = *parent_table;
if ((table != NULL) && (*(table-2) <= 64)) //*(table-2) is fixed memory configuration parameter
{
return(table+*(table-3));
}
printf("\nCannot find table pointer because parent table doesn't exist!");
return NULL;
}
//*********************************************************************************
//Function gets parameters from a given ASIC Init table and does the following operations
//depends on parameter's flag :
//programming registers, masking registers, delaying, waiting for some registers status
//or if command INFO is set it's printing on a screen what it's currently doing
//*********************************************************************************
int LoadInitBlock(unsigned char *init_block, unsigned short control, const char* comment)
{
unsigned int i;
unsigned long ormask, andmask;
unsigned short flag,index,command;
if (init_block == NULL)
{
printf("\nLoadInitBlock : table does not exist!!!");
return (FALSE);
}
if (control & cmdINFO) printf("\n\n*************** %s ******************** ",comment);
if (control & cmdINFO) printf("\nTable revision : 0x%02x\n",*(init_block-1));
while(*(unsigned short*)init_block)
{
//parsing a service word:
flag=*(unsigned short*) init_block & 0xe000; //taking highest 3 bits
index=*(unsigned short*) init_block & 0x1fff; //the rest of the word can be index
command=*(unsigned short*) init_block & 0xff; //scpecial command takes 1 byte
init_block+=INIT_TABLE_COMMAND_SIZE; // moves 2 bytes forward
switch (flag)
{
case 0x0000: // writing data to Index (Memory) Register; 4 bytes
if (control & cmdINFO) printf("\nIndex register 0x%04x <- 0x%08lx",index, *(unsigned long*) init_block);
if (control & cmdINIT) OutIndexRegs(index,*(unsigned long*) init_block);
init_block+=INIT_TABLE_DATA_SIZE;
break;
case 0x2000: // writing data to IO Register; 4 bytes
if (control & cmdINFO) printf("\nIO register 0x%02x <- 0x%08lx",index, *(unsigned long*) init_block);
if (control & cmdINIT) OutIORegs(index,*(unsigned long*) init_block);
init_block+=INIT_TABLE_DATA_SIZE;
break;
case 0x4000: // masking Index (Memory) Register; both "and" and "or" masks are 4 bytes long
andmask=*(unsigned long*) init_block;
init_block+=INIT_TABLE_DATA_SIZE;
ormask=*(unsigned long*) init_block;
init_block+=INIT_TABLE_DATA_SIZE;
if (control & cmdINFO) printf("\nIndex register 0x%04x AND 0x%08lx OR 0x%08lx",index, andmask, ormask);
if (control & cmdINIT) MaskIndexRegs(index,andmask,ormask);
break;
case 0x6000: // masking IO registers; 8 bytes
andmask=*(unsigned long*) init_block;
init_block+=INIT_TABLE_DATA_SIZE;
ormask=*(unsigned long*) init_block;
init_block+=INIT_TABLE_DATA_SIZE;
if (control & cmdINFO) printf("\nIO register 0x%04x AND 0x%08lx OR 0x%08lx",index, andmask, ormask);
if (control & cmdINIT) MaskIORegs(index,andmask,ormask);
break;
case 0x8000: // Delay mks; 2 bytes
if (control & cmdINFO) printf("\nDelay %d mks",*(unsigned short*) init_block);
if (control & cmdINIT) delay_ns(*(unsigned short*) init_block);
init_block+=INIT_TABLE_DELAY_SIZE;
break;
case 0xa000: // Special command; 2 bytes
if (control & cmdINFO) printf("\nSpecial command [0x%02x] - ",command);
switch (command)
{
case 0x0003:
if (control & cmdINFO) printf("wait CLK_PWRMGT_CNTL for WAIT_MC_BUSY_MASK bit set to 0");
if (control & cmdINIT)
{
for (i=0;i<*(unsigned short*) init_block;i++)
if ((pll_read(pllCLK_PWRMGT_CNTL) & pllWAIT_MC_BUSY_MASK) == 0) break;
}
break;
case 0x0008:
if (control & cmdINFO) printf("check MC_STATUS for MEM_PWRUP_COMPLETE");
if (control & cmdINIT)
{
for (i=0;i<*(unsigned short*) init_block;i++)
if (((unsigned char)InpIndexRegs(MC_STATUS) & 3) == MEM_PWRUP_COMPLETE_A+MEM_PWRUP_COMPLETE_B) break;
}
break;
}
init_block+=INIT_TABLE_SCOMMAND_SIZE;
break;
}
}
return (TRUE);
}
//*********************************************************************************
//Function gets parameters from a given PLL Init table and does the following operations
//depends on parameter's flag :
//wait (150mks,5ms or till some bit is set), programming registers, masking registers
//or if command INFO is set it's printing on a screen what it's currently doing
//*********************************************************************************
int LoadPLLBlock(unsigned char *init_block, unsigned short control, const char* comment)
{
unsigned long pwmgmtcntl;
unsigned char offset;
unsigned char andmask;
unsigned char ormask;
unsigned char index;
int i;
if (init_block == NULL)
{
printf("\nLoadPLLBlock : table does not exist!!!");
return (FALSE);
}
if (control & cmdINFO) printf("\n\n*************** %s ******************** ",comment);
if (control & cmdINFO) printf("\nTable revision : 0x%02x\n",*(init_block-1));
while(*init_block)
{
index = *init_block++;
switch (index & PLL_FLAG_BITS)
{
case PLL_WAIT: //This operation takes 1 byte from a table
switch (index & PLL_INDEX_BITS)
{
case PLL_DELAY_150MKS:
if (control & cmdINFO) printf("\nDelay 150 mks");
if (control & cmdINIT) delay_ns(150);
break;
case PLL_DELAY_5MS:
if (control & cmdINFO) printf("\nDelay 5 ms");
if (control & cmdINIT) delay_ns(5000);
break;
case WAIT_MC_BUSY_MASK:
if (control & cmdINFO) printf("\nwait CLK_PWRMGT_CNTL for WAIT_MC_BUSY_MASK bit set to 0");
if (control & cmdINIT)
{
for (i=0;i<10000;i++)
if ((pll_read(pllCLK_PWRMGT_CNTL) & pllWAIT_MC_BUSY_MASK) == 0) break;
}
break;
case WAIT_DLL_READY_MASK:
if (control & cmdINFO) printf("\nwait CLK_PWRMGT_CNTL for WAIT_DLL_READY_MASK bit set to 1");
if (control & cmdINIT)
{
for (i=0;i<10000;i++)
if ((pll_read(pllCLK_PWRMGT_CNTL) & pllWAIT_DLL_READY_MASK) != 0) break;
}
break;
case CHECK_SET_CLK_PWRMGT_CNTL24:
if (control & cmdINFO) printf("\ncheck PWRMGT_CNTL for bit 24 and clear it");
if (control & cmdINIT)
{
if (((pwmgmtcntl=pll_read(pllCLK_PWRMGT_CNTL)) & CLK_PWRMGT_CNTL24) != 0)
{
ProgPLLDword(pllMCLK_CNTL, (pll_read(pllMCLK_CNTL) & 0xFFFF0000) | SET_ALL_SOURCES_TO_PCI);
delay_ns(10000);
ProgPLLDword(pllCLK_PWRMGT_CNTL,pwmgmtcntl & ~CLK_PWRMGT_CNTL24);
delay_ns(10000);
}
}
break;
}
break;
case PLL_MASK_BYTE: // This operation takes 3 bytes from a table
offset=*init_block++; // offset of byte inside a dword
andmask=*init_block++; // and mask
ormask=*init_block++; // or mask
if (control & cmdINFO) printf("\nPLL byte 0x%04x, bits %d-%d AND 0x%02x OR 0x%02x",index,offset*8,offset*8+8,andmask,ormask);
if (control & cmdINIT) MaskPLLByte(index,offset,andmask,ormask);
break;
case PLL_PROGRAM_DWORD: // This operation takes 4 bytes from a table
if (control & cmdINFO) printf("\nPLL DWORD 0x%04x <- 0x%08lx",index, *(unsigned long*)init_block );
if (control & cmdINIT) ProgPLLDword(index,*(unsigned long*)init_block);
init_block+=4;
break;
}
}
return (TRUE);
}
//*********************************************************************************
//Function gets parameters from a given Memory reset table, runs ASIC init tables 3 and 4
//and does the following operations depends on parameter's flag :
//wait for MEM_PWRUP_COMPLETE and masking registers
//or if command INFO is set it's printing on a screen what it's currently doing
//*********************************************************************************
int Reset_SDRAM(unsigned char *reset_block, unsigned short control, const char * comment)
{
int i;
unsigned char index;
if (reset_block == NULL)
{
printf("\nReset_SDRAM : table does not exist!!!");
return (FALSE);
}
if (control & cmdINFO) printf("\n\n*************** %s ******************** ",comment);
if (control & cmdINFO) printf("\nTable revision : 0x%02x\n",*(reset_block-1));
while(*reset_block != 0xff)
{
index=*reset_block++;
if (index == 0x0f)
{
if (control & cmdINFO) printf("\ncheck MC_STATUS for MEM_PWRUP_COMPLETE");
if (control & cmdINIT)
{
for (i=0;i<20000;i++)
if (((unsigned char)InpIndexRegs(MC_STATUS) & 3) == MEM_PWRUP_COMPLETE_A+MEM_PWRUP_COMPLETE_B) break;
}
}
else
{
if (control & cmdINFO) printf("\nIndex register 0x%04x AND 0x%08lx OR 0x%08x",MEM_SDRAM_MODE_REG, mask_SDRAM_MODE, *(unsigned short*)reset_block);
if (control & cmdINIT) MaskIndexRegs(MEM_SDRAM_MODE_REG, mask_SDRAM_MODE, *(unsigned short*)reset_block);
reset_block+=2;
if (control & cmdINFO) printf("\nIndex register 0x%04x AND 0x%08lx OR 0x%08lx",MEM_SDRAM_MODE_REG, mask_b3MEM_RESET, (unsigned long)index << 24);
if (control & cmdINIT) MaskIndexRegs(MEM_SDRAM_MODE_REG, mask_b3MEM_RESET, (unsigned long)index << 24);
}
}
return (TRUE);
}
//*********************************************************************************
//Programming palette registers
void Init_DAC(void) //for mode 1204 16bpp only
{
int i;
unsigned long pal=0;
io_outdword(defaultdev->io_base + PALETTE_INDEX,0);
for (i = 0; i < 0x100; i++)
{
io_outdword(defaultdev->io_base + PALETTE_DATA,pal);
pal+=0x010101;
}
}
//*********************************************************************************
//Command line commands, can be in both Lower case and Upper case mode
//*********************************************************************************
struct cmd_struc commands[CMD_NUMBER] = {
{cmdBIOS, "bios", "Gets tables from current BIOS"},
{cmdFILE, "file", "Gets tables from file [file=filename]"},
{cmdINIT, "init", "Initializes adapter, sets 640x480x16bpp mode, shows test pattern"},
{cmdINFO, "info", "Displays information from all init tables"}};
//Shows all the commands with descriptions in case if no commands are given in command line
void usage(void)
{
int i;
printf("\nInitialization tables test utility. ATI Technologies 2002. All rights reserved.");
printf("\nUSAGE:");
for (i=0; i < CMD_NUMBER; i++)
printf("\n %s\t%s",commands[i].cmd_str,commands[i].cmd_expl);
printf("\n");
}
//Function's called when program exits in normal or error condition
//It disables default PCI device (if not primary) and frees BIOS binary memory buffer
void postprocess(void)
{
if ((defaultdev->config & MEM_IO_ENABLE)==0)
pci_outword(defaultdev->busdevfnc, PCI_CONFIG, pci_inword(defaultdev->busdevfnc, PCI_CONFIG) & ~MEM_IO_ENABLE);
if (buffer != NULL) free(buffer);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -