Unit PCI - Ultibo.org

Return to Unit Reference

Description


Ultibo PCI/PCIe Interface unit

Constants


PCI device, driver and host specific constants PCI_*

PCI_DEVICE_PREFIX = 'PCI'; Name prefix for PCI Devices
PCI_DRIVER_PREFIX = 'PCI'; Name prefix for PCI Drivers
PCI_HOST_PREFIX = 'PCIHost'; Name prefix for PCI Hosts

PCI device type PCI_TYPE_*

PCI_TYPE_NONE = 0;  
 
PCI_TYPE_MAX = 0;  
 
PCI_TYPE_NAMES:array[PCI_TYPE_NONE..PCI_TYPE_MAX] of String = ('PCI_TYPE_NONE');  

PCI device state PCI_STATE_*

PCI_STATE_DETACHED = 0;  
PCI_STATE_DETACHING = 1;  
PCI_STATE_ATTACHING = 2;  
PCI_STATE_ATTACHED = 3;  
 
PCI_STATE_MAX = 3;  
 
PCI_STATE_NAMES:array[PCI_STATE_DETACHED..PCI_STATE_MAX] of String = ('PCI_STATE_DETACHED', 'PCI_STATE_DETACHING', 'PCI_STATE_ATTACHING', 'PCI_STATE_ATTACHED');  

PCI device status PCI_STATUS_*

PCI_STATUS_UNBOUND = 0;  
PCI_STATUS_BOUND = 1;  
 
PCI_STATUS_MAX = 1;  
 
PCI_STATUS_NAMES:array[PCI_STATUS_UNBOUND..PCI_STATUS_MAX] of String = ('PCI_STATUS_UNBOUND', 'PCI_STATUS_BOUND');  

PCI device flag PCI_FLAG_*

PCI_FLAG_NONE = $00000000;  

PCI host type PCIHOST_TYPE_*

PCIHOST_TYPE_NONE = 0;  
PCIHOST_TYPE_PCI = 1;  
PCIHOST_TYPE_PCIX = 2;  
PCIHOST_TYPE_PCIE = 3;  
 
PCIHOST_TYPE_MAX = 3;  
 
PCIHOST_TYPE_NAMES:array[PCIHOST_TYPE_NONE..PCIHOST_TYPE_MAX] of String = ('PCIHOST_TYPE_NONE', 'PCIHOST_TYPE_PCI', 'PCIHOST_TYPE_PCIX', 'PCIHOST_TYPE_PCIE');  

PCI host state PCIHOST_STATE_*

PCIHOST_STATE_DISABLED = 0;  
PCIHOST_STATE_ENABLED = 1;  
 
PCIHOST_STATE_MAX = 1;  
 
PCIHOST_STATE_NAMES:array[PCIHOST_STATE_DISABLED..PCIHOST_STATE_MAX] of String = ('PCIHOST_STATE_DISABLED','PCIHOST_STATE_ENABLED');  

PCI host flag PCIHOST_FLAG_*

PCIHOST_FLAG_NONE = $00000000;  
PCIHOST_FLAG_SHARED = $00000001;  
PCIHOST_FLAG_NOCACHE = $00000002;  

PCI status code PCI_STATUS_*

PCI_STATUS_SUCCESS = 0; Function successful

PCI logging PCI_LOG_*

PCI_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG; PCI debugging messages
PCI_LOG_LEVEL_INFO = LOG_LEVEL_INFO; PCI informational messages, such as a device being attached or detached.
PCI_LOG_LEVEL_WARN = LOG_LEVEL_WARN; PCI warning messages
PCI_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR; PCI error messages
PCI_LOG_LEVEL_NONE = LOG_LEVEL_NONE; No PCI messages

Type definitions



PCI device

PPCIDevice = ^TPCIDevice;

TPCIDevice = record

Device Properties
Device:TDevice; The Device entry for this PCI device
PCI Properties
PCIId:LongWord; Unique Id of this PCI in the PCI device table
PCIState:LongWord; PCI device state (eg PCI_STATE_ATTACHED)
PCIStatus:LongWord; PCI device status (eg PCI_STATUS_BOUND)
Host:PPCIHost; Host controller this PCI device is connected to (Set by PCI core)
Parent:PPCIDevice; Parent this PCI device is connected to, if any (Set by PCI core)
Driver:PPCIDriver; Driver this PCI device is bound to, if any (Set by PCI core)
Driver Properties
Lock:TMutexHandle; PCI device lock
Internal Properties
Prev:PPCIDevice; Previous entry in PCI device table
Next:PPCIDevice; Next entry in PCI device table

