⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amcclib.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
📖 第 1 页 / 共 4 页
字号:
*/


static void pciConfigFindIncrement( UINT8 *bus, UINT8 *device, UINT8 *function )
{

        ++(*function);

        if( *function >= 8 )
        {
                *function = 0;
                ++(*device);
        }

        if( *device >= 32 )
        {
                *device = 0;
                ++(*bus);
        }

}


int pciConfigFindfirst( UINT16 vendorid, UINT16 deviceid, UINT8 *bus, UINT8 *device, UINT8 *function )
{

        UINT32 candidate;
        UINT32 signature = ((UINT32)deviceid << 16) + (vendorid);
        UINT8 multifunction;

        *bus = 0;
        *device = 0;

        while( *bus < MAX_BUS_COUNT && *device < MAX_DEVICE_COUNT && *function < MAX_DEVICE_FUNCTIONS )
        {

                pciConfigRead32( *bus, *device, 0x00, &candidate);
                pciConfigRead8( *bus, *device, 0x0E, &multifunction);

                multifunction = multifunction & 0x80;
                if( candidate == signature && (function == 0 || multifunction) )
                {
                        return TRUE;
                }
                else if( candidate == 0xFFFFFFFFlu )
                {
                        *function = MAX_DEVICE_FUNCTIONS;
                }
                else if( !multifunction )
                {
                        *function = MAX_DEVICE_FUNCTIONS;
                }

                pciConfigFindIncrement( bus, device, function );

        }

        return FALSE;

}


int pciConfigFindnext( UINT16 vendorid, UINT16 deviceid, UINT8 *bus, UINT8 *device, UINT8 *function )
{

        UINT32 candidate;
        UINT32 signature = ((UINT32)deviceid << 16) + (vendorid);
        UINT8 multifunction;

        pciConfigFindIncrement( bus, device, function );

        while( *bus < MAX_BUS_COUNT && *device < MAX_DEVICE_COUNT && *function < MAX_DEVICE_FUNCTIONS )
        {

                pciConfigRead32( *bus, *device, 0x00, &candidate );
                pciConfigRead8( *bus, *device,  0x0E, &multifunction);
                multifunction = multifunction & 0x80;

                if( candidate == signature && (function == 0 || multifunction) )
                {
                        return TRUE;
                }
                else if( candidate == 0xFFFFFFFFlu )
                {
                        *function = MAX_DEVICE_FUNCTIONS;
                }
                else if( !multifunction )
                {
                        *function = MAX_DEVICE_FUNCTIONS;
                }

                pciConfigFindIncrement( bus, device, function );

        }

        return FALSE;

}



/* SDISP_PAGE - display page using display structure - outputs to buffer */
void sdisp_page(struct PAGE_STRUCT page[], unsigned char *buf, int len, char *obuf)
{
int i=0;
unsigned char *data;

  while ((page[i].desc[0] != '\0') && (i < len)) {
    data = buf + page[i].byte;
    sprintf(obuf,"%20s  [%s]:\t",page[i].desc,page[i].tag);
    obuf += strlen(obuf);
    switch (page[i].type_ent) {      /* switch on type, hex etc */
      case T_HEX:
        switch (page[i].type_byte) {    /* switch on size */
          case T_BYTE:
            sprintf(obuf,"%2.2X",*((unsigned char *)data));
            break;
          case T_WORD:
            sprintf(obuf,"%4.4X",*((unsigned int *)data));
            break;
          case T_DWORD:
            sprintf(obuf,"%8.8lX",*((unsigned long *)data));
            break;
          case T_24:
            sprintf(obuf,"%6.6lX",(unsigned long)(*((unsigned int *)data)+*((unsigned char *)data+2)));
            break;
        }
        break;
      case T_DECIMAL:
        switch (page[i].type_byte) {
          case T_BYTE:
            sprintf(obuf,"%d",*((unsigned char *)data));
            break;
          case T_WORD:
            sprintf(obuf,"%d",*((unsigned int *)data));
            break;
          case T_DWORD:
            sprintf(obuf,"%ld",*((unsigned long *)data));
            break;
        }
        break;
    }
    obuf += strlen(obuf);
    i++;
    sprintf(obuf,"\n");
    obuf++;
  }
}


/****************************************************************************/
/*  DUMP                                                         */
/*                                                                          */
/* Purpose: dump memory - byte format                                       */
/*                                                                          */
/* Inputs: address, length                                                  */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/* Max size is 64k, since we use ints for offsets.                          */
/* Declare i and j as UINT32 and use the HUGH model if need > 64k.           */
/****************************************************************************/
void dump( void *addr, UINT32 len )
{

    int i,j;
    UINT8 *ptr = (UINT8 *)addr;


            for( i = 0; i < len; i += 16)
            {
                printf( "%04x: ", i );
                for( j = 0; j < 16; j++ )
                    if( i + j < len )
                        printf( "%02x ", *(UINT8 *)((UINT32)ptr + i + j) );
                    else
                        printf( "   " );
                printf( " " );
                for( j = 0; (j < 16) && (i + j < len); j++ )
                    if( isprint(ptr[ i + j ]) )
                        printf( "%c", ptr[ i + j ] );
                    else
                        printf( "." );
                printf( "\n" );
            }


}

