PCI Support Library¶
- unsignedcharpci_bus_max_busnr(structpci_bus*bus)¶
returns maximum PCI bus number of given bus’ children
Parameters
structpci_bus*buspointer to PCI bus structure to search
Description
Given a PCI bus, returns the highest PCI bus number present in the setincluding the given PCI bus and its list of child PCI buses.
- intpci_status_get_and_clear_errors(structpci_dev*pdev)¶
return and clear error bits in PCI_STATUS
Parameters
structpci_dev*pdevthe PCI device
Description
Returns error bits set in PCI_STATUS and clears them.
- u8pci_find_capability(structpci_dev*dev,intcap)¶
query for devices’ capabilities
Parameters
structpci_dev*devPCI device to query
intcapcapability code
Description
Tell if a device supports a given PCI capability.Returns the address of the requested capability structure within thedevice’s PCI configuration space or 0 in case the device does notsupport it. Possible values forcap include:
PCI_CAP_ID_PMPower ManagementPCI_CAP_ID_AGPAccelerated Graphics PortPCI_CAP_ID_VPDVital Product DataPCI_CAP_ID_SLOTIDSlot IdentificationPCI_CAP_ID_MSIMessage Signalled InterruptsPCI_CAP_ID_CHSWPCompactPCI HotSwapPCI_CAP_ID_PCIXPCI-XPCI_CAP_ID_EXPPCI Express
- u8pci_bus_find_capability(structpci_bus*bus,unsignedintdevfn,intcap)¶
query for devices’ capabilities
Parameters
structpci_bus*busthe PCI bus to query
unsignedintdevfnPCI device to query
intcapcapability code
Description
Likepci_find_capability() but works for PCI devices that do not have apci_dev structure set up yet.
Returns the address of the requested capability structure within thedevice’s PCI configuration space or 0 in case the device does notsupport it.
- u16pci_find_next_ext_capability(structpci_dev*dev,u16start,intcap)¶
Find an extended capability
Parameters
structpci_dev*devPCI device to query
u16startaddress at which to start looking (0 to start at beginning of list)
intcapcapability code
Description
Returns the address of the next matching extended capability structurewithin the device’s PCI configuration space or 0 if the device doesnot support it. Some capabilities can occur several times, e.g., thevendor-specific capability, and this provides a way to find them all.
- u16pci_find_ext_capability(structpci_dev*dev,intcap)¶
Find an extended capability
Parameters
structpci_dev*devPCI device to query
intcapcapability code
Description
Returns the address of the requested extended capability structurewithin the device’s PCI configuration space or 0 if the device doesnot support it. Possible values forcap include:
PCI_EXT_CAP_ID_ERRAdvanced Error ReportingPCI_EXT_CAP_ID_VCVirtual ChannelPCI_EXT_CAP_ID_DSNDevice Serial NumberPCI_EXT_CAP_ID_PWRPower Budgeting
- u64pci_get_dsn(structpci_dev*dev)¶
Read and return the 8-byte Device Serial Number
Parameters
structpci_dev*devPCI device to query
Description
Looks up the PCI_EXT_CAP_ID_DSN and reads the 8 bytes of the Device SerialNumber.
Returns the DSN, or zero if the capability does not exist.
- u8pci_find_next_ht_capability(structpci_dev*dev,u8pos,intht_cap)¶
query a device’s HyperTransport capabilities
Parameters
structpci_dev*devPCI device to query
u8posPosition from which to continue searching
intht_capHyperTransport capability code
Description
To be used in conjunction withpci_find_ht_capability() to search forall capabilities matchinght_cap.pos should always be a value returnedfrompci_find_ht_capability().
NB. To be 100% safe against broken PCI devices, the caller should takesteps to avoid an infinite loop.
- u8pci_find_ht_capability(structpci_dev*dev,intht_cap)¶
query a device’s HyperTransport capabilities
Parameters
structpci_dev*devPCI device to query
intht_capHyperTransport capability code
Description
Tell if a device supports a given HyperTransport capability.Returns an address within the device’s PCI configuration spaceor 0 in case the device does not support the request capability.The address points to the PCI capability, of type PCI_CAP_ID_HT,which has a HyperTransport capability matchinght_cap.
- u16pci_find_vsec_capability(structpci_dev*dev,u16vendor,intcap)¶
Find a vendor-specific extended capability
Parameters
structpci_dev*devPCI device to query
u16vendorVendor ID for which capability is defined
intcapVendor-specific capability ID
Description
Ifdev has Vendor IDvendor, search for a VSEC capability withVSEC IDcap. If found, return the capability offset inconfig space; otherwise return 0.
- u16pci_find_dvsec_capability(structpci_dev*dev,u16vendor,u16dvsec)¶
Find DVSEC for vendor
Parameters
structpci_dev*devPCI device to query
u16vendorVendor ID to match for the DVSEC
u16dvsecDesignated Vendor-specific capability ID
Description
If DVSEC has Vendor IDvendor and DVSEC IDdvsec return the capabilityoffset in config space; otherwise return 0.
- structresource*pci_find_parent_resource(conststructpci_dev*dev,structresource*res)¶
return resource region of parent bus of given region
Parameters
conststructpci_dev*devPCI device structure contains resources to be searched
structresource*reschild resource record for which parent is sought
Description
For given resource region of given device, return the resource region ofparent bus the given region is contained in.
- structresource*pci_find_resource(structpci_dev*dev,structresource*res)¶
Return matching PCI device resource
Parameters
structpci_dev*devPCI device to query
structresource*resResource to look for
Description
Goes over standard PCI resources (BARs) and checks if the given resourceis partially or fully contained in any of them. In that case thematching resource is returned,NULL otherwise.
- intpci_platform_power_transition(structpci_dev*dev,pci_power_tstate)¶
Use platform to change device power state
Parameters
structpci_dev*devPCI device to handle.
pci_power_tstateState to put the device into.
- intpci_set_power_state(structpci_dev*dev,pci_power_tstate)¶
Set the power state of a PCI device
Parameters
structpci_dev*devPCI device to handle.
pci_power_tstatePCI power state (D0, D1, D2, D3hot) to put the device into.
Description
Transition a device to a new power state, using the platform firmware and/orthe device’s PCI PM registers.
RETURN VALUE:-EINVAL if the requested state is invalid.-EIO if device does not support PCI PM or its PM capabilities register has awrong version, or device doesn’t support the requested state.0 if the transition is to D1 or D2 but D1 and D2 are not supported.0 if device already is in the requested state.0 if the transition is to D3 but D3 is not supported.0 if device’s power state has been successfully changed.
- intpci_save_state(structpci_dev*dev)¶
save the PCI configuration space of a device before suspending
Parameters
structpci_dev*devPCI device that we’re dealing with
- voidpci_restore_state(structpci_dev*dev)¶
Restore the saved state of a PCI device
Parameters
structpci_dev*devPCI device that we’re dealing with
- structpci_saved_state*pci_store_saved_state(structpci_dev*dev)¶
Allocate and return an opaque
structcontainingthe device saved state.
Parameters
structpci_dev*devPCI device that we’re dealing with
Description
Return NULL if no state or error.
- intpci_load_saved_state(structpci_dev*dev,structpci_saved_state*state)¶
Reload the provided save state into
structpci_dev.
Parameters
structpci_dev*devPCI device that we’re dealing with
structpci_saved_state*stateSaved state returned from
pci_store_saved_state()
- intpci_load_and_free_saved_state(structpci_dev*dev,structpci_saved_state**state)¶
Reload the save state pointed to by state, and free the memory allocated for it.
Parameters
structpci_dev*devPCI device that we’re dealing with
structpci_saved_state**statePointer to saved state returned from
pci_store_saved_state()
- intpci_reenable_device(structpci_dev*dev)¶
Resume abandoned device
Parameters
structpci_dev*devPCI device to be resumed
NOTE
This function is a backend ofpci_default_resume() and is not supposedto be called by normal code, write proper resume handler and use it instead.
- intpci_enable_device_mem(structpci_dev*dev)¶
Initialize a device for use with Memory space
Parameters
structpci_dev*devPCI device to be initialized
Description
Initialize device before it’s used by a driver. Ask low-level codeto enable Memory resources. Wake up the device if it was suspended.Beware, this function can fail.
- intpci_enable_device(structpci_dev*dev)¶
Initialize device before it’s used by a driver.
Parameters
structpci_dev*devPCI device to be initialized
Description
Initialize device before it’s used by a driver. Ask low-level codeto enable I/O and memory. Wake up the device if it was suspended.Beware, this function can fail.
Note we don’t actually enable the device many times if we callthis function repeatedly (we just increment the count).
- voidpci_disable_device(structpci_dev*dev)¶
Disable PCI device after use
Parameters
structpci_dev*devPCI device to be disabled
Description
Signal to the system that the PCI device is not in use by the systemanymore. This only involves disabling PCI bus-mastering, if active.
Note we don’t actually disable the device until all callers ofpci_enable_device() have calledpci_disable_device().
- intpci_set_pcie_reset_state(structpci_dev*dev,enumpcie_reset_statestate)¶
set reset state for device dev
Parameters
structpci_dev*devthe PCIe device reset
enumpcie_reset_statestateReset state to enter into
Description
Sets the PCI reset state for the device.
- boolpci_pme_capable(structpci_dev*dev,pci_power_tstate)¶
check the capability of PCI device to generate PME#
Parameters
structpci_dev*devPCI device to handle.
pci_power_tstatePCI state from which device will issue PME#.
- voidpci_pme_active(structpci_dev*dev,boolenable)¶
enable or disable PCI device’s PME# function
Parameters
structpci_dev*devPCI device to handle.
boolenable‘true’ to enable PME# generation; ‘false’ to disable it.
Description
The caller must verify that the device is capable of generating PME# beforecalling this function withenable equal to ‘true’.
- intpci_enable_wake(structpci_dev*pci_dev,pci_power_tstate,boolenable)¶
change wakeup settings for a PCI device
Parameters
structpci_dev*pci_devTarget device
pci_power_tstatePCI state from which device will issue wakeup events
boolenableWhether or not to enable event generation
Description
Ifenable is set, checkdevice_may_wakeup() for the device before calling__pci_enable_wake() for it.
- intpci_wake_from_d3(structpci_dev*dev,boolenable)¶
enable/disable device to wake up from D3_hot or D3_cold
Parameters
structpci_dev*devPCI device to prepare
boolenableTrue to enable wake-up event generation; false to disable
Description
Many drivers want the device to wake up the system from D3_hot or D3_coldand this function allows them to set that up cleanly -pci_enable_wake()should not be called twice in a row to enable wake-up due to PCI PM vs ACPIordering constraints.
This function only returns error code if the device is not allowed to wakeup the system from sleep or it is not capable of generating PME# from bothD3_hot and D3_cold and the platform is unable to enable wake-up power for it.
- intpci_prepare_to_sleep(structpci_dev*dev)¶
prepare PCI device for system-wide transition into a sleep state
Parameters
structpci_dev*devDevice to handle.
Description
Choose the power state appropriate for the device depending on whetherit can wake up the system and/or is power manageable by the platform(PCI_D3hot is the default) and put the device into that state.
- intpci_back_from_sleep(structpci_dev*dev)¶
turn PCI device on during system-wide transition into working state
Parameters
structpci_dev*devDevice to handle.
Description
Disable device’s system wake-up capability and put it into D0.
- boolpci_dev_run_wake(structpci_dev*dev)¶
Check if device can generate run-time wake-up events.
Parameters
structpci_dev*devDevice to check.
Description
Return true if the device itself is capable of generating wake-up events(through the platform or using the native PCIe PME) or if the device supportsPME and one of its upstream bridges can generate wake-up events.
- pci_power_tpci_choose_state(structpci_dev*dev,pm_message_tstate)¶
Choose the power state of a PCI device.
Parameters
structpci_dev*devTarget PCI device.
pm_message_tstateTarget state for the whole system.
Description
Returns PCI power state suitable fordev andstate.
- voidpci_d3cold_enable(structpci_dev*dev)¶
Enable D3cold for device
Parameters
structpci_dev*devPCI device to handle
Description
This function can be used in drivers to enable D3cold from the devicethey handle. It also updates upstream PCI bridge PM capabilitiesaccordingly.
- voidpci_d3cold_disable(structpci_dev*dev)¶
Disable D3cold for device
Parameters
structpci_dev*devPCI device to handle
Description
This function can be used in drivers to disable D3cold from the devicethey handle. It also updates upstream PCI bridge PM capabilitiesaccordingly.
- intpci_enable_atomic_ops_to_root(structpci_dev*dev,u32cap_mask)¶
enable AtomicOp requests to root port
Parameters
structpci_dev*devthe PCI device
u32cap_maskmask of desired AtomicOp sizes, including one or more of:PCI_EXP_DEVCAP2_ATOMIC_COMP32PCI_EXP_DEVCAP2_ATOMIC_COMP64PCI_EXP_DEVCAP2_ATOMIC_COMP128
Description
Return 0 if all upstream bridges support AtomicOp routing, egressblocking is disabled on all upstream ports, and the root port supportsthe requested completion capabilities (32-bit, 64-bit and/or 128-bitAtomicOp completion), or negative otherwise.
- voidpci_release_region(structpci_dev*pdev,intbar)¶
Release a PCI bar
Parameters
structpci_dev*pdevPCI device whose resources were previously reserved by
pci_request_region()intbarBAR to release
Description
Releases the PCI I/O and memory resources previously reserved by asuccessful call topci_request_region(). Call this function onlyafter all use of the PCI regions has ceased.
- intpci_request_region(structpci_dev*pdev,intbar,constchar*name)¶
Reserve PCI I/O and memory resource
Parameters
structpci_dev*pdevPCI device whose resources are to be reserved
intbarBAR to be reserved
constchar*namename of the driver requesting the resource
Return
0 on success, negative error code on failure.
Description
Mark the PCI region associated with PCI devicepdev BARbar as beingreserved by ownername. Do not access any address inside the PCI regionsunless this call returns successfully.
Returns 0 on success, orEBUSY on error. A warningmessage is also printed on failure.
- voidpci_release_selected_regions(structpci_dev*pdev,intbars)¶
Release selected PCI I/O and memory resources
Parameters
structpci_dev*pdevPCI device whose resources were previously reserved
intbarsBitmask of BARs to be released
Description
Release selected PCI I/O and memory resources previously reserved.Call this function only after all use of the PCI regions has ceased.
- intpci_request_selected_regions(structpci_dev*pdev,intbars,constchar*name)¶
Reserve selected PCI I/O and memory resources
Parameters
structpci_dev*pdevPCI device whose resources are to be reserved
intbarsBitmask of BARs to be requested
constchar*nameName of the driver requesting the resources
Return
0 on success, negative error code on failure.
- intpci_request_selected_regions_exclusive(structpci_dev*pdev,intbars,constchar*name)¶
Request regions exclusively
Parameters
structpci_dev*pdevPCI device to request regions from
intbarsbit mask of BARs to request
constchar*namename of the driver requesting the resources
Return
0 on success, negative error code on failure.
- voidpci_release_regions(structpci_dev*pdev)¶
Release reserved PCI I/O and memory resources
Parameters
structpci_dev*pdevPCI device whose resources were previously reserved by
pci_request_regions()
Description
Releases all PCI I/O and memory resources previously reserved by asuccessful call topci_request_regions(). Call this function onlyafter all use of the PCI regions has ceased.
- intpci_request_regions(structpci_dev*pdev,constchar*name)¶
Reserve PCI I/O and memory resources
Parameters
structpci_dev*pdevPCI device whose resources are to be reserved
constchar*namename of the driver requesting the resources
Description
Mark all PCI regions associated with PCI devicepdev as being reserved byownername. Do not access any address inside the PCI regions unless thiscall returns successfully.
Returns 0 on success, orEBUSY on error. A warningmessage is also printed on failure.
- intpci_request_regions_exclusive(structpci_dev*pdev,constchar*name)¶
Reserve PCI I/O and memory resources
Parameters
structpci_dev*pdevPCI device whose resources are to be reserved
constchar*namename of the driver requesting the resources
Return
0 on success, negative error code on failure.
Description
Mark all PCI regions associated with PCI devicepdev as being reservedby ownername. Do not access any address inside the PCI regionsunless this call returns successfully.
pci_request_regions_exclusive() will mark the region so that /dev/memand the sysfs MMIO access will not be allowed.
Returns 0 on success, orEBUSY on error. A warning message is alsoprinted on failure.
- intpci_remap_iospace(conststructresource*res,phys_addr_tphys_addr)¶
Remap the memory mapped I/O space
Parameters
conststructresource*resResource describing the I/O space
phys_addr_tphys_addrphysical address of range to be mapped
Description
Remap the memory mapped I/O space described by theres and the CPUphysical addressphys_addr into virtual address space. Onlyarchitectures that have memory mapped IO functions defined (and thePCI_IOBASE value defined) should call this function.
- voidpci_unmap_iospace(structresource*res)¶
Unmap the memory mapped I/O space
Parameters
structresource*resresource to be unmapped
Description
Unmap the CPU virtual addressres from virtual address space. Onlyarchitectures that have memory mapped IO functions defined (and thePCI_IOBASE value defined) should call this function.
- voidpci_set_master(structpci_dev*dev)¶
enables bus-mastering for device dev
Parameters
structpci_dev*devthe PCI device to enable
Description
Enables bus-mastering on the device and callspcibios_set_master()to do the needed arch specific settings.
- voidpci_clear_master(structpci_dev*dev)¶
disables bus-mastering for device dev
Parameters
structpci_dev*devthe PCI device to disable
- intpci_set_cacheline_size(structpci_dev*dev)¶
ensure the CACHE_LINE_SIZE register is programmed
Parameters
structpci_dev*devthe PCI device for which MWI is to be enabled
Description
Helper function for pci_set_mwi.Originally copied from drivers/net/acenic.c.Copyright 1998-2001 by Jes Sorensen, <jes**trained**-monkey.org>.
Return
An appropriate -ERRNO error value on error, or zero for success.
- intpci_set_mwi(structpci_dev*dev)¶
enables memory-write-invalidate PCI transaction
Parameters
structpci_dev*devthe PCI device for which MWI is enabled
Description
Enables the Memory-Write-Invalidate transaction inPCI_COMMAND.
Return
An appropriate -ERRNO error value on error, or zero for success.
- intpci_try_set_mwi(structpci_dev*dev)¶
enables memory-write-invalidate PCI transaction
Parameters
structpci_dev*devthe PCI device for which MWI is enabled
Description
Enables the Memory-Write-Invalidate transaction inPCI_COMMAND.Callers are not required to check the return value.
Return
An appropriate -ERRNO error value on error, or zero for success.
- voidpci_clear_mwi(structpci_dev*dev)¶
disables Memory-Write-Invalidate for device dev
Parameters
structpci_dev*devthe PCI device to disable
Description
Disables PCI Memory-Write-Invalidate transaction on the device
- voidpci_intx(structpci_dev*pdev,intenable)¶
enables/disables PCI INTx for device dev
Parameters
structpci_dev*pdevthe PCI device to operate on
intenableboolean: whether to enable or disable PCI INTx
Description
Enables/disables PCI INTx for devicepdev
- intpci_wait_for_pending_transaction(structpci_dev*dev)¶
wait for pending transaction
Parameters
structpci_dev*devthe PCI device to operate on
Description
Return 0 if transaction is pending 1 otherwise.
- intpcie_flr(structpci_dev*dev)¶
initiate a PCIe function level reset
Parameters
structpci_dev*devdevice to reset
Description
Initiate a function level reset unconditionally ondev withoutchecking any flags and DEVCAP
- intpcie_reset_flr(structpci_dev*dev,boolprobe)¶
initiate a PCIe function level reset
Parameters
structpci_dev*devdevice to reset
boolprobeif true, return 0 if device can be reset this way
Description
Initiate a function level reset ondev.
- intpci_bridge_secondary_bus_reset(structpci_dev*dev)¶
Reset the secondary bus on a PCI bridge.
Parameters
structpci_dev*devBridge device
Description
Use the bridge control register to assert reset on the secondary bus.Devices on the secondary bus are left in power-on state.
- int__pci_reset_function_locked(structpci_dev*dev)¶
reset a PCI device function while holding thedev mutex lock.
Parameters
structpci_dev*devPCI device to reset
Description
Some devices allow an individual function to be reset without affectingother functions in the same device. The PCI device must be responsiveto PCI config space in order to use this function.
The device function is presumed to be unused and the caller is holdingthe device mutex lock when this function is called.
Resetting the device will make the contents of PCI configuration spacerandom, so any caller of this must be prepared to reinitialise thedevice including MSI, bus mastering, BARs, decoding IO and memory spaces,etc.
Returns 0 if the device function was successfully reset or negative if thedevice doesn’t support resetting a single function.
- intpci_reset_function(structpci_dev*dev)¶
quiesce and reset a PCI device function
Parameters
structpci_dev*devPCI device to reset
Description
Some devices allow an individual function to be reset without affectingother functions in the same device. The PCI device must be responsiveto PCI config space in order to use this function.
This function does not just reset the PCI portion of a device, butclears all the state associated with the device. This function differsfrom__pci_reset_function_locked() in that it saves and restores device stateover the reset and takes the PCI device lock.
Returns 0 if the device function was successfully reset or negative if thedevice doesn’t support resetting a single function.
- intpci_reset_function_locked(structpci_dev*dev)¶
quiesce and reset a PCI device function
Parameters
structpci_dev*devPCI device to reset
Description
Some devices allow an individual function to be reset without affectingother functions in the same device. The PCI device must be responsiveto PCI config space in order to use this function.
This function does not just reset the PCI portion of a device, butclears all the state associated with the device. This function differsfrom__pci_reset_function_locked() in that it saves and restores device stateover the reset. It also differs frompci_reset_function() in that itrequires the PCI device lock to be held.
Returns 0 if the device function was successfully reset or negative if thedevice doesn’t support resetting a single function.
- intpci_try_reset_function(structpci_dev*dev)¶
quiesce and reset a PCI device function
Parameters
structpci_dev*devPCI device to reset
Description
Same as above, except return -EAGAIN if unable to lock device.
- intpci_probe_reset_slot(structpci_slot*slot)¶
probe whether a PCI slot can be reset
Parameters
structpci_slot*slotPCI slot to probe
Description
Return 0 if slot can be reset, negative if a slot reset is not supported.
- intpci_probe_reset_bus(structpci_bus*bus)¶
probe whether a PCI bus can be reset
Parameters
structpci_bus*busPCI bus to probe
Description
Return 0 if bus can be reset, negative if a bus reset is not supported.
- intpci_reset_bus(structpci_dev*pdev)¶
Try to reset a PCI bus
Parameters
structpci_dev*pdevtop level PCI device to reset via slot/bus
Description
Same as above except return -EAGAIN if the bus cannot be locked
- intpcix_get_max_mmrbc(structpci_dev*dev)¶
get PCI-X maximum designed memory read byte count
Parameters
structpci_dev*devPCI device to query
Description
Returns mmrbc: maximum designed memory read count in bytes orappropriate error value.
- intpcix_get_mmrbc(structpci_dev*dev)¶
get PCI-X maximum memory read byte count
Parameters
structpci_dev*devPCI device to query
Description
Returns mmrbc: maximum memory read count in bytes or appropriate errorvalue.
- intpcix_set_mmrbc(structpci_dev*dev,intmmrbc)¶
set PCI-X maximum memory read byte count
Parameters
structpci_dev*devPCI device to query
intmmrbcmaximum memory read count in bytesvalid values are 512, 1024, 2048, 4096
Description
If possible sets maximum memory read byte count, some bridges have erratathat prevent this.
- intpcie_get_readrq(structpci_dev*dev)¶
get PCI Express read request size
Parameters
structpci_dev*devPCI device to query
Description
Returns maximum memory read request in bytes or appropriate error value.
- intpcie_set_readrq(structpci_dev*dev,intrq)¶
set PCI Express maximum memory read request
Parameters
structpci_dev*devPCI device to query
intrqmaximum memory read count in bytesvalid values are 128, 256, 512, 1024, 2048, 4096
Description
If possible sets maximum memory read request in bytes
- intpcie_get_mps(structpci_dev*dev)¶
get PCI Express maximum payload size
Parameters
structpci_dev*devPCI device to query
Description
Returns maximum payload size in bytes
- intpcie_set_mps(structpci_dev*dev,intmps)¶
set PCI Express maximum payload size
Parameters
structpci_dev*devPCI device to query
intmpsmaximum payload size in bytesvalid values are 128, 256, 512, 1024, 2048, 4096
Description
If possible sets maximum payload size
- u32pcie_bandwidth_available(structpci_dev*dev,structpci_dev**limiting_dev,enumpci_bus_speed*speed,enumpcie_link_width*width)¶
determine minimum link settings of a PCIe device and its bandwidth limitation
Parameters
structpci_dev*devPCI device to query
structpci_dev**limiting_devstorage for device causing the bandwidth limitation
enumpci_bus_speed*speedstorage for speed of limiting device
enumpcie_link_width*widthstorage for width of limiting device
Description
Walk up the PCI device chain and find the point where the minimumbandwidth is available. Return the bandwidth available there and (iflimiting_dev, speed, and width pointers are supplied) information aboutthat point. The bandwidth returned is in Mb/s, i.e., megabits/second ofraw bandwidth.
- enumpci_bus_speedpcie_get_speed_cap(structpci_dev*dev)¶
query for the PCI device’s link speed capability
Parameters
structpci_dev*devPCI device to query
Description
Query the PCI device speed capability.
Return
the maximum link speed supported by the device.
- enumpcie_link_widthpcie_get_width_cap(structpci_dev*dev)¶
query for the PCI device’s link width capability
Parameters
structpci_dev*devPCI device to query
Description
Query the PCI device width capability. Return the maximum link widthsupported by the device.
- voidpcie_print_link_status(structpci_dev*dev)¶
Report the PCI device’s link speed and width
Parameters
structpci_dev*devPCI device to query
Description
Report the available bandwidth at the device.
- intpci_select_bars(structpci_dev*dev,unsignedlongflags)¶
Make BAR mask from the type of resource
Parameters
structpci_dev*devthe PCI device for which BAR mask is made
unsignedlongflagsresource type mask to be selected
Description
This helper routine makes bar mask from the type of resource.
- intpci_bus_find_emul_domain_nr(u32hint,u32min,u32max)¶
allocate a PCI domain number per constraints
Parameters
u32hintdesired domain, 0 if any ID in the range ofmin tomax is acceptable
u32minminimum allowable domain
u32maxmaximum allowable domain, no IDs higher than INT_MAX will be returned
- void__iomem*pci_iomap_range(structpci_dev*dev,intbar,unsignedlongoffset,unsignedlongmaxlen)¶
create a virtual mapping cookie for a PCI BAR
Parameters
structpci_dev*devPCI device that owns the BAR
intbarBAR number
unsignedlongoffsetmap memory at the given offset in BAR
unsignedlongmaxlenmax length of the memory to map
Description
Using this function you will get a __iomem address to your device BAR.You can access it using ioread*() and iowrite*(). These functions hidethe details if this is a MMIO or PIO address space and will just do whatyou expect from them in the correct way.
maxlen specifies the maximum length to map. If you want to get access tothe complete BAR from offset to the end, pass0 here.
- void__iomem*pci_iomap_wc_range(structpci_dev*dev,intbar,unsignedlongoffset,unsignedlongmaxlen)¶
create a virtual WC mapping cookie for a PCI BAR
Parameters
structpci_dev*devPCI device that owns the BAR
intbarBAR number
unsignedlongoffsetmap memory at the given offset in BAR
unsignedlongmaxlenmax length of the memory to map
Description
Using this function you will get a __iomem address to your device BAR.You can access it using ioread*() and iowrite*(). These functions hidethe details if this is a MMIO or PIO address space and will just do whatyou expect from them in the correct way. When possible write combiningis used.
maxlen specifies the maximum length to map. If you want to get access tothe complete BAR from offset to the end, pass0 here.
- void__iomem*pci_iomap(structpci_dev*dev,intbar,unsignedlongmaxlen)¶
create a virtual mapping cookie for a PCI BAR
Parameters
structpci_dev*devPCI device that owns the BAR
intbarBAR number
unsignedlongmaxlenlength of the memory to map
Description
Using this function you will get a __iomem address to your device BAR.You can access it using ioread*() and iowrite*(). These functions hidethe details if this is a MMIO or PIO address space and will just do whatyou expect from them in the correct way.
maxlen specifies the maximum length to map. If you want to get access tothe complete BAR without checking for its length first, pass0 here.
- void__iomem*pci_iomap_wc(structpci_dev*dev,intbar,unsignedlongmaxlen)¶
create a virtual WC mapping cookie for a PCI BAR
Parameters
structpci_dev*devPCI device that owns the BAR
intbarBAR number
unsignedlongmaxlenlength of the memory to map
Description
Using this function you will get a __iomem address to your device BAR.You can access it using ioread*() and iowrite*(). These functions hidethe details if this is a MMIO or PIO address space and will just do whatyou expect from them in the correct way. When possible write combiningis used.
maxlen specifies the maximum length to map. If you want to get access tothe complete BAR without checking for its length first, pass0 here.
- intdevm_pci_remap_iospace(structdevice*dev,conststructresource*res,phys_addr_tphys_addr)¶
Managed
pci_remap_iospace()
Parameters
structdevice*devGeneric device to remap IO address for
conststructresource*resResource describing the I/O space
phys_addr_tphys_addrphysical address of range to be mapped
Description
Managedpci_remap_iospace(). Map is automatically unmapped on driverdetach.
- void__iomem*devm_pci_remap_cfgspace(structdevice*dev,resource_size_toffset,resource_size_tsize)¶
Managed
pci_remap_cfgspace()
Parameters
structdevice*devGeneric device to remap IO address for
resource_size_toffsetResource address to map
resource_size_tsizeSize of map
Description
Managedpci_remap_cfgspace(). Map is automatically unmapped on driverdetach.
- void__iomem*devm_pci_remap_cfg_resource(structdevice*dev,structresource*res)¶
check, request region and ioremap cfg resource
Parameters
structdevice*devgeneric device to handle the resource for
structresource*resconfiguration space resource to be handled
Description
Checks that a resource is a valid memory region, requests the memoryregion and ioremaps withpci_remap_cfgspace() API that ensures theproper PCI configuration space memory attributes are guaranteed.
All operations are managed and will be undone on driver detach.
Returns a pointer to the remapped memory or anIOMEM_ERR_PTR() encoded errorcode on failure. Usage example:
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);base = devm_pci_remap_cfg_resource(&pdev->dev, res);if (IS_ERR(base)) return PTR_ERR(base);
- intpcim_set_mwi(structpci_dev*pdev)¶
a device-managed
pci_set_mwi()
Parameters
structpci_dev*pdevthe PCI device for which MWI is enabled
Description
Managedpci_set_mwi().
Return
An appropriate -ERRNO error value on error, or zero for success.
- intpcim_intx(structpci_dev*pdev,intenable)¶
managed
pci_intx()
Parameters
structpci_dev*pdevthe PCI device to operate on
intenableboolean: whether to enable or disable PCI INTx
Return
0 on success, -ENOMEM on error.
Description
Enable/disable PCI INTx for devicepdev.Restore the original state on driver detach.
- intpcim_enable_device(structpci_dev*pdev)¶
Managed
pci_enable_device()
Parameters
structpci_dev*pdevPCI device to be initialized
Return
0 on success, negative error code on failure.
Description
Managedpci_enable_device(). Device will automatically be disabled ondriver detach.
- voidpcim_pin_device(structpci_dev*pdev)¶
Pin managed PCI device
Parameters
structpci_dev*pdevPCI device to pin
Description
Pin managed PCI devicepdev. Pinned device won’t be disabled on driverdetach.pdev must have been enabled withpcim_enable_device().
- void__iomem*const*pcim_iomap_table(structpci_dev*pdev)¶
access iomap allocation table (DEPRECATED)
Parameters
structpci_dev*pdevPCI device to access iomap table for
Return
Const pointer to array of __iomem pointers on success, NULL on failure.
Description
Access iomap allocation table fordev. If iomap table doesn’texist andpdev is managed, it will be allocated. All iomapsrecorded in the iomap table are automatically unmapped on driverdetach.
This function might sleep when the table is first allocated but canbe safely called without context and guaranteed to succeed onceallocated.
This function is DEPRECATED. Do not use it in new code. Instead, obtain amapping’s address directly from one of the pcim_* mapping functions. For
example
void __iomem *mappy = pcim_iomap(pdev, bar, length);
- void__iomem*pcim_iomap(structpci_dev*pdev,intbar,unsignedlongmaxlen)¶
Managed
pcim_iomap()
Parameters
structpci_dev*pdevPCI device to iomap for
intbarBAR to iomap
unsignedlongmaxlenMaximum length of iomap
Return
__iomem pointer on success, NULL on failure.
Description
Managedpci_iomap(). Map is automatically unmapped on driver detach. Ifdesired, unmap manually only withpcim_iounmap().
This SHOULD only be used once per BAR.
NOTE
Contrary to the other pcim_* functions, this function does not return anIOMEM_ERR_PTR() on failure, but a simple NULL. This is done for backwardscompatibility.
- voidpcim_iounmap(structpci_dev*pdev,void__iomem*addr)¶
Managed
pci_iounmap()
Parameters
structpci_dev*pdevPCI device to iounmap for
void__iomem*addrAddress to unmap
Description
Managedpci_iounmap().addr must have been mapped using a pcim_* mappingfunction.
- void__iomem*pcim_iomap_region(structpci_dev*pdev,intbar,constchar*name)¶
Request and iomap a PCI BAR
Parameters
structpci_dev*pdevPCI device to map IO resources for
intbarIndex of a BAR to map
constchar*nameName of the driver requesting the resource
Return
__iomem pointer on success, an IOMEM_ERR_PTR on failure.
Description
Mapping and region will get automatically released on driver detach. Ifdesired, release manually only withpcim_iounmap_region().
- voidpcim_iounmap_region(structpci_dev*pdev,intbar)¶
Unmap and release a PCI BAR
Parameters
structpci_dev*pdevPCI device to operate on
intbarIndex of BAR to unmap and release
Description
Unmap a BAR and release its region manually. Only pass BARs that werepreviously mapped bypcim_iomap_region().
- intpcim_iomap_regions(structpci_dev*pdev,intmask,constchar*name)¶
Request and iomap PCI BARs (DEPRECATED)
Parameters
structpci_dev*pdevPCI device to map IO resources for
intmaskMask of BARs to request and iomap
constchar*nameName of the driver requesting the resources
Return
0 on success, negative error code on failure.
Description
Request and iomap regions specified bymask.
This function is DEPRECATED. Do not use it in new code.Usepcim_iomap_region() instead.
- intpcim_request_region(structpci_dev*pdev,intbar,constchar*name)¶
Request a PCI BAR
Parameters
structpci_dev*pdevPCI device to request region for
intbarIndex of BAR to request
constchar*nameName of the driver requesting the resource
Return
0 on success, a negative error code on failure.
Description
Request region specified bybar.
The region will automatically be released on driver detach. If desired,release manually only withpcim_release_region().
- intpcim_request_all_regions(structpci_dev*pdev,constchar*name)¶
Request all regions
Parameters
structpci_dev*pdevPCI device to map IO resources for
constchar*namename of the driver requesting the resources
Return
0 on success, negative error code on failure.
Description
Requested regions will automatically be released at driver detach. Ifdesired, release individual regions withpcim_release_region() or all ofthem at once withpcim_release_all_regions().
- void__iomem*pcim_iomap_range(structpci_dev*pdev,intbar,unsignedlongoffset,unsignedlonglen)¶
Create a ranged __iomap mapping within a PCI BAR
Parameters
structpci_dev*pdevPCI device to map IO resources for
intbarIndex of the BAR
unsignedlongoffsetOffset from the begin of the BAR
unsignedlonglenLength in bytes for the mapping
Return
__iomem pointer on success, an IOMEM_ERR_PTR on failure.
Description
Creates a new IO-Mapping within the specifiedbar, ranging fromoffset tooffset +len.
The mapping will automatically get unmapped on driver detach. If desired,release manually only withpcim_iounmap().
- intpci_add_dynid(structpci_driver*drv,unsignedintvendor,unsignedintdevice,unsignedintsubvendor,unsignedintsubdevice,unsignedintclass,unsignedintclass_mask,unsignedlongdriver_data)¶
add a new PCI device ID to this driver and re-probe devices
Parameters
structpci_driver*drvtarget pci driver
unsignedintvendorPCI vendor ID
unsignedintdevicePCI device ID
unsignedintsubvendorPCI subvendor ID
unsignedintsubdevicePCI subdevice ID
unsignedintclassPCI class
unsignedintclass_maskPCI class mask
unsignedlongdriver_dataprivate driver data
Description
Adds a new dynamic pci device ID to this driver and causes thedriver to probe for all devices again.drv must have beenregistered prior to calling this function.
Context
Does GFP_KERNEL allocation.
Return
0 on success, -errno on failure.
- conststructpci_device_id*pci_match_id(conststructpci_device_id*ids,structpci_dev*dev)¶
See if a PCI device matches a given pci_id table
Parameters
conststructpci_device_id*idsarray of PCI device ID structures to search in
structpci_dev*devthe PCI device structure to match against.
Description
Used by a driver to check whether a PCI device is in its list ofsupported devices. Returns the matching pci_device_id structure orNULL if there is no match.
Deprecated; don’t use this as it will not catch any dynamic IDsthat a driver might want to check for.
- int__pci_register_driver(structpci_driver*drv,structmodule*owner,constchar*mod_name)¶
register a new pci driver
Parameters
structpci_driver*drvthe driver structure to register
structmodule*ownerowner module of drv
constchar*mod_namemodule name string
Description
Adds the driver structure to the list of registered drivers.Returns a negative value on error, otherwise 0.If no error occurred, the driver remains registered even ifno device was claimed during registration.
- voidpci_unregister_driver(structpci_driver*drv)¶
unregister a pci driver
Parameters
structpci_driver*drvthe driver structure to unregister
Description
Deletes the driver structure from the list of registered PCI drivers,gives it a chance to clean up by calling itsremove() function foreach device it was responsible for, and marks those devices asdriverless.
- structpci_driver*pci_dev_driver(conststructpci_dev*dev)¶
get the pci_driver of a device
Parameters
conststructpci_dev*devthe device to query
Description
Returns the appropriate pci_driver structure orNULL if there is noregistered driver for the device.
- structpci_dev*pci_dev_get(structpci_dev*dev)¶
increments the reference count of the pci device structure
Parameters
structpci_dev*devthe device being referenced
Description
Each live reference to a device should be refcounted.
Drivers for PCI devices should normally record such references intheirprobe() methods, when they bind to a device, and releasethem by callingpci_dev_put(), in theirdisconnect() methods.
A pointer to the device with the incremented reference counter is returned.
- voidpci_dev_put(structpci_dev*dev)¶
release a use of the pci device structure
Parameters
structpci_dev*devdevice that’s been disconnected
Description
Must be called when a user of a device is finished with it. When the lastuser of the device calls this function, the memory of the device is freed.
- voidpci_stop_and_remove_bus_device(structpci_dev*dev)¶
remove a PCI device and any children
Parameters
structpci_dev*devthe device to remove
Description
Remove a PCI device from the device lists, informing the driversthat the device has been removed. We also remove any subordinatebuses and children in a depth-first manner.
For each device we remove, delete the device structure from thedevice lists, remove the /proc entry, and notify userspace(/sbin/hotplug).
- structpci_bus*pci_find_bus(intdomain,intbusnr)¶
locate PCI bus from a given domain and bus number
Parameters
intdomainnumber of PCI domain to search
intbusnrnumber of desired PCI bus
Description
Given a PCI bus number and domain number, the desired PCI bus is locatedin the global list of PCI buses. If the bus is found, a pointer to itsdata structure is returned. If no bus is found,NULL is returned.
- structpci_bus*pci_find_next_bus(conststructpci_bus*from)¶
begin or continue searching for a PCI bus
Parameters
conststructpci_bus*fromPrevious PCI bus found, or
NULLfor new search.
Description
Iterates through the list of known PCI buses. A new search isinitiated by passingNULL as thefrom argument. Otherwise iffrom is notNULL, searches continue from next device on theglobal list.
- structpci_dev*pci_get_slot(structpci_bus*bus,unsignedintdevfn)¶
locate PCI device for a given PCI slot
Parameters
structpci_bus*busPCI bus on which desired PCI device resides
unsignedintdevfnencodes number of PCI slot in which the desired PCIdevice resides and the logical device number within that slotin case of multi-function devices.
Description
Given a PCI bus and slot/function number, the desired PCI deviceis located in the list of PCI devices.If the device is found, its reference count is increased and thisfunction returns a pointer to its data structure. The caller mustdecrement the reference count by callingpci_dev_put().If no device is found,NULL is returned.
- structpci_dev*pci_get_domain_bus_and_slot(intdomain,unsignedintbus,unsignedintdevfn)¶
locate PCI device for a given PCI domain (segment), bus, and slot
Parameters
intdomainPCI domain/segment on which the PCI device resides.
unsignedintbusPCI bus on which desired PCI device resides
unsignedintdevfnencodes number of PCI slot in which the desired PCI deviceresides and the logical device number within that slot in case ofmulti-function devices.
Description
Given a PCI domain, bus, and slot/function number, the desired PCIdevice is located in the list of PCI devices. If the device isfound, its reference count is increased and this function returns apointer to its data structure. The caller must decrement thereference count by callingpci_dev_put(). If no device is found,NULL is returned.
- structpci_dev*pci_get_subsys(unsignedintvendor,unsignedintdevice,unsignedintss_vendor,unsignedintss_device,structpci_dev*from)¶
begin or continue searching for a PCI device by vendor/subvendor/device/subdevice id
Parameters
unsignedintvendorPCI vendor id to match, or
PCI_ANY_IDto match all vendor idsunsignedintdevicePCI device id to match, or
PCI_ANY_IDto match all device idsunsignedintss_vendorPCI subsystem vendor id to match, or
PCI_ANY_IDto match all vendor idsunsignedintss_devicePCI subsystem device id to match, or
PCI_ANY_IDto match all device idsstructpci_dev*fromPrevious PCI device found in search, or
NULLfor new search.
Description
Iterates through the list of known PCI devices. If a PCI device is foundwith a matchingvendor,device,ss_vendor andss_device, a pointer to itsdevice structure is returned, and the reference count to the device isincremented. Otherwise,NULL is returned. A new search is initiated bypassingNULL as thefrom argument. Otherwise iffrom is notNULL,searches continue from next device on the global list.The reference count forfrom is always decremented if it is notNULL.
- structpci_dev*pci_get_device(unsignedintvendor,unsignedintdevice,structpci_dev*from)¶
begin or continue searching for a PCI device by vendor/device id
Parameters
unsignedintvendorPCI vendor id to match, or
PCI_ANY_IDto match all vendor idsunsignedintdevicePCI device id to match, or
PCI_ANY_IDto match all device idsstructpci_dev*fromPrevious PCI device found in search, or
NULLfor new search.
Description
Iterates through the list of known PCI devices. If a PCI device isfound with a matchingvendor anddevice, the reference count to thedevice is incremented and a pointer to its device structure is returned.Otherwise,NULL is returned. A new search is initiated by passingNULLas thefrom argument. Otherwise iffrom is notNULL, searches continuefrom next device on the global list. The reference count forfrom isalways decremented if it is notNULL.
- structpci_dev*pci_get_class(unsignedintclass,structpci_dev*from)¶
begin or continue searching for a PCI device by class
Parameters
unsignedintclasssearch for a PCI device with this class designation
structpci_dev*fromPrevious PCI device found in search, or
NULLfor new search.
Description
Iterates through the list of known PCI devices. If a PCI device isfound with a matchingclass, the reference count to the device isincremented and a pointer to its device structure is returned.Otherwise,NULL is returned.A new search is initiated by passingNULL as thefrom argument.Otherwise iffrom is notNULL, searches continue from next deviceon the global list. The reference count forfrom is always decrementedif it is notNULL.
- structpci_dev*pci_get_base_class(unsignedintclass,structpci_dev*from)¶
searching for a PCI device by matching against the base class code only
Parameters
unsignedintclasssearch for a PCI device with this base class code
structpci_dev*fromPrevious PCI device found in search, or
NULLfor new search.
Description
Iterates through the list of known PCI devices. If a PCI device is foundwith a matching base class code, the reference count to the device isincremented. Seepci_match_one_device() to figure out how does this works.A new search is initiated by passingNULL as thefrom argument.Otherwise iffrom is notNULL, searches continue from next device on theglobal list. The reference count forfrom is always decremented if it isnotNULL.
Return
A pointer to a matched PCI device,NULL Otherwise.
- intpci_dev_present(conststructpci_device_id*ids)¶
Returns 1 if device matching the device list is present, 0 if not.
Parameters
conststructpci_device_id*idsA pointer to a null terminated list of
structpci_device_idstructuresthat describe the type of PCI device the caller is trying to find.
Description
Obvious fact: You do not have a reference to any device that might be foundby this function, so if that device is removed from the system right afterthis function is finished, the value will be stale. Use this function tofind devices that are usually built into a system, or for a general hint asto if another device happens to be present at this specific moment in time.
Parameters
structirq_data*datapointer to irqdata associated to that interrupt
Parameters
structirq_data*datapointer to irqdata associated to that interrupt
- intpci_msi_vec_count(structpci_dev*dev)¶
Return the number of MSI vectors a device can send
Parameters
structpci_dev*devdevice to report about
Description
This function returns the number of MSI vectors a device requested viaMultiple Message Capable register. It returns a negative errno if thedevice is not capable sending MSI interrupts. Otherwise, the call succeedsand returns a power of two, up to a maximum of 2^5 (32), according to theMSI specification.
- intpci_bus_alloc_resource(structpci_bus*bus,structresource*res,resource_size_tsize,resource_size_talign,resource_size_tmin,unsignedlongtype_mask,resource_alignfalignf,void*alignf_data)¶
allocate a resource from a parent bus
Parameters
structpci_bus*busPCI bus
structresource*resresource to allocate
resource_size_tsizesize of resource to allocate
resource_size_talignalignment of resource to allocate
resource_size_tminminimum /proc/iomem address to allocate
unsignedlongtype_maskIORESOURCE_* type flags
resource_alignfalignfresource alignment function
void*alignf_datadata argument for resource alignment function
Description
Given the PCI bus a device resides on, the size, minimum address,alignment and type, try to find an acceptable resource allocationfor a specific device resource.
- voidpci_bus_add_device(structpci_dev*dev)¶
start driver for a single device
Parameters
structpci_dev*devdevice to add
Description
This adds add sysfs entries and start device drivers
- voidpci_bus_add_devices(conststructpci_bus*bus)¶
start driver for PCI devices
Parameters
conststructpci_bus*busbus to check for new devices
Description
Start driver for PCI devices and add some sysfs entries.
- voidpci_walk_bus(structpci_bus*top,int(*cb)(structpci_dev*,void*),void*userdata)¶
walk devices on/under bus, calling callback.
Parameters
structpci_bus*topbus whose devices should be walked
int(*cb)(structpci_dev*,void*)callback to be called for each device found
void*userdataarbitrary pointer to be passed to callback
Description
Walk the given bus, including any bridged deviceson buses under this bus. Call the provided callbackon each device found.
We check the return ofcb each time. If it returns anythingother than 0, we break out.
- voidpci_walk_bus_reverse(structpci_bus*top,int(*cb)(structpci_dev*,void*),void*userdata)¶
walk devices on/under bus, calling callback.
Parameters
structpci_bus*topbus whose devices should be walked
int(*cb)(structpci_dev*,void*)callback to be called for each device found
void*userdataarbitrary pointer to be passed to callback
Description
Same semantics aspci_walk_bus(), but walks the bus in reverse order.
- structpci_ops*pci_bus_set_ops(structpci_bus*bus,structpci_ops*ops)¶
Set raw operations of pci bus
Parameters
structpci_bus*buspci bus struct
structpci_ops*opsnew raw operations
Description
Return previous raw operations
- voidpci_cfg_access_lock(structpci_dev*dev)¶
Lock PCI config reads/writes
Parameters
structpci_dev*devpci device struct
Description
When access is locked, any userspace reads or writes to configspace and concurrent lock requests will sleep until access isallowed viapci_cfg_access_unlock() again.
- boolpci_cfg_access_trylock(structpci_dev*dev)¶
try to lock PCI config reads/writes
Parameters
structpci_dev*devpci device struct
Description
Same as pci_cfg_access_lock, but will return 0 if access isalready locked, 1 otherwise. This function can be used fromatomic contexts.
- voidpci_cfg_access_unlock(structpci_dev*dev)¶
Unlock PCI config reads/writes
Parameters
structpci_dev*devpci device struct
Description
This function allows PCI config accesses to resume.
- intpci_request_irq(structpci_dev*dev,unsignedintnr,irq_handler_thandler,irq_handler_tthread_fn,void*dev_id,constchar*fmt,...)¶
allocate an interrupt line for a PCI device
Parameters
structpci_dev*devPCI device to operate on
unsignedintnrdevice-relative interrupt vector index (0-based).
irq_handler_thandlerFunction to be called when the IRQ occurs.Primary handler for threaded interrupts.If NULL and thread_fn != NULL the default primary handler isinstalled.
irq_handler_tthread_fnFunction called from the IRQ handler threadIf NULL, no IRQ thread is created
void*dev_idCookie passed back to the handler function
constchar*fmtPrintf-like format string naming the handler
...variable arguments
Description
This call allocates interrupt resources and enables the interrupt line andIRQ handling. From the point this call is madehandler andthread_fn maybe invoked. All interrupts requested using this function might be shared.
dev_id must not be NULL and must be globally unique.
- voidpci_free_irq(structpci_dev*dev,unsignedintnr,void*dev_id)¶
free an interrupt allocated with pci_request_irq
Parameters
structpci_dev*devPCI device to operate on
unsignedintnrdevice-relative interrupt vector index (0-based).
void*dev_idDevice identity to free
Description
Remove an interrupt handler. The handler is removed and if the interruptline is no longer in use by any driver it is disabled. The caller mustensure the interrupt is disabled on the device before calling this function.The function does not return until any executing interrupts for this IRQhave completed.
This function must not be called from interrupt context.
- u8pci_common_swizzle(structpci_dev*dev,u8*pinp)¶
swizzle INTx all the way to root bridge
Parameters
structpci_dev*devthe PCI device
u8*pinppointer to the INTx pin value (1=INTA, 2=INTB, 3=INTD, 4=INTD)
Description
Perform INTx swizzling for a device. This traverses through all PCI-to-PCIbridges all the way up to a PCI root bus.
- boolpci_check_and_mask_intx(structpci_dev*dev)¶
mask INTx on pending interrupt
Parameters
structpci_dev*devthe PCI device to operate on
Description
Check if the device dev has its INTx line asserted, mask it and returntrue in that case. False is returned if no interrupt was pending.
- boolpci_check_and_unmask_intx(structpci_dev*dev)¶
unmask INTx if no interrupt is pending
Parameters
structpci_dev*devthe PCI device to operate on
Description
Check if the device dev has its INTx line asserted, unmask it if not andreturn true. False is returned and the mask remains active if there wasstill an interrupt pending.
- boolpcie_relaxed_ordering_enabled(structpci_dev*dev)¶
Probe for PCIe relaxed ordering enable
Parameters
structpci_dev*devPCI device to query
Description
Returns true if the device has enabled relaxed ordering attribute.
- intpci_scan_slot(structpci_bus*bus,intdevfn)¶
Scan a PCI slot on a bus for devices
Parameters
structpci_bus*busPCI bus to scan
intdevfnslot number to scan (must have zero function)
Description
Scan a PCI slot on the specified PCI bus for devices, addingdiscovered devices to thebus->devices list. New deviceswill not have is_added set.
Returns the number of new devices found.
- unsignedintpci_scan_child_bus(structpci_bus*bus)¶
Scan devices below a bus
Parameters
structpci_bus*busBus to scan for devices
Description
Scans devices belowbus including subordinate buses. Returns newsubordinate number including all the found devices.
- unsignedintpci_rescan_bus(structpci_bus*bus)¶
Scan a PCI bus for devices
Parameters
structpci_bus*busPCI bus to scan
Description
Scan a PCI bus and child buses for new devices, add them,and enable them.
Returns the max number of subordinate bus discovered.
- structpci_slot*pci_create_slot(structpci_bus*parent,intslot_nr,constchar*name,structhotplug_slot*hotplug)¶
create or increment refcount for physical PCI slot
Parameters
structpci_bus*parentstructpci_busof parent bridgeintslot_nrPCI_SLOT(pci_dev->devfn) or -1 for placeholder
constchar*nameuser visible string presented in /sys/bus/pci/slots/<name>
structhotplug_slot*hotplugset if caller is hotplug driver, NULL otherwise
Description
PCI slots have first class attributes such as address, speed, width,and astructpci_slot is used to manage them. This interface willeither return a newstructpci_slot to the caller, or if the pci_slotalready exists, its refcount will be incremented.
Slots are uniquely identified by apci_bus,slot_nr tuple.
There are known platforms with broken firmware that assign the samename to multiple slots. Workaround these broken platforms by renamingthe slots on behalf of the caller. If firmware assigns name N tomultiple slots:
The first slot is assigned NThe second slot is assigned N-1The third slot is assigned N-2etc.
Placeholder slots:In most cases,pci_bus,slot_nr will be sufficient to uniquely identifya slot. There is one notable exception - pSeries (rpaphp), where theslot_nr cannot be determined until a device is actually inserted intothe slot. In this scenario, the caller may pass -1 forslot_nr.
The following semantics are imposed when the caller passesslot_nr ==-1. First, we no longer check for an existingstruct pci_slot, as theremay be many slots withslot_nr of -1. The other change in semantics isuser-visible, which is the ‘address’ parameter presented in sysfs willconsist solely of a dddd:bb tuple, where dddd is the PCI domain of thestruct pci_bus and bb is the bus number. In other words, the devfn ofthe ‘placeholder’ slot will not be displayed.
- voidpci_destroy_slot(structpci_slot*slot)¶
decrement refcount for physical PCI slot
Parameters
structpci_slot*slotstructpci_slotto decrement
Description
struct pci_slot is refcounted, so destroying them is really easy; wejust call kobject_put on its kobj and let our release methods do therest.
- intpci_rebar_bytes_to_size(u64bytes)¶
Convert size in bytes to PCI BAR Size
Parameters
u64bytessize in bytes
Description
Convert size in bytes to encoded BAR Size in Resizable BAR Capability(PCIe r6.2, sec. 7.8.6.3).
Return
encoded BAR Size as defined in the PCIe spec (0=1MB, 31=128TB)
- resource_size_tpci_rebar_size_to_bytes(intsize)¶
Convert encoded BAR Size to size in bytes
Parameters
intsizeencoded BAR Size as defined in the PCIe spec (0=1MB, 31=128TB)
Return
BAR size in bytes
- u64pci_rebar_get_possible_sizes(structpci_dev*pdev,intbar)¶
get possible sizes for Resizable BAR
Parameters
structpci_dev*pdevPCI device
intbarBAR to query
Description
Get the possible sizes of a resizable BAR as bitmask.
Return
A bitmask of possible sizes (bit 0=1MB, bit 31=128TB), or0 ifBAR isn’t resizable.
- boolpci_rebar_size_supported(structpci_dev*pdev,intbar,intsize)¶
check if size is supported for BAR
Parameters
structpci_dev*pdevPCI device
intbarBAR to check
intsizeencoded size as defined in the PCIe spec (0=1MB, 31=128TB)
Return
true ifbar is resizable andsize is supported, otherwisefalse.
- intpci_rebar_get_max_size(structpci_dev*pdev,intbar)¶
get the maximum supported size of a BAR
Parameters
structpci_dev*pdevPCI device
intbarBAR to query
Description
Get the largest supported size of a resizable BAR as a size.
Return
the encoded maximum BAR size as defined in the PCIe spec(0=1MB, 31=128TB), or-NOENT on error.
- intpci_resize_resource(structpci_dev*dev,intresno,intsize,intexclude_bars)¶
reconfigure a Resizable BAR and resources
Parameters
structpci_dev*devthe PCI device
intresnoindex of the BAR to be resized
intsizenew size as defined in the spec (0=1MB, 31=128TB)
intexclude_barsa mask of BARs that should not be released
Description
Reconfigureresno tosize and re-run resource assignment algorithmwith the new size.
Prior to resize, releasedev resources that share a bridge window withresno. This unpins the bridge window resource to allow changing it.
The caller may prevent releasing a particular BAR by providingexclude_bars mask, but this may result in the resize operation failingdue to insufficient space.
Return
0 on success, or negative on error. In case of an error, theresources are restored to their original places.
- intpci_enable_rom(structpci_dev*pdev)¶
enable ROM decoding for a PCI device
Parameters
structpci_dev*pdevPCI device to enable
Description
Enable ROM decoding ondev. This involves simply turning on the lastbit of the PCI ROM BAR. Note that some cards may share address decodersbetween the ROM and other resources, so enabling it may disable accessto MMIO registers or other card memory.
- voidpci_disable_rom(structpci_dev*pdev)¶
disable ROM decoding for a PCI device
Parameters
structpci_dev*pdevPCI device to disable
Description
Disable ROM decoding on a PCI device by turning off the last bit in theROM BAR.
- void__iomem*pci_map_rom(structpci_dev*pdev,size_t*size)¶
map a PCI ROM to kernel space
Parameters
structpci_dev*pdevpointer to pci device struct
size_t*sizepointer to receive size of pci window over ROM
Return
kernel virtual pointer to image of ROM
Description
Map a PCI ROM into kernel space. If ROM is boot video ROM,the shadow BIOS copy will be returned instead of theactual ROM.
- voidpci_unmap_rom(structpci_dev*pdev,void__iomem*rom)¶
unmap the ROM from kernel space
Parameters
structpci_dev*pdevpointer to pci device struct
void__iomem*romvirtual address of the previous mapping
Description
Remove a mapping of a previously mapped ROM
- void*pci_iov_get_pf_drvdata(structpci_dev*dev,structpci_driver*pf_driver)¶
Return the drvdata of a PF
Parameters
structpci_dev*devVF pci_dev
structpci_driver*pf_driverDevice driver required to own the PF
Description
This must be called from a context that ensures that a VF driver is attached.The value returned is invalid once the VF driver completes itsremove()callback.
Locking is achieved by the driver core. A VF driver cannot be probed untilpci_enable_sriov() is called andpci_disable_sriov() does not return untilall VF drivers have completed theirremove().
The PF driver must callpci_disable_sriov() before it begins to destroy thedrvdata.
- intpci_enable_sriov(structpci_dev*dev,intnr_virtfn)¶
enable the SR-IOV capability
Parameters
structpci_dev*devthe PCI device
intnr_virtfnnumber of virtual functions to enable
Description
Returns 0 on success, or negative on failure.
- voidpci_disable_sriov(structpci_dev*dev)¶
disable the SR-IOV capability
Parameters
structpci_dev*devthe PCI device
- intpci_num_vf(structpci_dev*dev)¶
return number of VFs associated with a PF device_release_driver
Parameters
structpci_dev*devthe PCI device
Description
Returns number of VFs, or 0 if SR-IOV is not enabled.
- intpci_vfs_assigned(structpci_dev*dev)¶
returns number of VFs are assigned to a guest
Parameters
structpci_dev*devthe PCI device
Description
Returns number of VFs belonging to this device that are assigned to a guest.If device is not a physical function returns 0.
- intpci_sriov_set_totalvfs(structpci_dev*dev,u16numvfs)¶
reduce the TotalVFs available
Parameters
structpci_dev*devthe PCI PF device
u16numvfsnumber that should be used for TotalVFs supported
Description
Should be called from PF driver’s probe routine withdevice’s mutex held.
Returns 0 if PF is an SRIOV-capable device andvalue of numvfs valid. If not a PF return -ENOSYS;if numvfs is invalid return -EINVAL;if VFs already enabled, return -EBUSY.
- intpci_sriov_get_totalvfs(structpci_dev*dev)¶
get total VFs supported on this device
Parameters
structpci_dev*devthe PCI PF device
Description
For a PCIe device with SRIOV support, return the PCIeSRIOV capability value of TotalVFs or the value of driver_max_VFsif the driver reduced it. Otherwise 0.
- intpci_sriov_configure_simple(structpci_dev*dev,intnr_virtfn)¶
helper to configure SR-IOV
Parameters
structpci_dev*devthe PCI device
intnr_virtfnnumber of virtual functions to enable, 0 to disable
Description
Enable or disable SR-IOV for devices that don’t require any PF setupbefore enabling SR-IOV. Return value is negative on error, or number ofVFs allocated on success.
- intpci_iov_vf_bar_set_size(structpci_dev*dev,intresno,intsize)¶
set a new size for a VF BAR
Parameters
structpci_dev*devthe PCI device
intresnothe resource number
intsizenew size as defined in the spec (0=1MB, 31=128TB)
Description
Set the new size of a VF BAR that supports VF resizable BAR capability.Unlikepci_resize_resource(), this does not cause the resource thatreserves the MMIO space (originally up to total_VFs) to be resized, whichmeans that following calls topci_enable_sriov() can fail if the resourcesno longer fit.
Return
0 on success, or negative on failure.
- u32pci_iov_vf_bar_get_sizes(structpci_dev*dev,intresno,intnum_vfs)¶
get VF BAR sizes allowing to create up to num_vfs
Parameters
structpci_dev*devthe PCI device
intresnothe resource number
intnum_vfsnumber of VFs
Description
Get the sizes of a VF resizable BAR that can accommodatenum_vfs withinthe currently assigned size of the resourceresno.
Return
A bitmask of sizes in format defined in the spec (bit 0=1MB,bit 31=128TB).
- ssize_tpci_read_legacy_io(structfile*filp,structkobject*kobj,conststructbin_attribute*bin_attr,char*buf,loff_toff,size_tcount)¶
read byte(s) from legacy I/O port space
Parameters
structfile*filpopen sysfs file
structkobject*kobjkobject corresponding to file to read from
conststructbin_attribute*bin_attrstructbin_attributefor this filechar*bufbuffer to store results
loff_toffoffset into legacy I/O port space
size_tcountnumber of bytes to read
Description
Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specificcallback routine (pci_legacy_read).
- ssize_tpci_write_legacy_io(structfile*filp,structkobject*kobj,conststructbin_attribute*bin_attr,char*buf,loff_toff,size_tcount)¶
write byte(s) to legacy I/O port space
Parameters
structfile*filpopen sysfs file
structkobject*kobjkobject corresponding to file to read from
conststructbin_attribute*bin_attrstructbin_attributefor this filechar*bufbuffer containing value to be written
loff_toffoffset into legacy I/O port space
size_tcountnumber of bytes to write
Description
Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specificcallback routine (pci_legacy_write).
- intpci_mmap_legacy_mem(structfile*filp,structkobject*kobj,conststructbin_attribute*attr,structvm_area_struct*vma)¶
map legacy PCI memory into user memory space
Parameters
structfile*filpopen sysfs file
structkobject*kobjkobject corresponding to device to be mapped
conststructbin_attribute*attrstructbin_attributefor this filestructvm_area_struct*vmastructvm_area_structpassed to mmap
Description
Uses an arch specific callback, pci_mmap_legacy_mem_page_range, to mmaplegacy memory space (first meg of bus space) into application virtualmemory space.
- intpci_mmap_legacy_io(structfile*filp,structkobject*kobj,conststructbin_attribute*attr,structvm_area_struct*vma)¶
map legacy PCI IO into user memory space
Parameters
structfile*filpopen sysfs file
structkobject*kobjkobject corresponding to device to be mapped
conststructbin_attribute*attrstructbin_attributefor this filestructvm_area_struct*vmastructvm_area_structpassed to mmap
Description
Uses an arch specific callback, pci_mmap_legacy_io_page_range, to mmaplegacy IO space (first meg of bus space) into application virtualmemory space. Returns -ENOSYS if the operation isn’t supported
- voidpci_adjust_legacy_attr(structpci_bus*b,enumpci_mmap_statemmap_type)¶
adjustment of legacy file attributes
Parameters
structpci_bus*bbus to create files under
enumpci_mmap_statemmap_typeI/O port or memory
Description
Stub implementation. Can be overridden by arch if necessary.
- voidpci_create_legacy_files(structpci_bus*b)¶
create legacy I/O port and memory files
Parameters
structpci_bus*bbus to create files under
Description
Some platforms allow access to legacy I/O port and ISA memory space ona per-bus basis. This routine creates the files and ties them intotheir associated read, write and mmap files from pci-sysfs.c
On error unwind, but don’t propagate the error to the calleras it is ok to set up the PCI bus without these files.
- intpci_mmap_resource(structkobject*kobj,conststructbin_attribute*attr,structvm_area_struct*vma,intwrite_combine)¶
map a PCI resource into user memory space
Parameters
structkobject*kobjkobject for mapping
conststructbin_attribute*attrstructbin_attributefor the file being mappedstructvm_area_struct*vmastructvm_area_structpassed into the mmapintwrite_combine1 for write_combine mapping
Description
Use the regular PCI mapping routines to map a PCI resource into userspace.
- voidpci_remove_resource_files(structpci_dev*pdev)¶
cleanup resource files
Parameters
structpci_dev*pdevdev to cleanup
Description
If we created resource files forpdev, remove them from sysfs andfree their resources.
- intpci_create_resource_files(structpci_dev*pdev)¶
create resource files in sysfs fordev
Parameters
structpci_dev*pdevdev in question
Description
Walk the resources inpdev creating files for each resource available.
- ssize_tpci_write_rom(structfile*filp,structkobject*kobj,conststructbin_attribute*bin_attr,char*buf,loff_toff,size_tcount)¶
used to enable access to the PCI ROM display
Parameters
structfile*filpsysfs file
structkobject*kobjkernel object handle
conststructbin_attribute*bin_attrstructbin_attributefor this filechar*bufuser input
loff_tofffile offset
size_tcountnumber of byte in input
Description
writing anything except 0 enables it
- ssize_tpci_read_rom(structfile*filp,structkobject*kobj,conststructbin_attribute*bin_attr,char*buf,loff_toff,size_tcount)¶
read a PCI ROM
Parameters
structfile*filpsysfs file
structkobject*kobjkernel object handle
conststructbin_attribute*bin_attrstructbin_attributefor this filechar*bufwhere to put the data we read from the ROM
loff_tofffile offset
size_tcountnumber of bytes to read
Description
Putcount bytes starting atoff intobuf from the ROM in the PCIdevice corresponding tokobj.
- voidpci_remove_sysfs_dev_files(structpci_dev*pdev)¶
cleanup PCI specific sysfs files
Parameters
structpci_dev*pdevdevice whose entries we should free
Description
Cleanup whenpdev is removed from sysfs.
- u32pcie_tph_get_st_table_loc(structpci_dev*pdev)¶
Return the device’s ST table location
Parameters
structpci_dev*pdevPCI device to query
Return
PCI_TPH_LOC_NONE - Not presentPCI_TPH_LOC_CAP - Located in the TPH Requester Extended CapabilityPCI_TPH_LOC_MSIX - Located in the MSI-X Table
- intpcie_tph_get_cpu_st(structpci_dev*pdev,enumtph_mem_typemem_type,unsignedintcpu_uid,u16*tag)¶
Retrieve Steering Tag for a target memory associated with a specific CPU
Parameters
structpci_dev*pdevPCI device
enumtph_mem_typemem_typetarget memory type (volatile or persistent RAM)
unsignedintcpu_uidassociated CPU id
u16*tagSteering Tag to be returned
Description
Return the Steering Tag for a target memory that is associated with aspecific CPU as indicated by cpu_uid.
Return
0 if success, otherwise negative value (-errno)
- intpcie_tph_set_st_entry(structpci_dev*pdev,unsignedintindex,u16tag)¶
Set Steering Tag in the ST table entry
Parameters
structpci_dev*pdevPCI device
unsignedintindexST table entry index
u16tagSteering Tag to be written
Description
Figure out the proper location of ST table, either in the MSI-X table orin the TPH Extended Capability space, and write the Steering Tag intothe ST entry pointed by index.
Return
0 if success, otherwise negative value (-errno)
- voidpcie_disable_tph(structpci_dev*pdev)¶
Turn off TPH support for device
Parameters
structpci_dev*pdevPCI device
Return
none
- intpcie_enable_tph(structpci_dev*pdev,intmode)¶
Enable TPH support for device using a specific ST mode
Parameters
structpci_dev*pdevPCI device
intmodeST mode to enable. Current supported modes include:
Description
PCI_TPH_ST_NS_MODE: NO ST Mode
PCI_TPH_ST_IV_MODE: Interrupt Vector Mode
PCI_TPH_ST_DS_MODE: Device Specific Mode
Check whether the mode is actually supported by the device before enablingand return an error if not. Additionally determine what types of requests,TPH or extended TPH, can be issued by the device based on its TPH requestercapability and the Root Port’s completer capability.
Return
0 on success, otherwise negative value (-errno)
PCI Hotplug Support Library¶
- int__pci_hp_register(structhotplug_slot*slot,structpci_bus*bus,intdevnr,constchar*name,structmodule*owner,constchar*mod_name)¶
register a hotplug_slot with the PCI hotplug subsystem
Parameters
structhotplug_slot*slotpointer to the
structhotplug_slotto registerstructpci_bus*busbus this slot is on
intdevnrdevice number
constchar*namename registered with kobject core
structmodule*ownercaller module owner
constchar*mod_namecaller module name
Description
Prepares a hotplug slot for in-kernel use and immediately publishes it touser space in one go. Drivers may alternatively carry out the two stepsseparately by invokingpci_hp_initialize() andpci_hp_add().
Returns 0 if successful, anything else for an error.
- int__pci_hp_initialize(structhotplug_slot*slot,structpci_bus*bus,intdevnr,constchar*name,structmodule*owner,constchar*mod_name)¶
prepare hotplug slot for in-kernel use
Parameters
structhotplug_slot*slotpointer to the
structhotplug_slotto initializestructpci_bus*busbus this slot is on
intdevnrslot number
constchar*namename registered with kobject core
structmodule*ownercaller module owner
constchar*mod_namecaller module name
Description
Allocate and fill in a PCI slot for use by a hotplug driver. Once this hasbeen called, the driver may invokehotplug_slot_name() to get the slot’sunique name. The driver must be prepared to handle a ->reset_slot callbackfrom this point on.
Returns 0 on success or a negative int on error.
- intpci_hp_add(structhotplug_slot*slot)¶
publish hotplug slot to user space
Parameters
structhotplug_slot*slotpointer to the
structhotplug_slotto publish
Description
Make a hotplug slot’s sysfs interface available and inform user space of itsaddition by sending a uevent. The hotplug driver must be prepared to handleallstructhotplug_slot_ops callbacks from this point on.
Returns 0 on success or a negative int on error.
- voidpci_hp_deregister(structhotplug_slot*slot)¶
deregister a hotplug_slot with the PCI hotplug subsystem
Parameters
structhotplug_slot*slotpointer to the
structhotplug_slotto deregister
Description
Theslot must have been registered with the pci hotplug subsystempreviously with a call topci_hp_register().
- voidpci_hp_del(structhotplug_slot*slot)¶
unpublish hotplug slot from user space
Parameters
structhotplug_slot*slotpointer to the
structhotplug_slotto unpublish
Description
Remove a hotplug slot’s sysfs interface.
- voidpci_hp_destroy(structhotplug_slot*slot)¶
remove hotplug slot from in-kernel use
Parameters
structhotplug_slot*slotpointer to the
structhotplug_slotto destroy
Description
Destroy a PCI slot used by a hotplug driver. Once this has been called,the driver may no longer invokehotplug_slot_name() to get the slot’sunique name. The driver no longer needs to handle a ->reset_slot callbackfrom this point on.