Specifications
D
evice Driver Programming
3-6
Finding the Correct Adapter Structure 3
Use the routines adapter_find and adapter_find2 to locate instances of your device. An
alternate method is to scan the external “adapters” array for “adapter_count” entries and
match the “adapter_type” element with a value generated from the macro
“PCI_ADAPTER_TYPE” and check the “adapter_state” element for the
“ADAPTER_PRESENT” flag.
Accessing the Configuration Space Registers 3
Use the routines “pci_cfgspc_read” and “pci_cfgspc_write” to access the configuration
space registers other than a BAR or the “PCI CMD” register. A prerequisite for correct
operation is that the routines must be given a pointer to the correct “adapter” structure
entry. Note: These routines read and write 32 bit quantities on 4 byte aligned boundaries
only.
Use “pci_cfg_cmd” routine to enable/disable PCI I/O and memory space slave operation.
This routine has no effect on Configuration space accesses. The “pci_cfg_cmd” routine is
also used to enable PCI bus master operation.
As a general note, most PCI devices also have a Base Address Register assigned to map
the PCI device’s configuration registers. It would advisable to use the BAR mapped con-
figuration space registers to access these resource whenever they required frequent access-
ing by the device driver during normal operation.
Getting/Releasing the Base Address Register Assignments 3
Use the “pci_iospc_alloc”, “pci_memspc_alloc”, “pci_iospc_free” and
“pci_memspc_free” routines to retrieve assigned values from Base Address Registers or
release them. The “iospc” and “memspc” versions may be used interchangeably, as they
will retrieve the assigned values or query the PCI device to determine which type of PCI
space is required.
The returned “pci_spc_t” structure will contain the type of space, size, the assigned PCI
address and the equivalent CPU physical address.
It is not necessary or desirable to release PCI allocations each time the driver is closed or
unloaded. The allocation routines will return the same values for each BAR every time
they are called. The exception to this rule is if you release them using a
“pci_XXXspc_free” call. In which case the assigned address may be different or fail allo-
cate.
Determining the Kernel Virtual Address of PCI Base Address Register3
To get a working Kernel virtual address of a PCI Base address register, the “physmap”