/* SDUMP - dump to a char buffer */
void sdump( void *addr, UINT32 len , char *obuf)
/* Max size is 64k, since we use ints for offsets.                 */
/* Declare i and j as UINT32 and use the HUGH model if need > 64k. */
{

    int i,j;
    UINT8 *ptr = (UINT8 *)addr;


            for( i = 0; i < len; i += 16)
            {
                sprintf(obuf, "%04x: ", i );
                 obuf += strlen(obuf);
                 for( j = 0; j < 16; j++ ) {
                    if( i + j < len )
                        sprintf(obuf,  "%02x ", *(UINT8 *)(ptr + i + j) );
                    else
                        sprintf(obuf,  "   " );
                    obuf += strlen(obuf);
                }
                sprintf(obuf,  " " );
                obuf++;
                for( j = 0; (j < 16) && (i + j < len); j++ ) {
                    if( isprint(ptr[ i + j ]) )
                        sprintf(obuf,  "%c", ptr[ i + j ] );
                    else
                        sprintf(obuf,  "." );
                    obuf += strlen(obuf);
                }
                sprintf(obuf,  "\n" );
                obuf++;
            }


}


/****************************************************************************/
/*  DUMPW                                                         */
/*                                                                          */
/* Purpose: dump memory - word format                                       */
/*                                                                          */
/* Inputs: address, length                                                  */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/* Max size is 64k, since we use ints for offsets.                          */
/* Declare i and j as UINT32 and use the HUGH model if need > 64k.          */
/****************************************************************************/

void dumpw( void *addr, UINT32 len )
{

    int i,j;
    UINT8 *ptr = (UINT8 *)addr;


            for( i = 0; i < len; i += 16)
            {
                printf( "%04x: ", i );
                for( j = 0; j < 16; j += 2 )
                    if( i + j < len )
                        printf( "%04x ", *(UINT16 *)(ptr + i + j) );
                    else
                        printf( "     " );
                printf( " " );
                for( j = 0; (j < 16) && (i + j < len); j++ )
                    if( isprint(ptr[ i + j ]) )
                        printf( "%c", ptr[ i + j ] );
                    else
                        printf( "." );
                printf( "\n" );
            }


}


/****************************************************************************/
/*  DUMPL                                                        */
/*                                                                          */
/* Purpose: dump memory - long format                                       */
/*                                                                          */
/* Inputs: address, length                                                  */
/*                                                                          */
/* Outputs:                                                                 */
/*                                                                          */
/* Max size is 64k, since we use ints for offsets.                          */
/* Declare i and j as UINT32 and use the HUGH model if need > 64k.          */
/****************************************************************************/

void dumpl( void *addr, UINT32 len )
{

    int i,j;
    UINT8 *ptr = (UINT8 *)addr;


            for( i = 0; i < len; i += 16)
            {
                printf( "%04x: ", i );
                for( j = 0; j < 16; j += 4 )
                    if( i + j < len )
                        printf( "%08lx ", *(UINT32 *)(ptr + i + j) );
                    else
                        printf( "         " );
                printf( " " );
                for( j = 0; (j < 16) && (i + j < len); j++ )
                    if( isprint(ptr[ i + j ]) )
                        printf( "%c", ptr[ i + j ] );
                    else
                        printf( "." );
                printf( "\n" );
            }


}




/*
** compare 2 strings for equality up to the length of s1 with a req'd minimum
**
*/

int strmcmp ( char *s1, char *s2, int len, int min )
{

    return( (strncmp(s1,s2,len) == 0) && (len >= min) );

}




/***/


/* REG_WRITE8 - write byte to register (memory or I/O) from region base 

	Entry:	base - base register as read from PCI (includes memory/IO bit)
			offset - offset from base to register
			amt - data to write
	Return:	N/A
*/
void reg_write8(UINT32 base, UINT32 offset, UINT8 amt)
{

	check_base(base);
    if (base & 1)  /* I/O location */
      outp((UINT16)offset + (UINT16)(base & 0xFFFFFFFCL),amt);
    else
      xpoke8((base & 0xFFFFFFF0L) + offset,amt);
}

/* REG_WRITE16 - write word to register (memory or I/O) from region base 

	Entry:	base - base register as read from PCI (includes memory/IO bit)
			offset - offset from base to register
			amt - data to write
	Return:	N/A
*/
void reg_write16(UINT32 base, UINT32 offset, UINT16 amt)
{
	check_base(base);
    if (base & 1)  /* I/O location */
      outpw((UINT16)offset + (UINT16)(base & 0xFFFFFFFCL),amt);
    else
      xpoke16((base & 0xFFFFFFF0L) + offset,amt);
}


void reg_write32(UINT32 base, UINT32 offset, UINT32 amt)
{
	check_base(base);
    if (base & 1)  /* I/O location */
      outpl((UINT16)offset + (UINT16)(base & 0xFFFFFFFCL),amt);
    else
      xpoke32((base & 0xFFFFFFF0L) + offset,amt);
}

/* REG_READ8 - Read byte from register (memory or I/O) from region base 

	Entry:	base - base register as read from PCI (includes memory/IO bit)
			offset - offset from base to register
	Return:	data read

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -