📄 pci.h
字号:
//=====================================================================
//[HEADER] PCI
// PCIBios and PCIDevice class definitions
//+
//[AUTHOR]
// Bruno Rivara
//.
#ifndef ___PCI_H
#define ___PCI_H
#include <lvdef.h>
#ifndef _MSC_VER
#ifndef _Windows
#ifndef __UNIX__
#include <stdio.h>
typedef unsigned int BOOL;
typedef unsigned int WORD;
typedef unsigned long LONG;
typedef unsigned long DWORD;
#ifndef FAR
#define FAR _far
#endif
#else
#include <windows.h>
#endif
#define LOBYTE(w) ((U8BIT)(w))
#define HIBYTE(w) ((U8BIT)((U16BIT)(w) >> 8))
#define LOWORD(l) ((U16BIT)(l))
#define HIWORD(l) ((U16BIT)((DWORD)(l) >> 16))
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif // TRUE
#endif // _Windows
#endif // _MSC_VER
#include <pcicfg.h>
#define PCICMD_ENABLE_IO 0x01
#define PCICMD_DISABLE_IO 0x02
#define PCICMD_ENABLE_MEM 0x03
#define PCICMD_DISABLE_MEM 0x04
#define PCICMD_ENABLE_PAL 0x05
#define PCICMD_DISABLE_PAL 0x06
#define PCICMD_ENABLE_IOMEMPAL 0x10
#define PCICMD_DISABLE_IOMEMPAL 0x11
#define PCI_FUNCTION_ID 0xB1
#define PCI_BIOS_PRESENT 0x01
#define FIND_PCI_DEVICE 0x02
#define FIND_PCI_CLASS_CODE 0x03
#define READ_CONFIG_BYTE 0x08
#define READ_CONFIG_WORD 0x09
#define READ_CONFIG_DWORD 0x0A
#define WRITE_CONFIG_BYTE 0x0B
#define WRITE_CONFIG_WORD 0x0C
#define WRITE_CONFIG_DWORD 0x0D
#define GET_IRQ_ROUTING_OPTIONS 0x0E
#include <lvpackon.h>
class PCIBios;
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//[CLASS] PCIDevice
// Class representing PCI devices
//+
//[DESCRIPTION]
// PCIDevice represents a generic PCI device that was found on the system by the PCIBios class.
// No assumption should be made about the 'graphic' nature of the PCIDevice object.
// This class provides query functions to identify the device it represents; it also provides methods to enable
//& and disable (always from the PCI point of view) the device.
// Since this class is one of the base classes for the LvMainBoard class all objects of this class inherit the
//& PCI interface.
//.
class PCIDevice {
private:
protected:
PCIBios *TheBios; // May be global since just one is allowed
// (in this way we have no reference to the outside world)
PCICfgSpace Config;
U8BIT *FullConfig;
U8BIT BusNr;
U8BIT DevNr;
U8BIT FnNr;
void DisableOnly(void);
int PciId;
#if defined(__WIN3264__) || defined(__UNIX__)
DRVHANDLE DriverHandle;
BOOL OriginalOpen;
#endif
// void ReadConfigField(U16BIT Address, U16BIT *Value, U8BIT Size);
// void WriteConfigField(U16BIT Address, U16BIT *Value, U8BIT Size);
public:
virtual BOOL ReadConfig(void);
PCIDevice(PCIDevice *aPCIDevice);
PCIDevice(PCIBios *aBios, U8BIT BusNr, U8BIT DevNr, U8BIT FnNr, int aPciId=0);
~PCIDevice(void);
U8BIT GetPCIBusNr(void) { return BusNr; }
U8BIT GetPCIDeviceNr(void) { return DevNr; }
U8BIT GetPCIFnNr(void) { return FnNr; }
PCIBios *GetPCIBios(void) { return TheBios; }
U16BIT GetVendorId(void) { return Config.VendorId; }
U16BIT GetDeviceId(void) { return Config.DeviceId; }
U32BIT GetROMBaseAddress(void) { return Config.ROMBaseAddress; }
U32BIT GetBaseAddress(int Index) { return Config.BaseAddress[Index]+GetBaseOffset(Index); }
U8BIT ReadCfgField(U8BIT Offset, U32BIT *Buffer, U8BIT Operation);
U8BIT WriteCfgField(U8BIT Offset, U32BIT Buffer, U8BIT Operation);
virtual U32BIT GetBaseOffset(int Index) { return 0; }
void FillPCIDeviceDescriptor(PCICfgSpace *Dev);
void FillPCIDeviceDescriptorEx(U8BIT *Dev);
void EnableIOAccess(void);
void DisableIOAccess(void);
void EnableMemAccess(void);
void DisableMemAccess(void);
void EnablePalAccess(void);
void DisablePalAccess(void);
void Enable(void);
void Disable(void);
void EnableROM(void);
void DisableROM(void);
virtual void WakeUp(void) {}
BOOL IsActive(void);
BOOL IsVGACompatible(void) { return (Config.ClassCode.Base==0 && Config.ClassCode.Sub==1) || Config.ClassCode.Base==3; }
BOOL IsMultimedia(void) { return (Config.ClassCode.Base==4 && Config.ClassCode.Sub!=1); }
BOOL IsMultiDevice(void) { return (Config.HeaderType & 0x80)!=0; }
int VgaNr(void);
#if defined(__WIN3264__) || defined(__UNIX__)
char *GetWin32DeviceName(char *Buffer);
#endif
friend class LvPCIChip;
friend int operator ==(const PCIDevice& D1, const PCIDevice& D2);
};
//-[CLASS] PCIDevice
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//[CLASS] PCIBios
// Class representing PCI Bios
//+
//[DESCRIPTION]
// PCIBios represents the PCI bios of the system; all the accesses to the Bios should be made through objects of this
//& class; it provides 'automatic' detection of PCI bios and collection of PCI information as well as rules to determine
//& the presence of PCI devices in the system.
// There should be just one object of this class per application, created on startup.
// When the object is created it checks for the presence of a PCI bios then, if found, scans the busses to identify
//& the PCI devices eventually installed in the system.
//.
//[LVSTATUS]
// The actual implementation was taken by the 'old' code from Felix. All the methods should be rewritten in a better way.
// To be done: providing memory access if the bios allows it (we are in protected mode)
//.
class PCIBios {
private:
BOOL Present;
U8BIT NrDevice;
U8BIT HwMechanism;
U16BIT Version;
U8BIT LastBus;
BOOL CheckPresence(void);
void GetIrqRoutingOptions(void);
PCIDevice *ActiveVGA;
PCIDevice *SystemActiveVGA;
HANDLE hPciOut;
protected:
PCIDevice **pDevice;
// PCIDevice *SetActiveVGA(PCIDevice *NewActiveVGA) { PCIDevice *Tmp=ActiveVGA; ActiveVGA=NewActiveVGA; return Tmp; }
#if defined(__WIN3264__) || defined(__UNIX__)
DRVHANDLE OpenDriver(U8BIT PciId, U8BIT BusNr, U8BIT DevNr);
void CloseDriver(DRVHANDLE DriverHandle);
char *GetWin32DeviceName(U8BIT BusNr, U8BIT DevNr, char *Buffer);
#endif
friend class PCIDevice;
public:
PCIBios(void);
~PCIBios(void);
PCIDevice *GetActiveVGA(void);
PCIDevice *GetSystemActiveVGA(void) { return SystemActiveVGA; }
int GetVgaNr(PCIDevice *aPCIDevice);
U8BIT ReadCfgField(U8BIT BusNr, U8BIT DevNr, U8BIT FnNr, U8BIT Offset, U32BIT *Buffer, U8BIT Operation);
U8BIT WriteCfgField(U8BIT BusNr, U8BIT DevNr, U8BIT FnNr, U8BIT Offset, U32BIT Buffer, U8BIT Operation);
U8BIT WriteCommand(U8BIT BusNr, U8BIT DevNr, U8BIT FnNr, U8BIT Code);
U8BIT ReadCommand(U8BIT BusNr, U8BIT DevNr, U8BIT FnNr, U16BIT *Value);
BOOL IsPresent(void) { return Present; }
U8BIT GetHwMechanism(void) { return HwMechanism; }
U16BIT GetVersion(void) { return Version; }
U8BIT GetLastBus(void) { return LastBus; }
U8BIT GetNrDevice(void) { return NrDevice; }
PCIDevice *GetDevice(int Index) { return Index<NrDevice ? pDevice[Index] : NULL; }
PCIDevice *FindDevice(int BusNr, int DevNr, int FnNr);
char *GetDeviceTextDescription(int DeviceNr, char *Buffer, BOOL Addresses=TRUE);
char *GetVendorDescription(U16BIT VendorId, char *Buffer);
char *GetClassDescription(U8BIT Base, U8BIT Sub, char *Buffer);
BOOL DeviceInSlot(U8BIT BusNr, U8BIT DevNr, U8BIT FnNr);
int GetFullVendorDescription(U16BIT VendorId, U16BIT DeviceId, U16BIT OEMVendorId, U16BIT OEMDeviceId, char *VId, char *DId, char *OVId, char *ODId);
};
//-[CLASS] PCIBios
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//[CLASS] PCIDevice
//+
//=====================================================================
//[FUNCTION/dynamic/public] PCIDevice::EnableIOAccess
// Test
//+
//[PARAMETERS]
// None
//.
//[RETURNS]
//.
//[PROTOTYPE]
void inline PCIDevice::EnableIOAccess(void)
//.
{
TheBios->WriteCommand(BusNr, DevNr, FnNr, PCICMD_ENABLE_IO);
}
//-[FUNCTION] PCIDevice::EnableIOAccess
//=====================================================================
//[FUNCTION/dynamic/public] PCIDevice::DisableIOAccess
// Test
//+
//[PARAMETERS]
// None
//.
//[RETURNS]
//.
//[PROTOTYPE]
void inline PCIDevice::DisableIOAccess(void)
//.
{
TheBios->WriteCommand(BusNr, DevNr, FnNr, PCICMD_DISABLE_IO);
}
//-[FUNCTION] PCIDevice::DisableIOAccess
//=====================================================================
//[FUNCTION/dynamic/public] PCIDevice::EnableMemAccess
// Test
//+
//[PARAMETERS]
// None
//.
//[RETURNS]
//.
//[PROTOTYPE]
void inline PCIDevice::EnableMemAccess(void)
//.
{
TheBios->WriteCommand(BusNr, DevNr, FnNr, PCICMD_ENABLE_MEM);
}
//-[FUNCTION] PCIDevice::EnableMemAccess
//=====================================================================
//[FUNCTION/dynamic/public] PCIDevice::DisableMemAccess
// Test
//+
//[PARAMETERS]
// None
//.
//[RETURNS]
//.
//[PROTOTYPE]
void inline PCIDevice::DisableMemAccess(void)
//.
{
TheBios->WriteCommand(BusNr, DevNr, FnNr, PCICMD_DISABLE_MEM);
}
//-[FUNCTION] PCIDevice::DisableMemAccess
//=====================================================================
//[FUNCTION/dynamic/public] PCIDevice::EnablePalAccess
// Test
//+
//[PARAMETERS]
// None
//.
//[RETURNS]
//.
//[PROTOTYPE]
void inline PCIDevice::EnablePalAccess(void)
//.
{
TheBios->WriteCommand(BusNr, DevNr, FnNr, PCICMD_ENABLE_PAL);
}
//-[FUNCTION] PCIDevice::EnablePalAccess
//=====================================================================
//[FUNCTION/dynamic/public] PCIDevice::DisablePalAccess
// Test
//+
//[PARAMETERS]
// None
//.
//[RETURNS]
//.
//[PROTOTYPE]
void inline PCIDevice::DisablePalAccess(void)
//.
{
TheBios->WriteCommand(BusNr, DevNr, FnNr, PCICMD_DISABLE_PAL);
}
//-[FUNCTION] PCIDevice::DisablePalAccess
//-[CLASS] PCIDevice
int inline operator ==(const PCIDevice& D1, const PCIDevice& D2)
{
return D1.BusNr==D2.BusNr && D1.DevNr==D2.DevNr;
}
#include <lvpackof.h>
#endif
//-[HEADER] PCI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -