Scanning for devices, Generic config information – Comtrol eCos User Manual
Page 442

Chapter 30. The eCos PCI Library
Scanning for devices
After the bus has been initialized, it is possible to scan it for devices. This is done using the function:
cyg_bool cyg_pci_find_next(
cyg_pci_device_id cur_devid,
cyg_pci_device_id *next_devid );
It will scan the bus for devices starting at
cur_devid
. If a device is found, its devid is stored in
next_devid
and the function returns
true
.
The
pci1
test’s outer loop looks like:
cyg_pci_init();
if (cyg_pci_find_next(CYG_PCI_NULL_DEVID, &devid)) {
do {
<
use devid
>
} while (cyg_pci_find_next(devid, &devid));
}
What happens is that the bus gets initialized and a scan is started.
CYG_PCI_NULL_DEVID
causes
cyg_pci_find_next()
to restart its scan. If the bus does not contain any devices, the first call to
cyg_pci_find_next()
will return
false
.
If the call returns
true
, a loop is entered where the found devid is used. After devid processing has completed, the
next device on the bus is searched for;
cyg_pci_find_next()
continues its scan from the current devid. The loop
terminates when no more devices are found on the bus.
This is the generic way of scanning the bus, enumerating all the devices on the bus. But if the application is looking
for a device of a given device class (e.g., a SCSI controller), or a specific vendor device, these functions simplify
the task a bit:
cyg_bool cyg_pci_find_class(
cyg_uint32 dev_class,
cyg_pci_device_id *devid );
cyg_bool cyg_pci_find_device(
cyg_uint16 vendor, cyg_uint16 device,
cyg_pci_device_id *devid );
They work just like
cyg_pci_find_next()
, but only return true when the dev_class or vendor/device qualifiers
match those of a device on the bus. The devid serves as both an input and an output operand: the scan starts at the
given device, and if a device is found devid is updated with the value for the found device.
The
<
cyg/io/pci_cfg.h
>
header file (included by
pci.h
) contains definitions for PCI class, vendor and device
codes which can be used as arguments to the find functions. The list of vendor and device codes is not complete:
add new codes as necessary. If possible also register the codes at the PCI Code List (http://www.yourvote.com/pci)
(http://www.yourvote.com/pci) which is where the eCos definitions are generated from.
Generic config information
When a valid device ID (devid) is found using one of the above functions, the associated device can be queried and
controlled using the functions:
void cyg_pci_get_device_info (
cyg_pci_device_id devid,
cyg_pci_device *dev_info );
void cyg_pci_set_device_info (
cyg_pci_device_id devid,
cyg_pci_device *dev_info );
338