📄 pci.c
字号:
/* */
/* unsigned char device_and_function */
/* Device Number in upper 5 bits, Function Number in lower 3 bits */
/* */
/* unsigned char register_number */
/* Register Number of configuration space to read */
/* */
/* Outputs: */
/* */
/* unsigned int *word_read */
/* Word read from Configuration Space */
/* */
/* Return Value - Indicates presence of device */
/* TRUE - Device found */
/* FALSE - Invalid Register Number or BIOS error */
/* */
/****************************************************************************/
int ReadConfigurationWord( unsigned char bus_number,
unsigned char device_and_function,
unsigned char register_number,
unsigned int *word_read)
{
int ret_status; /* Function Return Status */
unsigned long data;
/* Call read_configuration_area function with word data */
ret_status = ReadConfigurationArea( READ_CONFIG_WORD,
bus_number,
device_and_function,
register_number,
&data);
if (ret_status) {
/* Extract word */
*word_read = (unsigned int)(data & 0x0000ffffL);
}
return ret_status;
}
/****************************************************************************/
/* */
/* READ_CONFIGURATION_DWORD */
/* */
/* Purpose: Reads a dword from the configuration space of a specific device */
/* */
/* Inputs: */
/* */
/* unsigned char bus_number */
/* PCI bus to read configuration data from */
/* */
/* unsigned char device_and_function */
/* Device Number in upper 5 bits, Function Number in lower 3 bits */
/* */
/* unsigned char register_number */
/* Register Number of configuration space to read */
/* */
/* Outputs: */
/* */
/* unsigned long *dword_read */
/* Dword read from Configuration Space */
/* */
/* Return Value - Indicates presence of device */
/* TRUE - Device found */
/* FALSE - Invalid Register Number or BIOS error */
/* */
/****************************************************************************/
int ReadConfigurationDword( unsigned char bus_number,
unsigned char device_and_function,
unsigned char register_number,
unsigned long *dword_read)
{
int ret_status; /* Function Return Status */
unsigned long data;
/* Call read_configuration_area function with dword data */
ret_status = ReadConfigurationArea( READ_CONFIG_DWORD,
bus_number,
device_and_function,
register_number,
&data);
if (ret_status) {
/* Extract dword */
*dword_read = data;
}
return ret_status;
}
/****************************************************************************/
/* */
/* WRITE_CONFIGURATION_AREA */
/* */
/* Purpose: Writes a unsigned char/word/dword to the configuration space of */
/* a specific device */
/* */
/* Inputs: */
/* */
/* unsigned char bus_number */
/* PCI bus to read configuration data from */
/* */
/* unsigned char device_and_function */
/* Device Number in upper 5 bits, Function Number in lower 3 bits */
/* */
/* unsigned char register_number */
/* Register Number of configuration space to read */
/* */
/* unsigned long value */
/* Value to write to Configuration Space */
/* */
/* Outputs: */
/* */
/* Return Value - Indicates presence of device */
/* TRUE - Device found */
/* FALSE - Invalid Register Number or BIOS error */
/* */
/****************************************************************************/
int WriteConfigurationArea( unsigned char function,
unsigned char bus_number,
unsigned char device_and_function,
unsigned char register_number,
unsigned long value)
{
int ret_status; /* Function Return Status */
DRegs inregs, outregs;
/* Load entry registers for PCI BIOS */
inregs.h.bh = bus_number;
inregs.h.bl = device_and_function;
inregs.e.ecx = value;
inregs.x.di = register_number;
inregs.h.ah = PCI_FUNCTION_ID;
inregs.h.al = function;
/* Call PCI BIOS Int 1Ah interface */
Bios32(&inregs, &outregs);
/* First check if CARRY FLAG Set, if so, error has occurred */
if (outregs.x.cflag == 0)
{
/* Get Return code from BIOS */
if (outregs.h.ah == 0)
ret_status = TRUE;
else
ret_status = FALSE;
} else
ret_status = FALSE;
return ret_status;
}
/****************************************************************************/
/* */
/* WRITE_CONFIGURATION_BYTE */
/* */
/* Purpose: Writes a unsigned char to the configuration space of a specific */
/* device */
/* Inputs: */
/* */
/* unsigned char bus_number */
/* PCI bus to write configuration data to */
/* */
/* unsigned char device_and_function */
/* Device Number in upper 5 bits, Function Number in lower 3 bits */
/* */
/* unsigned char register_number */
/* Register Number of configuration space to write */
/* */
/* unsigned char unsigned char_to_write */
/* Byte to write to Configuration Space */
/* */
/* Outputs: */
/* */
/* Return Value - Indicates presence of device */
/* TRUE - Device found */
/* FALSE - Invalid Register Number or BIOS error */
/* */
/****************************************************************************/
int WriteConfigurationByte( unsigned char bus_number,
unsigned char device_and_function,
unsigned char register_number,
unsigned char byte_to_write)
{
int ret_status; /* Function Return Status */
/* Call write_configuration_area function with unsigned char data */
ret_status = WriteConfigurationArea( WRITE_CONFIG_BYTE,
bus_number,
device_and_function,
register_number,
byte_to_write);
return ret_status;
}
/****************************************************************************/
/* */
/* WRITE_CONFIGURATION_WORD */
/* */
/* Purpose: Writes a word to the configuration space of a specific device */
/* */
/* Inputs: */
/* */
/* unsigned char bus_number */
/* PCI bus to read configuration data from */
/* */
/* unsigned char device_and_function */
/* Device Number in upper 5 bits, Function Number in lower 3 bits */
/* */
/* unsigned char register_number */
/* Register Number of configuration space to read */
/* */
/* unsigned int word_to_write */
/* Word to write to Configuration Space */
/* */
/* Outputs: */
/* */
/* Return Value - Indicates presence of device */
/* TRUE - Device found */
/* FALSE - Invalid Register Number or BIOS error */
/* */
/****************************************************************************/
int WriteConfigurationWord( unsigned char bus_number,
unsigned char device_and_function,
unsigned char register_number,
unsigned int word_to_write)
{
int ret_status; /* Function Return Status */
/* Call read_configuration_area function with word data */
ret_status = WriteConfigurationArea( WRITE_CONFIG_WORD,
bus_number,
device_and_function,
register_number,
word_to_write);
return ret_status;
}
/****************************************************************************/
/* */
/* WRITE_CONFIGURATION_DWORD */
/* */
/* Purpose: Reads a dword from the configuration space of a specific device */
/* */
/* Inputs: */
/* */
/* unsigned char bus_number */
/* PCI bus to read configuration data from */
/* */
/* unsigned char device_and_function */
/* Device Number in upper 5 bits, Function Number in lower 3 bits */
/* */
/* unsigned char register_number */
/* Register Number of configuration space to read */
/* */
/* unsigned long dword_to_write */
/* Dword to write to Configuration Space */
/* */
/* Outputs: */
/* */
/* Return Value - Indicates presence of device */
/* TRUE - Device found */
/* FALSE - Invalid Register Number or BIOS error */
/* */
/****************************************************************************/
int WriteConfigurationDword( unsigned char bus_number,
unsigned char device_and_function,
unsigned char register_number,
unsigned long dword_to_write)
{
int ret_status; /* Function Return Status */
/* Call write_configuration_area function with dword data */
ret_status = WriteConfigurationArea( WRITE_CONFIG_DWORD,
bus_number,
device_and_function,
register_number,
dword_to_write);
return ret_status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -