home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 January / pcwk_01_1999.iso / Tajnepp / MCLK093 / PCI.H < prev    next >
C/C++ Source or Header  |  1997-04-02  |  3KB  |  127 lines

  1. // pci.h
  2. //    Header file for definitions of class pci_vga and pci_bios
  3.  
  4. #ifndef __pci_h
  5.     #define __pci_h
  6. #define CONFIG_ADDRESS    0x0CF8
  7. #define CONFIG_DATA        0x0CFC
  8. #define PCI_INT        0x1A
  9. #define TRUE            1
  10. #define FALSE            0
  11.  
  12.  
  13. typedef unsigned long ulong;
  14. typedef unsigned char uchar;
  15. typedef unsigned short uint;
  16.  
  17.  
  18. // "dword" is a special class which facilitates the manipulation of
  19. // a 32-bit register.  The class offers access to a single 32-bit value
  20. // via 8-bit access, 16-bit access, or 32-bit access
  21. //
  22. // Class supports copy constructor, opreator "=" assignment to types
  23. // of ULONG or DWORD
  24. #ifndef __dword_struct
  25.     #define __dword_struct
  26. union dword
  27. {
  28. public:
  29.     ulong dw;
  30.     struct    {
  31.           uint w0;
  32.           uint w1;
  33.      } w;
  34.  
  35.      struct    {
  36.          uchar b0;
  37.           uchar b1;
  38.           uchar b2;
  39.           uchar b3;
  40.      } b;
  41.  
  42.      // Constructors
  43.      dword( void )
  44.             {    dw = 0;    };
  45.     dword( ulong init_value )
  46.          {    dw = init_value;    };
  47.      dword( long init_value )
  48.          {    dw = (ulong)init_value;    };
  49.      dword( dword &init_dword )
  50.          {    dw = init_dword.dw;    };
  51.  
  52.      dword&
  53.     operator =( ulong value )
  54.     {
  55.         dw = value;
  56.         return *this;
  57.     };
  58. };
  59. #endif
  60.  
  61. // PCI BIOS characteristics returned by BIOS call 0x1A, check_installation
  62. struct bios_info_type
  63. {
  64.     uchar major_version;
  65.      uchar minor_version;
  66.      uchar last_bus;
  67.      uchar hardware_characteristics;
  68. };
  69.  
  70.  
  71. struct pci_device_handle_type
  72. {
  73.     uint device;    // Device_ID (16-bit)
  74.      uint vendor;    // Vendor_ID (16-bit)
  75.      uint index;    // Index (0-n)
  76.  
  77.      uchar bus;        // Bus# of PCI-device
  78.  
  79.      union {
  80.          uchar byte;
  81.           struct {
  82.                unsigned char func:3;
  83.             unsigned char dev:5;
  84.           } x;
  85.      }    f;
  86.     //    f.byte represents func/device byte
  87.     //    where bits 7-3=device, 2-0=function
  88.      //    f.x.func represents function (3-bit value)
  89.      //    f.x.dev represents device (5-bit value)
  90. };
  91.  
  92.  
  93. class pci_bios_type
  94. {
  95. protected:
  96.     uchar installed;    // Indicates whether PCI_BIOS is installed
  97.     bios_info_type *bios_info;
  98.          // BIOS information, as returned by PCI BIOS call 0xB101
  99.  
  100. public:
  101.     bios_info_type * installation_check( void );
  102.          // Returns pointer to bios_info if PCI_BIOS detected
  103.           // NULL otherwise
  104.  
  105.      uchar find_device( pci_device_handle_type *pci_device );
  106.          // Attempts to locate device specified in *pci_device
  107.           // Returns TRUE if successful, FALSE otherwise
  108.  
  109.      uchar read_cbyte( const pci_device_handle_type pci_device,
  110.         const uint index, uchar *value );
  111.          // Returns BIOS code
  112.           // If successful, read_cbyte() places read-config-byte into *value
  113.  
  114.      uchar write_cbyte( const pci_device_handle_type pci_device,
  115.         const uint index, const uchar value );
  116.          // Returns BIOS code
  117.  
  118.      pci_bios_type();
  119.          // Constructor initially calls BIOS for presence of PCI,
  120.           // sets "installed" to TRUE or FALSE accordingly.  And loads
  121.           // bios_info with pci_information returned by the BIOS call
  122.  
  123.      ~pci_bios_type();    // Destructor
  124.  
  125. };
  126.  
  127. #endif