www.pudn.com > ScriptsSample.zip > SPCI.H


/*--------------------------------------------------*/ 
/*                                                  */ 
/* Module SPCI.H                                    */ 
/*                                                  */ 
/* Declarations for PCI constants and structures.   */ 
/* PCI function declarations.                       */ 
/*                                                  */ 
/* Adapted from Symbios Logic                       */ 
/*    Software Development Kit                      */ 
/*                                                  */ 
/* Project: A Programmer's Guide to SCSI            */ 
/* Copyright (C) 1997, Brian Sawert.                */ 
/* All rights reserved.                             */ 
/*                                                  */ 
/*--------------------------------------------------*/ 
 
 
#ifndef _SPCI_H 
#define _SPCI_H 
 
 
/*---------- constant definitions ----------*/ 
 
// PCI BIOS interrupt 
#define PCI_BIOS_INT             0x1a 
 
// PCI BIOS function call ID 
#define PCI_FUNCTION_ID          0xb1 
 
// PCI BIOS present subfunction 
#define PCI_BIOS_PRESENT         0x01 
 
// PCI find device subfunction 
#define PCI_FIND_DEVICE          0x02 
 
// PCI read configuration subfunction 
#define PCI_READ_CONFIG_DWORD    0x0a 
 
// PCI write configuration subfunction 
#define PCI_WRITE_CONFIG_DWORD   0x0d 
 
 
// PCI version numbers 
#define PCI_BIOS_REV_1X          0x10 
#define PCI_BIOS_REV_2X          0x20 
#define PCI_UNKNOWN_BIOS         0xFF 
#define PCI_NO_BIOS              0x00 
 
// PCI configuration registers 
 
// vendor ID register 
#define PCI_CONFIG_REG_VENID     0x00 
 
// device ID register 
#define PCI_CONFIG_REG_DEVID     0x00 
 
// command register 
#define PCI_CONFIG_REG_CMD       0x04 
 
// status register 
#define PCI_CONFIG_REG_STAT      0x04 
 
// revision ID register 
#define PCI_CONFIG_REG_REVID     0x08 
 
// subsystem vendor ID register 
#define PCI_CONFIG_REG_SUBV      0x2C 
 
// subsystem ID register 
#define PCI_CONFIG_REG_SUBID     0x2C 
 
// ROM base address register 
#define PCI_CONFIG_REG_ROM       0x30 
 
// interrupt line register 
#define PCI_CONFIG_REG_INTL      0x3C 
 
 
/*---------- type definitions ----------*/ 
 
typedef unsigned char   BYTE; 
typedef unsigned int    WORD; 
typedef unsigned long   DWORD; 
 
 
// PCI BIOS information 
 
typedef struct { 
   BYTE access;            // access mechanism 
   WORD version;           // major/minor version 
   BYTE lastbus;           // last PCI bus number 
} pci_bios; 
 
 
// PCI device information 
 
typedef struct { 
   WORD bus_num;           // PCI bus number 
   WORD dev_num;           // device number 
   WORD function;          // function number 
   WORD vend_id;           // vendor ID 
   WORD dev_id;            // device ID 
   WORD dev_index;         // device index 
   BYTE rev_id;            // revision ID 
   WORD  command;          // command register 
   DWORD mem_base;         // register memory base 
   DWORD io_base;          // register I/O base 
   DWORD ram_base;         // SCRIPTS RAM base 
   WORD  sub_id;           // subsystem ID 
   WORD  sub_vend_id;      // subsystem vendor ID 
   DWORD rom_base;         // ROM base address 
   BYTE intl;              // interrupt number 
} pci_device; 
 
 
/*---------- macro definitions ----------*/ 
 
#define LOBYTE(w) ((BYTE)(w)) 
#define HIBYTE(w) ((BYTE)((WORD)(w) >> 8)) 
 
#define LOWORD(l) ((WORD)(l)) 
#define HIWORD(l) ((WORD)((DWORD)(l) >> 16)) 
 
 
/*---------- PCI function declarations ----------*/ 
 
// read PCI BIOS version information 
extern WORD PCI_GetPCIBIOSVersion(pci_bios *ppcibios); 
 
// find a specific PCI device 
extern int PCI_FindDevice(pci_device *ppcidevice); 
 
// read a PCI configuration register 
extern DWORD PCI_GetConfigRegister(pci_device *ppcidevice, 
   WORD offset); 
 
// write to a PCI configuration register 
extern WORD PCI_SetConfigRegister(pci_device *ppcidevice, 
   WORD offset, DWORD value); 
 
 
#endif