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

📄 amcclib.c

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

int read_config_area( UINT8 function, UINT8 bus_number, UINT8 device_and_function, \
	UINT8 register_number, UINT32*data32 )
{
	int ret_status;
	UINT16 ax, flags;
	UINT32 ecx;

	_BH = bus_number;
	_BL = device_and_function;
	_DI = register_number;
	_AH = PCI_FUNCTION_ID;
	_AL = function;


	ecx = _ECX;
	return ret_status;	
}
*/


/****************************************************************************/
/*  pciConfiwriteX                                                          */
/*                                                                          */
/* Purpose: write config space                                              */
/*                                                                          */
/****************************************************************************/
UINT8 pciConfigWrite8 ( UINT8 bus, UINT8 device, UINT8 offset, UINT8 byte )
{
	int ret_status;
	UINT16 ax, flags;

	// must do AX last because compiler uses it for other stuff
    _BX = (bus << 8) | (device);
    _CL = byte;
    _DI = (UINT16)offset;
    _AH = PCI_FUNCTION_ID;
    _AL = WRITE_CONFIG_BYTE;
    geninterrupt( 0x1A );

	// save regs before compiler overwrites...
	ax = _AX;
	flags = _FLAGS;

	if( (flags & CARRY_FLAG) == 0 )
		ret_status = HIGH_BYTE(ax);
	else ret_status = PCI_NOT_SUCCESSFUL;

	return( ret_status );
}

UINT8 pciConfigWrite16 ( UINT8 bus, UINT8 device, UINT8 offset, UINT16 word )
{
	int ret_status;
	UINT16 ax, flags;

	// must do AX last because compiler uses it for other stuff
    _BX = (bus << 8) | (device);
    _CX = word;
    _DI = (UINT16)offset;
    _AH = PCI_FUNCTION_ID;
    _AL = WRITE_CONFIG_WORD;
    geninterrupt( 0x1A );

	// save regs before compiler overwrites...
	ax = _AX;
	flags = _FLAGS;

	if( (flags & CARRY_FLAG) == 0 )
		ret_status = HIGH_BYTE(ax);
	else ret_status = PCI_NOT_SUCCESSFUL;

	return( ret_status );
}


UINT8 pciConfigWrite32 ( UINT8 bus, UINT8 device, UINT8 offset, UINT32 ulong )
{
	int ret_status;
	UINT16 ax, flags;

	// must do AX last because compiler uses it for other stuff
    _BX = (bus << 8) | (device);
    _ECX = ulong;
    _DI = (UINT16)offset;
    _AH = PCI_FUNCTION_ID;
    _AL = WRITE_CONFIG_DWORD;
    geninterrupt( 0x1A );

	// save regs before compiler overwrites...
	ax = _AX;
	flags = _FLAGS;

	if( (flags & CARRY_FLAG) == 0 )
		ret_status = HIGH_BYTE(ax);
	else ret_status = PCI_NOT_SUCCESSFUL;

	return( ret_status );
}



/****************************************************************************/
/*  pciConfigReadX                                                          */
/*                                                                          */
/* Purpose: read config space                                               */
/*                                                                          */
/****************************************************************************/
UINT8 pciConfigRead8 ( UINT8 bus, UINT8 device, UINT8 offset, UINT8 *byte )
{
	int ret_status;
	UINT16 ax, flags;

	// must do AX last because compiler uses it for other stuff
    _BX = (bus << 8) | (device);
    _DI = (UINT16)offset;
    _AH = PCI_FUNCTION_ID;
    _AL = READ_CONFIG_BYTE;
    geninterrupt( 0x1A );

	// save regs before compiler overwrites...
	ax = _AX;
	flags = _FLAGS;
	*byte = _CL;

	if( (flags & CARRY_FLAG) == 0 )
		ret_status = HIGH_BYTE(ax);
	else ret_status = PCI_NOT_SUCCESSFUL;

	return( ret_status );
}


UINT8 pciConfigRead16 ( UINT8 bus, UINT8 device, UINT8 offset, UINT16 *word )
{
	int ret_status;
	UINT16 ax, flags;

	// must do AX last because compiler uses it for other stuff
    _BX = (bus << 8) | (device);
    _DI = (UINT16)offset;
    _AH = PCI_FUNCTION_ID;
    _AL = READ_CONFIG_WORD;
    geninterrupt( 0x1A );

	// save regs before compiler overwrites...
	ax = _AX;
	flags = _FLAGS;
	*word = _CX;

	if( (flags & CARRY_FLAG) == 0 )
		ret_status = HIGH_BYTE(ax);
	else ret_status = PCI_NOT_SUCCESSFUL;

	return( ret_status );
}

UINT8 pciConfigRead32 ( UINT8 bus, UINT8 device, UINT8 offset, UINT32 *ulong )
{
	int ret_status;
	UINT16 ax, flags;

	// must do AX last because compiler uses it for other stuff
    _BX = (bus << 8) | (device);
    _DI = (UINT16)offset;
    _AH = PCI_FUNCTION_ID;
    _AL = READ_CONFIG_DWORD;
    geninterrupt( 0x1A );

	// save regs before compiler overwrites...
	ax = _AX;
	flags = _FLAGS;
	*ulong = _ECX;

	if( (flags & CARRY_FLAG) == 0 )
		ret_status = HIGH_BYTE(ax);
	else ret_status = PCI_NOT_SUCCESSFUL;

	return( ret_status );
}