PCI device bind callback

TPCIDeviceBind = function(Device:PPCIDevice):LongWord;

PCI device unbind callback

TPCIDeviceUnbind = function(Device:PPCIDevice; Driver:PPCIDriver):LongWord;

PCI device enumeration callback

TPCIDeviceEnumerate = function(Device:PPCIDevice; Data:Pointer):LongWord;

PCI device notification callback

TPCIDeviceNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;

PCI driver

PPCIDriver = ^TPCIDriver;

TPCIDriver = record

Driver Properties
Driver:TDriver; The Driver entry for this PCI Driver
PCI Properties
DriverBind:TPCIDriverBind; A Driver specific DriverBind method implementing the standard PCI driver interface
DriverUnbind:TPCIDriverUnbind; A Driver specific DriverUnbind method implementing the standard PCI driver interface
Interface Properties
Lock:TMutexHandle; Driver lock
Internal Properties
Prev:PPCIDriver; Previous entry in Driver table
Next:PPCIDriver; Next entry in Driver table

PCI driver enumeration callback

TPCIDriverEnumerate = function(Driver:PPCIDriver; Data:Pointer):LongWord;

PCI driver bind

TPCIDriverBind = function(Device:PPCIDevice):LongWord;

PCI driver unbind

TPCIDriverUnbind = function(Device:PPCIDevice):LongWord;

PCI host

PPCIHost = ^TPCIHost;

TPCIHost = record

Device Properties
Device:TDevice; The Device entry for this PCI Host
PCI Properties
HostId:LongWord; Unique Id of this Host in the Host table
HostState:LongWord Host state (eg PCIHOST_STATE_ENABLED)
HostStart:TPCIHostStart; A Host specific HostStart method implementing the standard PCI host interface
HostStop:TPCIHostStop; A Host specific HostStop method implementing the standard PCI host interface
HostReset:TPCIHostReset; A Host specific HostReset method implementing the standard PCI host interface
Driver Properties
Lock:TMutexHandle; Host lock
Internal Properties
Prev:PPCIHost; Previous entry in Host table
Next:PPCIHost; Next entry in Host table

PCI host enumeration callback

TPCIHostEnumerate = function(Host:PPCIHost; Data:Pointer):LongWord;

PCI host notification callback

TPCIHostNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;

PCI host start

TPCIHostStart = function(Host:PPCIHost):LongWord;

PCI host stop

TPCIHostStop = function(Host:PPCIHost):LongWord;

PCI host reset

TPCIHostReset = function(Host:PPCIHost):LongWord;

PCI logging

TPCILogOutput = procedure(const AText:String; Data:Pointer);

Public variables



PCI logging

PCI_DEFAULT_LOG_LEVEL:LongWord = PCI_LOG_LEVEL_DEBUG; Minimum level for PCI messages. Only messages with level greater than or equal to this will be printed.

Function declarations



Initialization functions

procedure PCIInit;

Description: Performs basic initialization of the PCI core driver, after this devices, hosts and drivers can be registered however nothing will work until PCIStart is called

function PCIStart:LongWord;

Description: Starts all registered PCI hosts and begins the PCI enumeration process

function PCIStop:LongWord;

Description: To be documented

procedure PCIAsyncStart(Host:PPCIHost);

Description: To be documented

PCI device, driver and host functions

function PCIDeviceAllocate(Host:PPCIHost):PPCIDevice;

Description: Create and Register a new Device entry in the Device table

Host The Host this device is attached to
Return Pointer to new Device entry or nil if device could not be created
function PCIDeviceRelease(Device:PPCIDevice):LongWord;

Description: Deregister and Destroy a Device from the Device table

Device The device to deregister and destroy
Return ERROR_SUCCESS if completed or another error code on failure
function PCIDeviceFind(PCIId:LongWord):PPCIDevice;

Description: To be documented

function PCIDeviceFindById(VendorId,ProductId:Word):PPCIDevice;

Description: To be documented

function PCIDeviceFindByName(const Name:String):PPCIDevice; inline;

Description: To be documented

function PCIDeviceFindByDescription(const Description:String):PPCIDevice; inline;

Description: To be documented

function PCIDeviceEnumerate(Callback:TPCIDeviceEnumerate; Data:Pointer):LongWord;

Description: To be documented

