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

📄 findchip.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
字号:
/*
	findchip.c


*/
#include <stdtypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* non-standard includes... */
#include <lib.h>
#include <amcclib.h>
#include <main.h>
#include <amcc5920.h>
#include <amcc5933.h>


#define CHECKPCI  	if ( status != PCI_SUCCESSFUL ) \
					return pci_bios_fail( status );

extern CHAR text[], infostring[];

int findchip( struct _chip *chip, CHAR *errstr )
/*
	Find chip based on VID, DID, SVID, and SID.

	Entry:	chip->device_id, chip->vendor_id, 
			chip->susbsy_vendor_id, chip->susbsy_id
			infostring is valid (null-teminated after stuff we don't want)

	Return:	TRUE if chip found, and chip->index updated
			FALSE and errstr updated			
*/
{
	UINT16 subsys_vendor=0, subsys_id=0;
	int found, index, status, strptr;

	strptr = strlen( infostring );
		// holds each device subsystem info
	found = FALSE;
	for ( index = 0; !found ; index++ )
	{
	    switch ( pci_init( chip, index, chip->device_id, chip->vendor_id ) )
	    {
			case 0:	
					status = pci_config_read16( chip, PCI_CS_SVID, &subsys_vendor );
					CHECKPCI
					status = pci_config_read16( chip, PCI_CS_SID, &subsys_id );
					CHECKPCI
					sprintf( text, "Index %d Subsystem Vendor/ID %4.4x/%4.4x.\n",
						index, subsys_vendor, subsys_id );
					strcat( infostring, text );
					break;		// chip found
			case 1:	strcat( errstr, "PCI BIOS not found.\n" );
					return FALSE;
			case 2:	if ( index == 0 )
					{
						sprintf( text, "No device matches Vendor ID/Device ID %4.4x/%4.4x.\n", chip->vendor_id, chip->device_id );
						strcat( errstr, text );
						return FALSE;
					}
					// index != 0...
					sprintf( text, "%d devices match Vendor/Device, but not Subsystem Vendor/ID %4.4x/%4.4x.\n", \
						index, chip->subsys_vendor_id, chip->subsys_id );
					strcat( errstr, text );
					strcat( errstr, infostring );	// add each subsystem stuff
					return FALSE;

			default: strcat( errstr, "Unknown case - programming error in \"findchip\".\n" );
					return FALSE;
		}

		// see if susbsystem ID matches...
		if ( chip->subsys_vendor_id != subsys_vendor ) continue;
		if ( chip->subsys_id == subsys_id ) break;	// found
	}

	infostring[strptr] = '\0';	// delete string stuff we added
	chip->index = index;
	return TRUE;
}

⌨️ 快捷键说明

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