/****************************************************************************/
/*  pciConfiwrite8                                                          */
/*                                                                          */
/* Purpose: write config space                                              */
/*                                                                          */
/* Inputs: bus num, function, offset, byte                                  */
/*                                                                          */
/* Outputs: read data,  BIOS return PCI_xxx (see lib.h)                     */
/*                                                                          */
/****************************************************************************/
/*
UINT8 pciConfigWrite8 ( UINT8 bus, UINT8 device, UINT8 offset, UINT8 byte )
{

    union REGS regs;

    regs.h.ah = PCI_FUNCTION_ID;
    regs.h.al = WRITE_CONFIG_BYTE;
    regs.x.bx = (bus << 8) | (device);
    regs.h.cl = byte;
    regs.x.di = (UINT16)offset;
    int86( 0x1A, &regs, &regs );

    enable();
    return regs.h.ah;
}
*/

/****************************************************************************/
/*  pciConfigwrite16                                                          */
/*                                                                          */
/* Purpose: write config space                                              */
/*                                                                          */
/* Inputs: bus num, function, offset, byte                                  */
/*                                                                          */
/* Outputs: read data,  BIOS return PCI_xxx (see lib.h)                     */
/*                                                                          */
/****************************************************************************/
/*
UINT8 pciConfigWrite16 ( UINT8 bus, UINT8 device, UINT8 offset, UINT16 word )
{

    union REGS regs;

    regs.h.ah = PCI_FUNCTION_ID;
    regs.h.al = WRITE_CONFIG_WORD;
    regs.x.bx = (bus << 8) | (device);
    regs.x.cx = word;
    regs.x.di = (UINT16)offset;
    int86( 0x1A, &regs, &regs );

    enable();
    return regs.h.ah;
}
*/

/****************************************************************************/
/*  pciConfigwrite32                                                        */
/*                                                                          */
/* Purpose: write config space                                              */
/*                                                                          */
/* Inputs: bus num, function, offset, byte                                  */
/*                                                                          */
/* Outputs: read data,  BIOS return PCI_xxx (see lib.h)                     */
/*                                                                          */
/****************************************************************************/
/*
UINT8 pciConfigWrite32 ( UINT8 bus, UINT8 device, UINT8 offset, UINT32 ulong )
{

    union REGS regs;

    regs.h.ah = PCI_FUNCTION_ID;
    regs.h.al = WRITE_CONFIG_WORD;
    regs.x.bx = (bus << 8) | (device);
    regs.x.cx = (UINT16)(ulong & 0xFFFFL);
    regs.x.di = (UINT16)offset;
    int86( 0x1A, &regs, &regs );

    regs.h.ah = PCI_FUNCTION_ID;
    regs.h.al = WRITE_CONFIG_WORD;
    regs.x.bx = (bus << 8) | (device);
    regs.x.cx = (UINT16)(ulong >> 16);
    regs.x.di = (UINT16)(offset + 2);
    int86( 0x1A, &regs, &regs );

    enable();
    return regs.h.ah;
}
*/

/****************************************************************************/
/*  pciConfigRead8                                                          */
/*                                                                          */
/* Purpose: write read config space                                         */
/*                                                                          */
/* Inputs: bus num, function, offset                                        */
/*                                                                          */
/* Outputs: read data,  BIOS return PCI_xxx (see lib.h)                     */
/*                                                                          */
/****************************************************************************/
/*
UINT8 pciConfigRead8 ( UINT8 bus, UINT8 device, UINT8 offset, UINT8 *data)
{

    union REGS regs;

    regs.h.ah = PCI_FUNCTION_ID;
    regs.h.al = READ_CONFIG_BYTE;
    regs.x.bx = (bus << 8) | (device);
    regs.x.di = (UINT16)offset;
    int86( 0x1A, &regs, &regs );

    enable();

    *data = regs.h.cl;

    return regs.h.ah;

}
*/

/****************************************************************************/
/*  pciConfigRead16                                                         */
/*                                                                          */
/* Purpose: read config space                                               */
/*                                                                          */
/* Inputs: bus num, function, offset                                        */
/*                                                                          */
/* Outputs: read data,  BIOS return PCI_xxx (see lib.h)                     */
/*                                                                          */
/****************************************************************************/
/*
UINT8 pciConfigRead16 ( UINT8 bus, UINT8 device, UINT8 offset, UINT16 *data )
{

    union REGS regs;

    regs.h.ah = PCI_FUNCTION_ID;
    regs.h.al = READ_CONFIG_WORD;
    regs.x.bx = (bus << 8) | (device);
    regs.x.di = (UINT16)offset;
    int86( 0x1A, &regs, &regs );

    enable();

    *data = regs.x.cx;
    return regs.h.ah;

}
*/

/****************************************************************************/
/*  pciConfigRead32                                                         */
/*                                                                          */
/* Purpose: read config space                                               */
/*                                                                          */
/* Inputs: bus num, function, offset                                        */
/*                                                                          */
/* Outputs: read data,  BIOS return PCI_xxx (see lib.h)                     */
/*                                                                          */
/****************************************************************************/
/*
UINT8 pciConfigRead32 ( UINT8 bus, UINT8 device, UINT8 offset, UINT32 *data )
{

    union REGS regs;
    UINT32 lower;
    UINT32 upper;

    regs.h.ah = PCI_FUNCTION_ID;
    regs.h.al = READ_CONFIG_WORD;
    regs.x.bx = (bus << 8) | (device);
    regs.x.di = (UINT16)offset;
    int86( 0x1A, &regs, &regs );
    lower = (UINT32)regs.x.cx;

    regs.h.ah = PCI_FUNCTION_ID;
    regs.h.al = READ_CONFIG_WORD;
    regs.x.bx = (bus << 8) | (device);
    regs.x.di = (UINT16)offset + 2;
    int86( 0x1A, &regs, &regs );
    upper = (UINT32)regs.x.cx;

    enable();
    *data = (upper * 0x10000lu) + lower;

    return regs.h.ah;

}
*/

⌨️ 快捷键说明

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