function PCIDeviceNotification(Device:PPCIDevice; Callback:TPCIDeviceNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;

Description: To be documented

function PCIDriverCreate:PPCIDriver;

Description: Create a new PCI Driver entry

Return Pointer to new Driver entry or nil if driver could not be created
function PCIDriverCreateEx(Size:LongWord):PPCIDriver;

Description: Create a new PCI Driver entry

Size Size in bytes to allocate for new driver (Including the driver entry)
Return Pointer to new Driver entry or nil if driver could not be created
function PCIDriverDestroy(Driver:PPCIDriver):LongWord;

Description: Destroy an existing PCI Driver entry

function PCIDriverRegister(Driver:PPCIDriver):LongWord;

Description: Register a new PCI Driver in the Driver table

function PCIDriverDeregister(Driver:PPCIDriver):LongWord;

Description: Deregister a PCI Driver from the Driver table

function PCIDriverFind(DriverId:LongWord):PPCIDriver;

Description: Find a driver by Id in the PCI Driver table

function PCIDriverFindByName(const Name:String):PPCIDriver; inline;

Description: Find a driver by name in the Driver table

function PCIDriverEnumerate(Callback:TPCIDriverEnumerate; Data:Pointer):LongWord;

Description: Enumerate all drivers in the PCI Driver table

function PCIHostCreate:PPCIHost;

Description: Create a new Host entry

Return Pointer to new Host entry or nil if host could not be created
function PCIHostCreateEx(Size:LongWord):PPCIHost;

Description: Create a new Host entry

Size Size in bytes to allocate for new host (Including the host entry)
Return Pointer to new Host entry or nil if host could not be created
function PCIHostDestroy(Host:PPCIHost):LongWord;

Description: Destroy an existing Host entry

function PCIHostRegister(Host:PPCIHost):LongWord;

Description: Register a new Host in the Host table

function PCIHostDeregister(Host:PPCIHost):LongWord;

Description: Deregister a Host from the Host table

function PCIHostFind(HostId:LongWord):PPCIHost;

Description: To be documented

function PCIHostFindByName(const Name:String):PPCIHost; inline;

Description: To be documented

function PCIHostFindByDescription(const Description:String):PPCIHost; inline;

Description: To be documented

function PCIHostEnumerate(Callback:TPCIHostEnumerate; Data:Pointer):LongWord;

Description: To be documented

function PCIHostNotification(Host:PPCIHost; Callback:TPCIHostNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;

Description: To be documented

PCI device, driver and host helper functions

function PCIDeviceGetCount:LongWord; inline;

Description: Get the current device count

function PCIDeviceCheck(Device:PPCIDevice):PPCIDevice;

Description: Check if the supplied Device is in the device table

function PCIDriverGetCount:LongWord; inline;

Description: Get the current PCI driver count

function PCIDriverCheck(Driver:PPCIDriver):PPCIDriver;

Description: Check if the supplied PCI Driver is in the driver table

function PCIHostGetCount:LongWord; inline;

Description: Get the current host count

function PCIHostCheck(Host:PPCIHost):PPCIHost;

Description: Check if the supplied Host is in the host table

function PCIStatusToString(Status:LongWord):String;

Description: Translates a PCI status code into a string

function PCIDeviceTypeToString(PCIType:LongWord):String;

Description: To be documented

function PCIDeviceStateToString(PCIState:LongWord):String;

Description: To be documented

function PCIDeviceStatusToString(PCIStatus:LongWord):String;

Description: To be documented

function PCIDeviceStateToNotification(State:LongWord):LongWord;

Description: Convert a Device state value into the notification code for device notifications

function PCIDeviceStatusToNotification(Status:LongWord):LongWord;

Description: Convert a Device status value into the notification code for device notifications

function PCIHostTypeToString(HostType:LongWord):String;

Description: To be documented

function PCIHostStateToString(HostState:LongWord):String;

Description: To be documented

function PCIHostStateToNotification(State:LongWord):LongWord;

Description: Convert a Host state value into the notification code for device notifications

procedure PCILog(Level:LongWord;Device:PPCIDevice; const AText:String);

Description: To be documented

procedure PCILogInfo(Device:PPCIDevice; const AText:String); inline;

Description: To be documented

procedure PCILogWarn(Device:PPCIDevice; const AText:String); inline;

Description: To be documented

procedure PCILogError(Device:PPCIDevice; const AText:String); inline;

Description: To be documented

procedure PCILogDebug(Device:PPCIDevice; const AText:String); inline;

Description: To be documented

Return to Unit Reference