PCI
Single-page view · as markdown
The Linux PCI driver implementer's API guide
Peios Kernel / Hardware and drivers / Driver development / PCI
Table of contents
PCI Peer-to-Peer DMA Support
Peios Kernel / Hardware and drivers / Driver development / PCI
The PCI bus has pretty decent support for performing DMA transfers between two devices on the bus. This type of transaction is henceforth called Peer-to-Peer (or P2P). However, there are a number of issues that make P2P transactions tricky to do in a perfectly safe way.
For PCIe the routing of Transaction Layer Packets (TLPs) is well-defined up until they reach a host bridge or root port. If the path includes PCIe switches then based on the ACS settings the transaction can route entirely within the PCIe hierarchy and never reach the root port. The kernel will evaluate the PCIe topology and always permit P2P in these well-defined cases.
However, if the P2P transaction reaches the host bridge then it might have to hairpin back out the same root port, be routed inside the CPU SOC to another PCIe root port, or routed internally to the SOC.
The PCIe specification doesn't define the forwarding of transactions between hierarchy domains and kernel defaults to blocking such routing. There is an allow list to allow detecting known-good HW, in which case P2P between any two PCIe devices will be permitted.
Since P2P inherently is doing transactions between two devices it requires two drivers to be co-operating inside the kernel. The providing driver has to convey its MMIO to the consuming driver. To meet the driver model lifecycle rules the MMIO must have all DMA mapping removed, all CPU accesses prevented, all page table mappings undone before the providing driver completes remove().
This requires the providing and consuming driver to actively work together to guarantee that the consuming driver has stopped using the MMIO during a removal cycle. This is done by either a synchronous invalidation shutdown or waiting for all usage refcounts to reach zero.
At the lowest level the P2P subsystem offers a naked struct p2p_provider that delegates lifecycle management to the providing driver. It is expected that drivers using this option will wrap their MMIO memory in DMABUF and use DMABUF to provide an invalidation shutdown. These MMIO addresess have no struct page, and if used with mmap() must create special PTEs. As such there are very few kernel uAPIs that can accept pointers to them; in particular they cannot be used with read()/write(), including O_DIRECT.
Building on this, the subsystem offers a layer to wrap the MMIO in a ZONE_DEVICE pgmap of MEMORY_DEVICE_PCI_P2PDMA to create struct pages. The lifecycle of pgmap ensures that when the pgmap is destroyed all other drivers have stopped using the MMIO. This option works with O_DIRECT flows, in some cases, if the underlying subsystem supports handling MEMORY_DEVICE_PCI_P2PDMA through FOLL_PCI_P2PDMA. The use of FOLL_LONGTERM is prevented. As this relies on pgmap it also relies on architecture support along with alignment and minimum size limitations.
Driver Writer's Guide #
In a given P2P implementation there may be three or more different types of kernel drivers in play:
-
Provider - A driver which provides or publishes P2P resources like memory or doorbell registers to other drivers.
-
Client - A driver which makes use of a resource by setting up a DMA transaction to or from it.
-
Orchestrator - A driver which orchestrates the flow of data between clients and providers.
In many cases there could be overlap between these three types (i.e., it may be typical for a driver to be both a provider and a client).
For example, in the NVMe Target Copy Offload implementation:
-
The NVMe PCI driver is both a client, provider and orchestrator in that it exposes any CMB (Controller Memory Buffer) as a P2P memory resource (provider), it accepts P2P memory pages as buffers in requests to be used directly (client) and it can also make use of the CMB as submission queue entries (orchestrator).
-
The RDMA driver is a client in this arrangement so that an RNIC can DMA directly to the memory exposed by the NVMe device.
-
The NVMe Target driver (nvmet) can orchestrate the data from the RNIC to the P2P memory (CMB) and then to the NVMe device (and vice versa).
This is currently the only arrangement supported by the kernel but one could imagine slight tweaks to this that would allow for the same functionality. For example, if a specific RNIC added a BAR with some memory behind it, its driver could add support as a P2P provider and then the NVMe Target could use the RNIC's memory instead of the CMB in cases where the NVMe cards in use do not have CMB support.
Provider Drivers #
A provider simply needs to register a BAR (or a portion of a BAR) as a P2P DMA resource using pci_p2pdma_add_resource(). This will register struct pages for all the specified memory.
After that it may optionally publish all of its resources as P2P memory using pci_p2pmem_publish(). This will allow any orchestrator drivers to find and use the memory. When marked in this way, the resource must be regular memory with no side effects.
For the time being this is fairly rudimentary in that all resources are typically going to be P2P memory. Future work will likely expand this to include other types of resources like doorbells.
Client Drivers #
A client driver only has to use the mapping API dma_map_sg() and dma_unmap_sg() functions as usual, and the implementation will do the right thing for the P2P capable memory.
Orchestrator Drivers #
The first task an orchestrator driver must do is compile a list of all client devices that will be involved in a given transaction. For example, the NVMe Target driver creates a list including the namespace block device and the RNIC in use. If the orchestrator has access to a specific P2P provider to use it may check compatibility using pci_p2pdma_distance() otherwise it may find a memory provider that's compatible with all clients using pci_p2pmem_find(). If more than one provider is supported, the one nearest to all the clients will be chosen first. If more than one provider is an equal distance away, the one returned will be chosen at random (it is not an arbitrary but truly random). This function returns the PCI device to use for the provider with a reference taken and therefore when it's no longer needed it should be returned with pci_dev_put().
Once a provider is selected, the orchestrator can then use pci_alloc_p2pmem() and pci_free_p2pmem() to allocate P2P memory from the provider. pci_p2pmem_alloc_sgl() and pci_p2pmem_free_sgl() are convenience functions for allocating scatter-gather lists with P2P memory.
Struct Page Caveats #
While the MEMORY_DEVICE_PCI_P2PDMA pages can be installed in VMAs, pin_user_pages() and related will not return them unless FOLL_PCI_P2PDMA is set.
The MEMORY_DEVICE_PCI_P2PDMA pages require care to support in the kernel. The KVA is still MMIO and must still be accessed through the normal readX()/writeX()/etc helpers. Direct CPU access (e.g. memcpy) is forbidden, just like any other MMIO mapping. While this will actually work on some architectures, others will experience corruption or just crash in the kernel. Supporting FOLL_PCI_P2PDMA in a subsystem requires scrubbing it to ensure no CPU access happens.
Usage With DMABUF #
DMABUF provides an alternative to the above struct page-based client/provider/orchestrator system and should be used when struct page doesn't exist. In this mode the exporting driver will wrap some of its MMIO in a DMABUF and give the DMABUF FD to userspace.
Userspace can then pass the FD to an importing driver which will ask the exporting driver to map it to the importer.
In this case the initiator and target pci_devices are known and the P2P subsystem is used to determine the mapping type. The phys_addr_t-based DMA API is used to establish the dma_addr_t.
Lifecycle is controlled by DMABUF move_notify(). When the exporting driver wants to remove() it must deliver an invalidation shutdown to all DMABUF importing drivers through move_notify() and synchronously DMA unmap all the MMIO.
No importing driver can continue to have a DMA map to the MMIO after the exporting driver has destroyed its p2p_provider.
P2P DMA Support Library #
pcim_p2pdma_init() #
int Initialise peer-to-peer DMA providers
Parameters
struct pci_dev *pdev: The PCI device to enable P2PDMA for
Description
This function initializes the peer-to-peer DMA infrastructure for a PCI device. It allocates and sets up the necessary data structures to support P2PDMA operations, including mapping type tracking.
pcim_p2pdma_provider() #
struct p2pdma_provider * Get peer-to-peer DMA provider
Parameters
struct pci_dev *pdev: The PCI device to enable P2PDMA forint bar: BAR index to get provider
Description
This function gets peer-to-peer DMA provider for a PCI device. The lifetime
of the provider (and of course the MMIO) is bound to the lifetime of the
driver. A driver calling this function must ensure that all references to the
provider, and any DMA mappings created for any MMIO, are all cleaned up
before the driver remove() completes.
Since P2P is almost always shared with a second driver this means some system to notify, invalidate and revoke the MMIO's DMA must be in place to use this function. For example a revoke can be built using DMABUF.
pci_p2pdma_add_resource() #
int add memory for use as p2p memory
Parameters
struct pci_dev *pdev: the device to add the memory toint bar: PCI BAR to addsize_t size: size of the memory to add, may be zero to use the whole BARu64 offset: offset into the PCI BAR
Description
The memory will be given ZONE_DEVICE struct pages so that it may be used with any DMA request.
pci_p2pdma_distance_many() #
int Determine the cumulative distance between a p2pdma provider and the clients in use.
Parameters
struct pci_dev *provider: p2pdma provider to check against the client liststruct device **clients: array of devices to check (NULL-terminated)int num_clients: number of clients in the arraybool verbose: if true, print warnings for devices when we return -1
Description
Returns -1 if any of the clients are not compatible, otherwise returns a positive number where a lower number is the preferable choice. (If there's one client that's the same as the provider it will return 0, which is best choice).
"compatible" means the provider and the clients are either all behind the same PCI root port or the host bridges connected to each of the devices are listed in the 'pci_p2pdma_whitelist'.
pci_p2pmem_find_many() #
struct pci_dev * find a peer-to-peer DMA memory device compatible with the specified list of clients and shortest distance
Parameters
struct device **clients: array of devices to check (NULL-terminated)int num_clients: number of client devices in the list
Description
If multiple devices are behind the same switch, the one "closest" to the client devices in use will be chosen first. (So if one of the providers is the same as one of the clients, that provider will be used ahead of any other providers that are unrelated). If multiple providers are an equal distance away, one will be chosen at random.
Returns a pointer to the PCI device with a reference taken (use pci_dev_put to return the reference) or NULL if no compatible device is found. The found provider will also be assigned to the client list.
pci_alloc_p2pmem() #
void * allocate peer-to-peer DMA memory
Parameters
struct pci_dev *pdev: the device to allocate memory fromsize_t size: number of bytes to allocate
Description
Returns the allocated memory or NULL on error.
pci_free_p2pmem() #
void free peer-to-peer DMA memory
Parameters
struct pci_dev *pdev: the device the memory was allocated fromvoid *addr: address of the memory that was allocatedsize_t size: number of bytes that were allocated
pci_p2pmem_virt_to_bus() #
pci_bus_addr_t return the PCI bus address for a given virtual address obtained with pci_alloc_p2pmem()
Parameters
struct pci_dev *pdev: the device the memory was allocated fromvoid *addr: address of the memory that was allocated
pci_p2pmem_alloc_sgl() #
struct scatterlist * allocate peer-to-peer DMA memory in a scatterlist
Parameters
struct pci_dev *pdev: the device to allocate memory fromunsigned int *nents: the number of SG entries in the listu32 length: number of bytes to allocate
Return
NULL on error or struct scatterlist pointer and nents on success
pci_p2pmem_free_sgl() #
void free a scatterlist allocated by pci_p2pmem_alloc_sgl()
Parameters
struct pci_dev *pdev: the device to allocate memory fromstruct scatterlist *sgl: the allocated scatterlist
pci_p2pmem_publish() #
void publish the peer-to-peer DMA memory for use by other devices with pci_p2pmem_find()
Parameters
struct pci_dev *pdev: the device with peer-to-peer DMA memory to publishbool publish: set to true to publish the memory, false to unpublish it
Description
Published memory can be used by other PCI device drivers for peer-2-peer DMA operations. Non-published memory is reserved for exclusive use of the device driver that registers the peer-to-peer memory.
pci_p2pdma_enable_store() #
int parse a configfs/sysfs attribute store to enable p2pdma
Parameters
const char *page: contents of the value to be storedstruct pci_dev **p2p_dev: returns the PCI device that was selected to be used (if one was specified in the stored value)bool *use_p2pdma: returns whether to enable p2pdma or not
Description
Parses an attribute value to decide whether to enable p2pdma.
The value can select a PCI device (using its full BDF device
name) or a boolean (in any format kstrtobool() accepts). A false
value disables p2pdma, a true value expects the caller
to automatically find a compatible device and specifying a PCI device
expects the caller to use the specific provider.
pci_p2pdma_enable_show() should be used as the show operation for
the attribute.
Returns 0 on success
pci_p2pdma_enable_show() #
ssize_t show a configfs/sysfs attribute indicating whether p2pdma is enabled
Parameters
char *page: contents of the stored valuestruct pci_dev *p2p_dev: the selected p2p device (NULL if no device is selected)bool use_p2pdma: whether p2pdma has been enabled
Description
Attributes that use pci_p2pdma_enable_store() should use this function
to show the value of the attribute.
Returns 0 on success
PCI Support Library
Peios Kernel / Hardware and drivers / Driver development / PCI
PCI Support Library #
pci_bus_max_busnr() #
unsigned char returns maximum PCI bus number of given bus' children
Parameters
struct pci_bus *bus: pointer to PCI bus structure to search
Description
Given a PCI bus, returns the highest PCI bus number present in the set including the given PCI bus and its list of child PCI buses.
pci_status_get_and_clear_errors() #
int return and clear error bits in PCI_STATUS
Parameters
struct pci_dev *pdev: the PCI device
Description
Returns error bits set in PCI_STATUS and clears them.
pci_find_capability() #
u8 query for devices' capabilities
Parameters
struct pci_dev *dev: PCI device to queryint cap: capability code
Description
Tell if a device supports a given PCI capability. Returns the address of the requested capability structure within the device's PCI configuration space or 0 in case the device does not support it. Possible values for cap include:
PCI_CAP_ID_PM Power Management
PCI_CAP_ID_AGP Accelerated Graphics Port
PCI_CAP_ID_VPD Vital Product Data
PCI_CAP_ID_SLOTID Slot Identification
PCI_CAP_ID_MSI Message Signalled Interrupts
PCI_CAP_ID_CHSWP CompactPCI HotSwap
PCI_CAP_ID_PCIX PCI-X
PCI_CAP_ID_EXP PCI Express
pci_bus_find_capability() #
u8 query for devices' capabilities
Parameters
struct pci_bus *bus: the PCI bus to queryunsigned int devfn: PCI device to queryint cap: capability code
Description
Like pci_find_capability() but works for PCI devices that do not have a
pci_dev structure set up yet.
Returns the address of the requested capability structure within the device's PCI configuration space or 0 in case the device does not support it.
pci_find_next_ext_capability() #
u16 Find an extended capability
Parameters
struct pci_dev *dev: PCI device to queryu16 start: address at which to start looking (0 to start at beginning of list)int cap: capability code
Description
Returns the address of the next matching extended capability structure within the device's PCI configuration space or 0 if the device does not support it. Some capabilities can occur several times, e.g., the vendor-specific capability, and this provides a way to find them all.
pci_find_ext_capability() #
u16 Find an extended capability
Parameters
struct pci_dev *dev: PCI device to queryint cap: capability code
Description
Returns the address of the requested extended capability structure within the device's PCI configuration space or 0 if the device does not support it. Possible values for cap include:
PCI_EXT_CAP_ID_ERR Advanced Error Reporting
PCI_EXT_CAP_ID_VC Virtual Channel
PCI_EXT_CAP_ID_DSN Device Serial Number
PCI_EXT_CAP_ID_PWR Power Budgeting
pci_get_dsn() #
u64 Read and return the 8-byte Device Serial Number
Parameters
struct pci_dev *dev: PCI device to query
Description
Looks up the PCI_EXT_CAP_ID_DSN and reads the 8 bytes of the Device Serial Number.
Returns the DSN, or zero if the capability does not exist.
pci_find_next_ht_capability() #
u8 query a device's HyperTransport capabilities
Parameters
struct pci_dev *dev: PCI device to queryu8 pos: Position from which to continue searchingint ht_cap: HyperTransport capability code
Description
To be used in conjunction with pci_find_ht_capability() to search for
all capabilities matching ht_cap. pos should always be a value returned
from pci_find_ht_capability().
NB. To be 100% safe against broken PCI devices, the caller should take steps to avoid an infinite loop.
pci_find_ht_capability() #
u8 query a device's HyperTransport capabilities
Parameters
struct pci_dev *dev: PCI device to queryint ht_cap: HyperTransport capability code
Description
Tell if a device supports a given HyperTransport capability. Returns an address within the device's PCI configuration space or 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 matching ht_cap.
pci_find_vsec_capability() #
u16 Find a vendor-specific extended capability
Parameters
struct pci_dev *dev: PCI device to queryu16 vendor: Vendor ID for which capability is definedint cap: Vendor-specific capability ID
Description
If dev has Vendor ID vendor, search for a VSEC capability with VSEC ID cap. If found, return the capability offset in config space; otherwise return 0.
pci_find_dvsec_capability() #
u16 Find DVSEC for vendor
Parameters
struct pci_dev *dev: PCI device to queryu16 vendor: Vendor ID to match for the DVSECu16 dvsec: Designated Vendor-specific capability ID
Description
If DVSEC has Vendor ID vendor and DVSEC ID dvsec return the capability offset in config space; otherwise return 0.
pci_find_parent_resource() #
struct resource * return resource region of parent bus of given region
Parameters
const struct pci_dev *dev: PCI device structure contains resources to be searchedstruct resource *res: child resource record for which parent is sought
Description
For given resource region of given device, return the resource region of parent bus the given region is contained in.
pci_find_resource() #
struct resource * Return matching PCI device resource
Parameters
struct pci_dev *dev: PCI device to querystruct resource *res: Resource to look for
Description
Goes over standard PCI resources (BARs) and checks if the given resource
is partially or fully contained in any of them. In that case the
matching resource is returned, NULL otherwise.
pci_platform_power_transition() #
int Use platform to change device power state
Parameters
struct pci_dev *dev: PCI device to handle.pci_power_t state: State to put the device into.
pci_set_power_state() #
int Set the power state of a PCI device
Parameters
struct pci_dev *dev: PCI device to handle.pci_power_t state: PCI 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/or the 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 a wrong 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.
pci_save_state() #
int save the PCI configuration space of a device before suspending
Parameters
struct pci_dev *dev: PCI device that we're dealing with
pci_restore_state() #
void Restore the saved state of a PCI device
Parameters
struct pci_dev *dev: PCI device that we're dealing with
pci_store_saved_state() #
struct pci_saved_state * Allocate and return an opaque struct containing the device saved state.
Parameters
struct pci_dev *dev: PCI device that we're dealing with
Description
Return NULL if no state or error.
pci_load_saved_state() #
int Reload the provided save state into struct pci_dev.
Parameters
struct pci_dev *dev: PCI device that we're dealing withstruct pci_saved_state *state: Saved state returned frompci_store_saved_state()
pci_load_and_free_saved_state() #
int Reload the save state pointed to by state, and free the memory allocated for it.
Parameters
struct pci_dev *dev: PCI device that we're dealing withstruct pci_saved_state **state: Pointer to saved state returned frompci_store_saved_state()
pci_reenable_device() #
int Resume abandoned device
Parameters
struct pci_dev *dev: PCI device to be resumed
NOTE
This function is a backend of pci_default_resume() and is not supposed
to be called by normal code, write proper resume handler and use it instead.
pci_enable_device_mem() #
int Initialize a device for use with Memory space
Parameters
struct pci_dev *dev: PCI device to be initialized
Description
Initialize device before it's used by a driver. Ask low-level code to enable Memory resources. Wake up the device if it was suspended. Beware, this function can fail.
pci_enable_device() #
int Initialize device before it's used by a driver.
Parameters
struct pci_dev *dev: PCI device to be initialized
Description
Initialize device before it's used by a driver. Ask low-level code to 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 call this function repeatedly (we just increment the count).
pci_disable_device() #
void Disable PCI device after use
Parameters
struct pci_dev *dev: PCI device to be disabled
Description
Signal to the system that the PCI device is not in use by the system anymore. This only involves disabling PCI bus-mastering, if active.
Note we don't actually disable the device until all callers of
pci_enable_device() have called pci_disable_device().
pci_set_pcie_reset_state() #
int set reset state for device dev
Parameters
struct pci_dev *dev: the PCIe device resetenum pcie_reset_state state: Reset state to enter into
Description
Sets the PCI reset state for the device.
pci_pme_capable() #
bool check the capability of PCI device to generate PME#
Parameters
struct pci_dev *dev: PCI device to handle.pci_power_t state: PCI state from which device will issue PME#.
pci_pme_active() #
void enable or disable PCI device's PME# function
Parameters
struct pci_dev *dev: PCI device to handle.bool enable: 'true' to enable PME# generation; 'false' to disable it.
Description
The caller must verify that the device is capable of generating PME# before calling this function with enable equal to 'true'.
pci_enable_wake() #
int change wakeup settings for a PCI device
Parameters
struct pci_dev *pci_dev: Target devicepci_power_t state: PCI state from which device will issue wakeup eventsbool enable: Whether or not to enable event generation
Description
If enable is set, check device_may_wakeup() for the device before calling
__pci_enable_wake() for it.
pci_wake_from_d3() #
int enable/disable device to wake up from D3_hot or D3_cold
Parameters
struct pci_dev *dev: PCI device to preparebool enable: True 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_cold
and 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 ACPI
ordering constraints.
This function only returns error code if the device is not allowed to wake up the system from sleep or it is not capable of generating PME# from both D3_hot and D3_cold and the platform is unable to enable wake-up power for it.
pci_prepare_to_sleep() #
int prepare PCI device for system-wide transition into a sleep state
Parameters
struct pci_dev *dev: Device to handle.
Description
Choose the power state appropriate for the device depending on whether it 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.
pci_back_from_sleep() #
int turn PCI device on during system-wide transition into working state
Parameters
struct pci_dev *dev: Device to handle.
Description
Disable device's system wake-up capability and put it into D0.
pci_dev_run_wake() #
bool Check if device can generate run-time wake-up events.
Parameters
struct pci_dev *dev: Device 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 supports PME and one of its upstream bridges can generate wake-up events.
pci_choose_state() #
pci_power_t Choose the power state of a PCI device.
Parameters
struct pci_dev *dev: Target PCI device.pm_message_t state: Target state for the whole system.
Description
Returns PCI power state suitable for dev and state.
pci_d3cold_enable() #
void Enable D3cold for device
Parameters
struct pci_dev *dev: PCI device to handle
Description
This function can be used in drivers to enable D3cold from the device they handle. It also updates upstream PCI bridge PM capabilities accordingly.
pci_d3cold_disable() #
void Disable D3cold for device
Parameters
struct pci_dev *dev: PCI device to handle
Description
This function can be used in drivers to disable D3cold from the device they handle. It also updates upstream PCI bridge PM capabilities accordingly.
pci_enable_atomic_ops_to_root() #
int enable AtomicOp requests to root port
Parameters
struct pci_dev *dev: the PCI deviceu32 cap_mask: mask of desired AtomicOp sizes, including one or more of: PCI_EXP_DEVCAP2_ATOMIC_COMP32 PCI_EXP_DEVCAP2_ATOMIC_COMP64 PCI_EXP_DEVCAP2_ATOMIC_COMP128
Description
Return 0 if all upstream bridges support AtomicOp routing, egress blocking is disabled on all upstream ports, and the root port supports the requested completion capabilities (32-bit, 64-bit and/or 128-bit AtomicOp completion), or negative otherwise.
pci_release_region() #
void Release a PCI bar
Parameters
struct pci_dev *pdev: PCI device whose resources were previously reserved bypci_request_region()int bar: BAR to release
Description
Releases the PCI I/O and memory resources previously reserved by a
successful call to pci_request_region(). Call this function only
after all use of the PCI regions has ceased.
pci_request_region() #
int Reserve PCI I/O and memory resource
Parameters
struct pci_dev *pdev: PCI device whose resources are to be reservedint bar: BAR to be reservedconst char *name: name of the driver requesting the resource
Return
0 on success, negative error code on failure.
Description
Mark the PCI region associated with PCI device pdev BAR bar as being reserved by owner name. Do not access any address inside the PCI regions unless this call returns successfully.
Returns 0 on success, or EBUSY on error. A warning
message is also printed on failure.
pci_release_selected_regions() #
void Release selected PCI I/O and memory resources
Parameters
struct pci_dev *pdev: PCI device whose resources were previously reservedint bars: Bitmask 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.
pci_request_selected_regions() #
int Reserve selected PCI I/O and memory resources
Parameters
struct pci_dev *pdev: PCI device whose resources are to be reservedint bars: Bitmask of BARs to be requestedconst char *name: Name of the driver requesting the resources
Return
0 on success, negative error code on failure.
pci_request_selected_regions_exclusive() #
int Request regions exclusively
Parameters
struct pci_dev *pdev: PCI device to request regions fromint bars: bit mask of BARs to requestconst char *name: name of the driver requesting the resources
Return
0 on success, negative error code on failure.
pci_release_regions() #
void Release reserved PCI I/O and memory resources
Parameters
struct pci_dev *pdev: PCI device whose resources were previously reserved bypci_request_regions()
Description
Releases all PCI I/O and memory resources previously reserved by a
successful call to pci_request_regions(). Call this function only
after all use of the PCI regions has ceased.
pci_request_regions() #
int Reserve PCI I/O and memory resources
Parameters
struct pci_dev *pdev: PCI device whose resources are to be reservedconst char *name: name of the driver requesting the resources
Description
Mark all PCI regions associated with PCI device pdev as being reserved by owner name. Do not access any address inside the PCI regions unless this call returns successfully.
Returns 0 on success, or EBUSY on error. A warning
message is also printed on failure.
pci_request_regions_exclusive() #
int Reserve PCI I/O and memory resources
Parameters
struct pci_dev *pdev: PCI device whose resources are to be reservedconst char *name: name of the driver requesting the resources
Return
0 on success, negative error code on failure.
Description
Mark all PCI regions associated with PCI device pdev as being reserved by owner name. Do not access any address inside the PCI regions unless this call returns successfully.
pci_request_regions_exclusive() will mark the region so that /dev/mem
and the sysfs MMIO access will not be allowed.
Returns 0 on success, or EBUSY on error. A warning message is also
printed on failure.
pci_remap_iospace() #
int Remap the memory mapped I/O space
Parameters
const struct resource *res: Resource describing the I/O spacephys_addr_t phys_addr: physical address of range to be mapped
Description
Remap the memory mapped I/O space described by the res and the CPU physical address phys_addr into virtual address space. Only architectures that have memory mapped IO functions defined (and the PCI_IOBASE value defined) should call this function.
pci_unmap_iospace() #
void Unmap the memory mapped I/O space
Parameters
struct resource *res: resource to be unmapped
Description
Unmap the CPU virtual address res from virtual address space. Only architectures that have memory mapped IO functions defined (and the PCI_IOBASE value defined) should call this function.
pci_set_master() #
void enables bus-mastering for device dev
Parameters
struct pci_dev *dev: the PCI device to enable
Description
Enables bus-mastering on the device and calls pcibios_set_master()
to do the needed arch specific settings.
pci_clear_master() #
void disables bus-mastering for device dev
Parameters
struct pci_dev *dev: the PCI device to disable
pci_set_cacheline_size() #
int ensure the CACHE_LINE_SIZE register is programmed
Parameters
struct pci_dev *dev: the 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.
pci_set_mwi() #
int enables memory-write-invalidate PCI transaction
Parameters
struct pci_dev *dev: the PCI device for which MWI is enabled
Description
Enables the Memory-Write-Invalidate transaction in PCI_COMMAND.
Return
An appropriate -ERRNO error value on error, or zero for success.
pci_try_set_mwi() #
int enables memory-write-invalidate PCI transaction
Parameters
struct pci_dev *dev: the PCI device for which MWI is enabled
Description
Enables the Memory-Write-Invalidate transaction in PCI_COMMAND.
Callers are not required to check the return value.
Return
An appropriate -ERRNO error value on error, or zero for success.
pci_clear_mwi() #
void disables Memory-Write-Invalidate for device dev
Parameters
struct pci_dev *dev: the PCI device to disable
Description
Disables PCI Memory-Write-Invalidate transaction on the device
pci_intx() #
void enables/disables PCI INTx for device dev
Parameters
struct pci_dev *pdev: the PCI device to operate onint enable: boolean: whether to enable or disable PCI INTx
Description
Enables/disables PCI INTx for device pdev
pci_wait_for_pending_transaction() #
int wait for pending transaction
Parameters
struct pci_dev *dev: the PCI device to operate on
Description
Return 0 if transaction is pending 1 otherwise.
pcie_flr() #
int initiate a PCIe function level reset
Parameters
struct pci_dev *dev: device to reset
Description
Initiate a function level reset unconditionally on dev without checking any flags and DEVCAP
pcie_reset_flr() #
int initiate a PCIe function level reset
Parameters
struct pci_dev *dev: device to resetbool probe: if true, return 0 if device can be reset this way
Description
Initiate a function level reset on dev.
pci_bridge_secondary_bus_reset() #
int Reset the secondary bus on a PCI bridge.
Parameters
struct pci_dev *dev: Bridge 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.
__pci_reset_function_locked() #
int reset a PCI device function while holding the dev mutex lock.
Parameters
struct pci_dev *dev: PCI device to reset
Description
Some devices allow an individual function to be reset without affecting other functions in the same device. The PCI device must be responsive to PCI config space in order to use this function.
The device function is presumed to be unused and the caller is holding the device mutex lock when this function is called.
Resetting the device will make the contents of PCI configuration space random, so any caller of this must be prepared to reinitialise the device including MSI, bus mastering, BARs, decoding IO and memory spaces, etc.
Context
The caller must hold the device lock.
Return
0 if the device function was successfully reset or negative if the device doesn't support resetting a single function.
pci_reset_function() #
int quiesce and reset a PCI device function
Parameters
struct pci_dev *dev: PCI device to reset
Description
Some devices allow an individual function to be reset without affecting other functions in the same device. The PCI device must be responsive to PCI config space in order to use this function.
This function does not just reset the PCI portion of a device, but
clears all the state associated with the device. This function differs
from __pci_reset_function_locked() in that it saves and restores device state
over the reset and takes the PCI device lock.
Returns 0 if the device function was successfully reset or negative if the device doesn't support resetting a single function.
pci_reset_function_locked() #
int quiesce and reset a PCI device function
Parameters
struct pci_dev *dev: PCI device to reset
Description
Some devices allow an individual function to be reset without affecting other functions in the same device. The PCI device must be responsive to PCI config space in order to use this function.
This function does not just reset the PCI portion of a device, but
clears all the state associated with the device. This function differs
from __pci_reset_function_locked() in that it saves and restores device state
over the reset. It also differs from pci_reset_function() in that it
requires the PCI device lock to be held.
Context
The caller must hold the device lock.
Return
0 if the device function was successfully reset or negative if the device doesn't support resetting a single function.
pci_try_reset_function() #
int quiesce and reset a PCI device function
Parameters
struct pci_dev *dev: PCI device to reset
Description
Same as above, except return -EAGAIN if unable to lock device.
pci_probe_reset_slot() #
int probe whether a PCI slot can be reset
Parameters
struct pci_slot *slot: PCI slot to probe
Description
Return 0 if slot can be reset, negative if a slot reset is not supported.
pci_probe_reset_bus() #
int probe whether a PCI bus can be reset
Parameters
struct pci_bus *bus: PCI bus to probe
Description
Return 0 if bus can be reset, negative if a bus reset is not supported.
pci_reset_bus() #
int Try to reset a PCI bus
Parameters
struct pci_dev *pdev: top level PCI device to reset via slot/bus
Description
Same as above except return -EAGAIN if the bus cannot be locked
pcix_get_max_mmrbc() #
int get PCI-X maximum designed memory read byte count
Parameters
struct pci_dev *dev: PCI device to query
Description
Returns mmrbc: maximum designed memory read count in bytes or appropriate error value.
pcix_get_mmrbc() #
int get PCI-X maximum memory read byte count
Parameters
struct pci_dev *dev: PCI device to query
Description
Returns mmrbc: maximum memory read count in bytes or appropriate error value.
pcix_set_mmrbc() #
int set PCI-X maximum memory read byte count
Parameters
struct pci_dev *dev: PCI device to queryint mmrbc: maximum memory read count in bytes valid values are 512, 1024, 2048, 4096
Description
If possible sets maximum memory read byte count, some bridges have errata that prevent this.
pcie_get_readrq() #
int get PCI Express read request size
Parameters
struct pci_dev *dev: PCI device to query
Description
Returns maximum memory read request in bytes or appropriate error value.
pcie_set_readrq() #
int set PCI Express maximum memory read request
Parameters
struct pci_dev *dev: PCI device to queryint rq: maximum memory read count in bytes valid values are 128, 256, 512, 1024, 2048, 4096
Description
If possible sets maximum memory read request in bytes
pcie_get_mps() #
int get PCI Express maximum payload size
Parameters
struct pci_dev *dev: PCI device to query
Description
Returns maximum payload size in bytes
pcie_set_mps() #
int set PCI Express maximum payload size
Parameters
struct pci_dev *dev: PCI device to queryint mps: maximum payload size in bytes valid values are 128, 256, 512, 1024, 2048, 4096
Description
If possible sets maximum payload size
pcie_bandwidth_available() #
u32 determine minimum link settings of a PCIe device and its bandwidth limitation
Parameters
struct pci_dev *dev: PCI device to querystruct pci_dev **limiting_dev: storage for device causing the bandwidth limitationenum pci_bus_speed *speed: storage for speed of limiting deviceenum pcie_link_width *width: storage for width of limiting device
Description
Walk up the PCI device chain and find the point where the minimum bandwidth is available. Return the bandwidth available there and (if limiting_dev, speed, and width pointers are supplied) information about that point. The bandwidth returned is in Mb/s, i.e., megabits/second of raw bandwidth.
pcie_get_speed_cap() #
enum pci_bus_speed query for the PCI device's link speed capability
Parameters
struct pci_dev *dev: PCI device to query
Description
Query the PCI device speed capability.
Return
the maximum link speed supported by the device.
pcie_get_width_cap() #
enum pcie_link_width query for the PCI device's link width capability
Parameters
struct pci_dev *dev: PCI device to query
Description
Query the PCI device width capability. Return the maximum link width supported by the device.
pcie_print_link_status() #
void Report the PCI device's link speed and width
Parameters
struct pci_dev *dev: PCI device to query
Description
Report the available bandwidth at the device.
pci_select_bars() #
int Make BAR mask from the type of resource
Parameters
struct pci_dev *dev: the PCI device for which BAR mask is madeunsigned long flags: resource type mask to be selected
Description
This helper routine makes bar mask from the type of resource.
pci_bus_find_emul_domain_nr() #
int allocate a PCI domain number per constraints
Parameters
u32 hint: desired domain, 0 if any ID in the range of min to max is acceptableu32 min: minimum allowable domainu32 max: maximum allowable domain, no IDs higher than INT_MAX will be returned
pci_iomap_range() #
void __iomem * create a virtual mapping cookie for a PCI BAR
Parameters
struct pci_dev *dev: PCI device that owns the BARint bar: BAR numberunsigned long offset: map memory at the given offset in BARunsigned long maxlen: max 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 hide the details if this is a MMIO or PIO address space and will just do what you expect from them in the correct way.
maxlen specifies the maximum length to map. If you want to get access to
the complete BAR from offset to the end, pass 0 here.
pci_iomap_wc_range() #
void __iomem * create a virtual WC mapping cookie for a PCI BAR
Parameters
struct pci_dev *dev: PCI device that owns the BARint bar: BAR numberunsigned long offset: map memory at the given offset in BARunsigned long maxlen: max 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 hide the details if this is a MMIO or PIO address space and will just do what you expect from them in the correct way. When possible write combining is used.
maxlen specifies the maximum length to map. If you want to get access to
the complete BAR from offset to the end, pass 0 here.
pci_iomap() #
void __iomem * create a virtual mapping cookie for a PCI BAR
Parameters
struct pci_dev *dev: PCI device that owns the BARint bar: BAR numberunsigned long maxlen: 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 hide the details if this is a MMIO or PIO address space and will just do what you expect from them in the correct way.
maxlen specifies the maximum length to map. If you want to get access to
the complete BAR without checking for its length first, pass 0 here.
pci_iomap_wc() #
void __iomem * create a virtual WC mapping cookie for a PCI BAR
Parameters
struct pci_dev *dev: PCI device that owns the BARint bar: BAR numberunsigned long maxlen: 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 hide the details if this is a MMIO or PIO address space and will just do what you expect from them in the correct way. When possible write combining is used.
maxlen specifies the maximum length to map. If you want to get access to
the complete BAR without checking for its length first, pass 0 here.
devm_pci_remap_iospace() #
int Managed pci_remap_iospace()
Parameters
struct device *dev: Generic device to remap IO address forconst struct resource *res: Resource describing the I/O spacephys_addr_t phys_addr: physical address of range to be mapped
Description
Managed pci_remap_iospace(). Map is automatically unmapped on driver
detach.
devm_pci_remap_cfgspace() #
void __iomem * Managed pci_remap_cfgspace()
Parameters
struct device *dev: Generic device to remap IO address forresource_size_t offset: Resource address to mapresource_size_t size: Size of map
Description
Managed pci_remap_cfgspace(). Map is automatically unmapped on driver
detach.
devm_pci_remap_cfg_resource() #
void __iomem * check, request region and ioremap cfg resource
Parameters
struct device *dev: generic device to handle the resource forstruct resource *res: configuration space resource to be handled
Description
Checks that a resource is a valid memory region, requests the memory
region and ioremaps with pci_remap_cfgspace() API that ensures the
proper 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 an IOMEM_ERR_PTR() encoded error
code 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);
pcim_set_mwi() #
int a device-managed pci_set_mwi()
Parameters
struct pci_dev *pdev: the PCI device for which MWI is enabled
Description
Managed pci_set_mwi().
Return
An appropriate -ERRNO error value on error, or zero for success.
pcim_intx() #
int managed pci_intx()
Parameters
struct pci_dev *pdev: the PCI device to operate onint enable: boolean: whether to enable or disable PCI INTx
Return
0 on success, -ENOMEM on error.
Description
Enable/disable PCI INTx for device pdev. Restore the original state on driver detach.
pcim_enable_device() #
int Managed pci_enable_device()
Parameters
struct pci_dev *pdev: PCI device to be initialized
Return
0 on success, negative error code on failure.
Description
Managed pci_enable_device(). Device will automatically be disabled on
driver detach.
pcim_pin_device() #
void Pin managed PCI device
Parameters
struct pci_dev *pdev: PCI device to pin
Description
Pin managed PCI device pdev. Pinned device won't be disabled on driver
detach. pdev must have been enabled with pcim_enable_device().
pcim_iomap_table() #
void __iomem * const * access iomap allocation table (DEPRECATED)
Parameters
struct pci_dev *pdev: PCI device to access iomap table for
Return
Const pointer to array of __iomem pointers on success, NULL on failure.
Description
Access iomap allocation table for dev. If iomap table doesn't exist and pdev is managed, it will be allocated. All iomaps recorded in the iomap table are automatically unmapped on driver detach.
This function might sleep when the table is first allocated but can be safely called without context and guaranteed to succeed once allocated.
This function is DEPRECATED. Do not use it in new code. Instead, obtain a mapping's address directly from one of the pcim_* mapping functions. For
example
void __iomem *mappy = pcim_iomap(pdev, bar, length);
pcim_iomap() #
void __iomem * Managed pcim_iomap()
Parameters
struct pci_dev *pdev: PCI device to iomap forint bar: BAR to iomapunsigned long maxlen: Maximum length of iomap
Return
__iomem pointer on success, NULL on failure.
Description
Managed pci_iomap(). Map is automatically unmapped on driver detach. If
desired, unmap manually only with pcim_iounmap().
This SHOULD only be used once per BAR.
NOTE
Contrary to the other pcim_* functions, this function does not return an
IOMEM_ERR_PTR() on failure, but a simple NULL. This is done for backwards
compatibility.
pcim_iounmap() #
void Managed pci_iounmap()
Parameters
struct pci_dev *pdev: PCI device to iounmap forvoid __iomem *addr: Address to unmap
Description
Managed pci_iounmap(). addr must have been mapped using a pcim_* mapping
function.
pcim_iomap_region() #
void __iomem * Request and iomap a PCI BAR
Parameters
struct pci_dev *pdev: PCI device to map IO resources forint bar: Index of a BAR to mapconst char *name: Name 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. If
desired, release manually only with pcim_iounmap_region().
pcim_iounmap_region() #
void Unmap and release a PCI BAR
Parameters
struct pci_dev *pdev: PCI device to operate onint bar: Index of BAR to unmap and release
Description
Unmap a BAR and release its region manually. Only pass BARs that were
previously mapped by pcim_iomap_region().
pcim_iomap_regions() #
int Request and iomap PCI BARs (DEPRECATED)
Parameters
struct pci_dev *pdev: PCI device to map IO resources forint mask: Mask of BARs to request and iomapconst char *name: Name of the driver requesting the resources
Return
0 on success, negative error code on failure.
Description
Request and iomap regions specified by mask.
This function is DEPRECATED. Do not use it in new code.
Use pcim_iomap_region() instead.
pcim_request_region() #
int Request a PCI BAR
Parameters
struct pci_dev *pdev: PCI device to request region forint bar: Index of BAR to requestconst char *name: Name of the driver requesting the resource
Return
0 on success, a negative error code on failure.
Description
Request region specified by bar.
The region will automatically be released on driver detach. If desired,
release manually only with pcim_release_region().
pcim_request_all_regions() #
int Request all regions
Parameters
struct pci_dev *pdev: PCI device to map IO resources forconst char *name: name 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. If
desired, release individual regions with pcim_release_region() or all of
them at once with pcim_release_all_regions().
pcim_iomap_range() #
void __iomem * Create a ranged __iomap mapping within a PCI BAR
Parameters
struct pci_dev *pdev: PCI device to map IO resources forint bar: Index of the BARunsigned long offset: Offset from the begin of the BARunsigned long len: Length in bytes for the mapping
Return
__iomem pointer on success, an IOMEM_ERR_PTR on failure.
Description
Creates a new IO-Mapping within the specified bar, ranging from offset to offset + len.
The mapping will automatically get unmapped on driver detach. If desired,
release manually only with pcim_iounmap().
pci_add_dynid() #
int add a new PCI device ID to this driver and re-probe devices
Parameters
struct pci_driver *drv: target pci driverunsigned int vendor: PCI vendor IDunsigned int device: PCI device IDunsigned int subvendor: PCI subvendor IDunsigned int subdevice: PCI subdevice IDunsigned int class: PCI classunsigned int class_mask: PCI class maskunsigned long driver_data: private driver data
Description
Adds a new dynamic pci device ID to this driver and causes the driver to probe for all devices again. drv must have been registered prior to calling this function.
Context
Does GFP_KERNEL allocation.
Return
0 on success, -errno on failure.
pci_match_id() #
const struct pci_device_id * See if a PCI device matches a given pci_id table
Parameters
const struct pci_device_id *ids: array of PCI device ID structures to search instruct pci_dev *dev: the PCI device structure to match against.
Description
Used by a driver to check whether a PCI device is in its list of
supported devices. Returns the matching pci_device_id structure or
NULL if there is no match.
Deprecated; don't use this as it will not catch any dynamic IDs that a driver might want to check for.
__pci_register_driver() #
int register a new pci driver
Parameters
struct pci_driver *drv: the driver structure to registerstruct module *owner: owner module of drvconst char *mod_name: module 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 if no device was claimed during registration.
pci_unregister_driver() #
void unregister a pci driver
Parameters
struct pci_driver *drv: the 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 its remove() function for
each device it was responsible for, and marks those devices as
driverless.
pci_dev_driver() #
struct pci_driver * get the pci_driver of a device
Parameters
const struct pci_dev *dev: the device to query
Description
Returns the appropriate pci_driver structure or NULL if there is no
registered driver for the device.
pci_dev_get() #
struct pci_dev * increments the reference count of the pci device structure
Parameters
struct pci_dev *dev: the device being referenced
Description
Each live reference to a device should be refcounted.
Drivers for PCI devices should normally record such references in
their probe() methods, when they bind to a device, and release
them by calling pci_dev_put(), in their disconnect() methods.
A pointer to the device with the incremented reference counter is returned.
pci_dev_put() #
void release a use of the pci device structure
Parameters
struct pci_dev *dev: device that's been disconnected
Description
Must be called when a user of a device is finished with it. When the last user of the device calls this function, the memory of the device is freed.
pci_stop_and_remove_bus_device() #
void remove a PCI device and any children
Parameters
struct pci_dev *dev: the device to remove
Description
Remove a PCI device from the device lists, informing the drivers that the device has been removed. We also remove any subordinate buses and children in a depth-first manner.
For each device we remove, delete the device structure from the device lists, remove the /proc entry, and notify userspace (/sbin/hotplug).
pci_find_bus() #
struct pci_bus * locate PCI bus from a given domain and bus number
Parameters
int domain: number of PCI domain to searchint busnr: number of desired PCI bus
Description
Given a PCI bus number and domain number, the desired PCI bus is located
in the global list of PCI buses. If the bus is found, a pointer to its
data structure is returned. If no bus is found, NULL is returned.
pci_find_next_bus() #
struct pci_bus * begin or continue searching for a PCI bus
Parameters
const struct pci_bus *from: Previous PCI bus found, orNULLfor new search.
Description
Iterates through the list of known PCI buses. A new search is
initiated by passing NULL as the from argument. Otherwise if
from is not NULL, searches continue from next device on the
global list.
pci_get_slot() #
struct pci_dev * locate PCI device for a given PCI slot
Parameters
struct pci_bus *bus: PCI bus on which desired PCI device residesunsigned int devfn: encodes number of PCI slot in which the desired PCI device resides and the logical device number within that slot in case of multi-function devices.
Description
Given a PCI bus and slot/function number, the desired PCI device
is located in the list of PCI devices.
If the device is found, its reference count is increased and this
function returns a pointer to its data structure. The caller must
decrement the reference count by calling pci_dev_put().
If no device is found, NULL is returned.
pci_get_domain_bus_and_slot() #
struct pci_dev * locate PCI device for a given PCI domain (segment), bus, and slot
Parameters
int domain: PCI domain/segment on which the PCI device resides.unsigned int bus: PCI bus on which desired PCI device residesunsigned int devfn: encodes number of PCI slot in which the desired PCI device resides and the logical device number within that slot in case of multi-function devices.
Description
Given a PCI domain, bus, and slot/function number, the desired PCI
device is located in the list of PCI devices. If the device is
found, its reference count is increased and this function returns a
pointer to its data structure. The caller must decrement the
reference count by calling pci_dev_put(). If no device is found,
NULL is returned.
pci_get_subsys() #
struct pci_dev * begin or continue searching for a PCI device by vendor/subvendor/device/subdevice id
Parameters
unsigned int vendor: PCI vendor id to match, orPCI_ANY_IDto match all vendor idsunsigned int device: PCI device id to match, orPCI_ANY_IDto match all device idsunsigned int ss_vendor: PCI subsystem vendor id to match, orPCI_ANY_IDto match all vendor idsunsigned int ss_device: PCI subsystem device id to match, orPCI_ANY_IDto match all device idsstruct pci_dev *from: Previous PCI device found in search, orNULLfor new search.
Description
Iterates through the list of known PCI devices. If a PCI device is found
with a matching vendor, device, ss_vendor and ss_device, a pointer to its
device structure is returned, and the reference count to the device is
incremented. Otherwise, NULL is returned. A new search is initiated by
passing NULL as the from argument. Otherwise if from is not NULL,
searches continue from next device on the global list.
The reference count for from is always decremented if it is not NULL.
pci_get_device() #
struct pci_dev * begin or continue searching for a PCI device by vendor/device id
Parameters
unsigned int vendor: PCI vendor id to match, orPCI_ANY_IDto match all vendor idsunsigned int device: PCI device id to match, orPCI_ANY_IDto match all device idsstruct pci_dev *from: Previous PCI device found in search, orNULLfor new search.
Description
Iterates through the list of known PCI devices. If a PCI device is
found with a matching vendor and device, the reference count to the
device is incremented and a pointer to its device structure is returned.
Otherwise, NULL is returned. A new search is initiated by passing NULL
as the from argument. Otherwise if from is not NULL, searches continue
from next device on the global list. The reference count for from is
always decremented if it is not NULL.
pci_get_class() #
struct pci_dev * begin or continue searching for a PCI device by class
Parameters
unsigned int class: search for a PCI device with this class designationstruct pci_dev *from: Previous PCI device found in search, orNULLfor new search.
Description
Iterates through the list of known PCI devices. If a PCI device is
found with a matching class, the reference count to the device is
incremented and a pointer to its device structure is returned.
Otherwise, NULL is returned.
A new search is initiated by passing NULL as the from argument.
Otherwise if from is not NULL, searches continue from next device
on the global list. The reference count for from is always decremented
if it is not NULL.
pci_get_base_class() #
struct pci_dev * searching for a PCI device by matching against the base class code only
Parameters
unsigned int class: search for a PCI device with this base class codestruct pci_dev *from: Previous PCI device found in search, orNULLfor new search.
Description
Iterates through the list of known PCI devices. If a PCI device is found
with a matching base class code, the reference count to the device is
incremented. See pci_match_one_device() to figure out how does this works.
A new search is initiated by passing NULL as the from argument.
Otherwise if from is not NULL, searches continue from next device on the
global list. The reference count for from is always decremented if it is
not NULL.
Return
A pointer to a matched PCI device, NULL Otherwise.
pci_dev_present() #
int Returns 1 if device matching the device list is present, 0 if not.
Parameters
const struct pci_device_id *ids: A pointer to a null terminated list of struct pci_device_id structures that 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 found by this function, so if that device is removed from the system right after this function is finished, the value will be stale. Use this function to find devices that are usually built into a system, or for a general hint as to if another device happens to be present at this specific moment in time.
pci_msi_mask_irq() #
void Generic IRQ chip callback to mask PCI/MSI interrupts
Parameters
struct irq_data *data: pointer to irqdata associated to that interrupt
pci_msi_unmask_irq() #
void Generic IRQ chip callback to unmask PCI/MSI interrupts
Parameters
struct irq_data *data: pointer to irqdata associated to that interrupt
pci_msi_vec_count() #
int Return the number of MSI vectors a device can send
Parameters
struct pci_dev *dev: device to report about
Description
This function returns the number of MSI vectors a device requested via Multiple Message Capable register. It returns a negative errno if the device is not capable sending MSI interrupts. Otherwise, the call succeeds and returns a power of two, up to a maximum of 2^5 (32), according to the MSI specification.
pci_bus_alloc_resource() #
int allocate a resource from a parent bus
Parameters
struct pci_bus *bus: PCI busstruct resource *res: resource to allocateresource_size_t size: size of resource to allocateresource_size_t align: alignment of resource to allocateresource_size_t min: minimum /proc/iomem address to allocateunsigned long type_mask: IORESOURCE_* type flagsresource_alignf alignf: resource alignment functionvoid *alignf_data: data 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 allocation for a specific device resource.
pci_bus_add_device() #
void start driver for a single device
Parameters
struct pci_dev *dev: device to add
Description
This adds add sysfs entries and start device drivers
pci_bus_add_devices() #
void start driver for PCI devices
Parameters
const struct pci_bus *bus: bus to check for new devices
Description
Start driver for PCI devices and add some sysfs entries.
pci_walk_bus() #
void walk devices on/under bus, calling callback.
Parameters
struct pci_bus *top: bus whose devices should be walkedint (*cb)(struct pci_dev *, void *): callback to be called for each device foundvoid *userdata: arbitrary pointer to be passed to callback
Description
Walk the given bus, including any bridged devices on buses under this bus. Call the provided callback on each device found.
We check the return of cb each time. If it returns anything other than 0, we break out.
pci_walk_bus_reverse() #
void walk devices on/under bus, calling callback.
Parameters
struct pci_bus *top: bus whose devices should be walkedint (*cb)(struct pci_dev *, void *): callback to be called for each device foundvoid *userdata: arbitrary pointer to be passed to callback
Description
Same semantics as pci_walk_bus(), but walks the bus in reverse order.
pci_bus_set_ops() #
struct pci_ops * Set raw operations of pci bus
Parameters
struct pci_bus *bus: pci bus structstruct pci_ops *ops: new raw operations
Description
Return previous raw operations
pci_cfg_access_lock() #
void Lock PCI config reads/writes
Parameters
struct pci_dev *dev: pci device struct
Description
When access is locked, any userspace reads or writes to config
space and concurrent lock requests will sleep until access is
allowed via pci_cfg_access_unlock() again.
pci_cfg_access_trylock() #
bool try to lock PCI config reads/writes
Parameters
struct pci_dev *dev: pci device struct
Description
Same as pci_cfg_access_lock, but will return 0 if access is already locked, 1 otherwise. This function can be used from atomic contexts.
pci_cfg_access_unlock() #
void Unlock PCI config reads/writes
Parameters
struct pci_dev *dev: pci device struct
Description
This function allows PCI config accesses to resume.
pci_request_irq() #
int allocate an interrupt line for a PCI device
Parameters
struct pci_dev *dev: PCI device to operate onunsigned int nr: device-relative interrupt vector index (0-based).irq_handler_t handler: Function to be called when the IRQ occurs. Primary handler for threaded interrupts. If NULL and thread_fn != NULL the default primary handler is installed.irq_handler_t thread_fn: Function called from the IRQ handler thread If NULL, no IRQ thread is createdvoid *dev_id: Cookie passed back to the handler functionconst char *fmt: Printf-like format string naming the handler...: variable arguments
Description
This call allocates interrupt resources and enables the interrupt line and IRQ handling. From the point this call is made handler and thread_fn may be invoked. All interrupts requested using this function might be shared.
dev_id must not be NULL and must be globally unique.
pci_free_irq() #
void free an interrupt allocated with pci_request_irq
Parameters
struct pci_dev *dev: PCI device to operate onunsigned int nr: device-relative interrupt vector index (0-based).void *dev_id: Device identity to free
Description
Remove an interrupt handler. The handler is removed and if the interrupt line is no longer in use by any driver it is disabled. The caller must ensure the interrupt is disabled on the device before calling this function. The function does not return until any executing interrupts for this IRQ have completed.
This function must not be called from interrupt context.
pci_common_swizzle() #
u8 swizzle INTx all the way to root bridge
Parameters
struct pci_dev *dev: the PCI deviceu8 *pinp: pointer 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-PCI bridges all the way up to a PCI root bus.
pci_check_and_mask_intx() #
bool mask INTx on pending interrupt
Parameters
struct pci_dev *dev: the PCI device to operate on
Description
Check if the device dev has its INTx line asserted, mask it and return true in that case. False is returned if no interrupt was pending.
pci_check_and_unmask_intx() #
bool unmask INTx if no interrupt is pending
Parameters
struct pci_dev *dev: the PCI device to operate on
Description
Check if the device dev has its INTx line asserted, unmask it if not and return true. False is returned and the mask remains active if there was still an interrupt pending.
pcie_relaxed_ordering_enabled() #
bool Probe for PCIe relaxed ordering enable
Parameters
struct pci_dev *dev: PCI device to query
Description
Returns true if the device has enabled relaxed ordering attribute.
pci_scan_slot() #
int Scan a PCI slot on a bus for devices
Parameters
struct pci_bus *bus: PCI bus to scanint devfn: slot number to scan (must have zero function)
Description
Scan a PCI slot on the specified PCI bus for devices, adding discovered devices to the bus->devices list. New devices will not have is_added set.
Returns the number of new devices found.
pci_scan_child_bus() #
unsigned int Scan devices below a bus
Parameters
struct pci_bus *bus: Bus to scan for devices
Description
Scans devices below bus including subordinate buses. Returns new subordinate number including all the found devices.
pci_rescan_bus() #
unsigned int Scan a PCI bus for devices
Parameters
struct pci_bus *bus: PCI 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.
pci_create_slot() #
struct pci_slot * create or increment refcount for physical PCI slot
Parameters
struct pci_bus *parent: struct pci_bus of parent bridgeint slot_nr: PCI_SLOT(pci_dev->devfn) or -1 for placeholderconst char *name: user visible string presented in /sys/bus/pci/slots/<name>struct hotplug_slot *hotplug: set if caller is hotplug driver, NULL otherwise
Description
PCI slots have first class attributes such as address, speed, width,
and a struct pci_slot is used to manage them. This interface will
either return a new struct pci_slot to the caller, or if the pci_slot
already exists, its refcount will be incremented.
Slots are uniquely identified by a pci_bus, slot_nr tuple.
There are known platforms with broken firmware that assign the same name to multiple slots. Workaround these broken platforms by renaming the slots on behalf of the caller. If firmware assigns name N to multiple slots:
The first slot is assigned N The second slot is assigned N-1 The third slot is assigned N-2 etc.
Placeholder slots: In most cases, pci_bus, slot_nr will be sufficient to uniquely identify a slot. There is one notable exception - pSeries (rpaphp), where the slot_nr cannot be determined until a device is actually inserted into the slot. In this scenario, the caller may pass -1 for slot_nr.
The following semantics are imposed when the caller passes slot_nr ==
-1. First, we no longer check for an existing struct pci_slot, as there
may be many slots with slot_nr of -1. The other change in semantics is
user-visible, which is the 'address' parameter presented in sysfs will
consist solely of a dddd:bb tuple, where dddd is the PCI domain of the
struct pci_bus and bb is the bus number. In other words, the devfn of
the 'placeholder' slot will not be displayed.
pci_destroy_slot() #
void decrement refcount for physical PCI slot
Parameters
struct pci_slot *slot: struct pci_slot to decrement
Description
struct pci_slot is refcounted, so destroying them is really easy; we
just call kobject_put on its kobj and let our release methods do the
rest.
pci_rebar_bytes_to_size() #
int Convert size in bytes to PCI BAR Size
Parameters
u64 bytes: size 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)
pci_rebar_size_to_bytes() #
resource_size_t Convert encoded BAR Size to size in bytes
Parameters
int size: encoded BAR Size as defined in the PCIe spec (0=1MB, 31=128TB)
Return
BAR size in bytes
pci_rebar_get_possible_sizes() #
u64 get possible sizes for Resizable BAR
Parameters
struct pci_dev *pdev: PCI deviceint bar: BAR 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), or 0 if
BAR isn't resizable.
pci_rebar_size_supported() #
bool check if size is supported for BAR
Parameters
struct pci_dev *pdev: PCI deviceint bar: BAR to checkint size: encoded size as defined in the PCIe spec (0=1MB, 31=128TB)
Return
true if bar is resizable and size is supported, otherwise
false.
pci_rebar_get_max_size() #
int get the maximum supported size of a BAR
Parameters
struct pci_dev *pdev: PCI deviceint bar: BAR 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.
pci_resize_resource() #
int reconfigure a Resizable BAR and resources
Parameters
struct pci_dev *dev: the PCI deviceint resno: index of the BAR to be resizedint size: new size as defined in the spec (0=1MB, 31=128TB)int exclude_bars: a mask of BARs that should not be released
Description
Reconfigure resno to size and re-run resource assignment algorithm with the new size.
Prior to resize, release dev resources that share a bridge window with resno. This unpins the bridge window resource to allow changing it.
The caller may prevent releasing a particular BAR by providing exclude_bars mask, but this may result in the resize operation failing due to insufficient space.
Return
0 on success, or negative on error. In case of an error, the resources are restored to their original places.
pci_enable_rom() #
int enable ROM decoding for a PCI device
Parameters
struct pci_dev *pdev: PCI device to enable
Description
Enable ROM decoding on dev. This involves simply turning on the last bit of the PCI ROM BAR. Note that some cards may share address decoders between the ROM and other resources, so enabling it may disable access to MMIO registers or other card memory.
pci_disable_rom() #
void disable ROM decoding for a PCI device
Parameters
struct pci_dev *pdev: PCI device to disable
Description
Disable ROM decoding on a PCI device by turning off the last bit in the ROM BAR.
pci_map_rom() #
void __iomem * map a PCI ROM to kernel space
Parameters
struct pci_dev *pdev: pointer to pci device structsize_t *size: pointer 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 the actual ROM.
pci_unmap_rom() #
void unmap the ROM from kernel space
Parameters
struct pci_dev *pdev: pointer to pci device structvoid __iomem *rom: virtual address of the previous mapping
Description
Remove a mapping of a previously mapped ROM
pci_iov_get_pf_drvdata() #
void * Return the drvdata of a PF
Parameters
struct pci_dev *dev: VF pci_devstruct pci_driver *pf_driver: Device 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 its remove()
callback.
Locking is achieved by the driver core. A VF driver cannot be probed until
pci_enable_sriov() is called and pci_disable_sriov() does not return until
all VF drivers have completed their remove().
The PF driver must call pci_disable_sriov() before it begins to destroy the
drvdata.
pci_enable_sriov() #
int enable the SR-IOV capability
Parameters
struct pci_dev *dev: the PCI deviceint nr_virtfn: number of virtual functions to enable
Description
Returns 0 on success, or negative on failure.
pci_disable_sriov() #
void disable the SR-IOV capability
Parameters
struct pci_dev *dev: the PCI device
pci_num_vf() #
int return number of VFs associated with a PF device_release_driver
Parameters
struct pci_dev *dev: the PCI device
Description
Returns number of VFs, or 0 if SR-IOV is not enabled.
pci_vfs_assigned() #
int returns number of VFs are assigned to a guest
Parameters
struct pci_dev *dev: the 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.
pci_sriov_set_totalvfs() #
int - reduce the TotalVFs available
Parameters
struct pci_dev *dev: the PCI PF deviceu16 numvfs: number that should be used for TotalVFs supported
Description
Should be called from PF driver's probe routine with device's mutex held.
Returns 0 if PF is an SRIOV-capable device and value of numvfs valid. If not a PF return -ENOSYS; if numvfs is invalid return -EINVAL; if VFs already enabled, return -EBUSY.
pci_sriov_get_totalvfs() #
int - get total VFs supported on this device
Parameters
struct pci_dev *dev: the PCI PF device
Description
For a PCIe device with SRIOV support, return the PCIe SRIOV capability value of TotalVFs or the value of driver_max_VFs if the driver reduced it. Otherwise 0.
pci_sriov_configure_simple() #
int helper to configure SR-IOV
Parameters
struct pci_dev *dev: the PCI deviceint nr_virtfn: number of virtual functions to enable, 0 to disable
Description
Enable or disable SR-IOV for devices that don't require any PF setup before enabling SR-IOV. Return value is negative on error, or number of VFs allocated on success.
pci_iov_vf_bar_set_size() #
int set a new size for a VF BAR
Parameters
struct pci_dev *dev: the PCI deviceint resno: the resource numberint size: new 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.
Unlike pci_resize_resource(), this does not cause the resource that
reserves the MMIO space (originally up to total_VFs) to be resized, which
means that following calls to pci_enable_sriov() can fail if the resources
no longer fit.
Return
0 on success, or negative on failure.
pci_iov_vf_bar_get_sizes() #
u32 get VF BAR sizes allowing to create up to num_vfs
Parameters
struct pci_dev *dev: the PCI deviceint resno: the resource numberint num_vfs: number of VFs
Description
Get the sizes of a VF resizable BAR that can accommodate num_vfs within the currently assigned size of the resource resno.
Return
A bitmask of sizes in format defined in the spec (bit 0=1MB, bit 31=128TB).
pci_read_legacy_io() #
ssize_t read byte(s) from legacy I/O port space
Parameters
struct file *filp: open sysfs filestruct kobject *kobj: kobject corresponding to file to read fromconst struct bin_attribute *bin_attr: struct bin_attribute for this filechar *buf: buffer to store resultsloff_t off: offset into legacy I/O port spacesize_t count: number of bytes to read
Description
Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specific callback routine (pci_legacy_read).
pci_write_legacy_io() #
ssize_t write byte(s) to legacy I/O port space
Parameters
struct file *filp: open sysfs filestruct kobject *kobj: kobject corresponding to file to read fromconst struct bin_attribute *bin_attr: struct bin_attribute for this filechar *buf: buffer containing value to be writtenloff_t off: offset into legacy I/O port spacesize_t count: number of bytes to write
Description
Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specific callback routine (pci_legacy_write).
pci_mmap_legacy_mem() #
int map legacy PCI memory into user memory space
Parameters
struct file *filp: open sysfs filestruct kobject *kobj: kobject corresponding to device to be mappedconst struct bin_attribute *attr: struct bin_attribute for this filestruct vm_area_struct *vma: struct vm_area_struct passed to mmap
Description
Uses an arch specific callback, pci_mmap_legacy_mem_page_range, to mmap legacy memory space (first meg of bus space) into application virtual memory space.
pci_mmap_legacy_io() #
int map legacy PCI IO into user memory space
Parameters
struct file *filp: open sysfs filestruct kobject *kobj: kobject corresponding to device to be mappedconst struct bin_attribute *attr: struct bin_attribute for this filestruct vm_area_struct *vma: struct vm_area_struct passed to mmap
Description
Uses an arch specific callback, pci_mmap_legacy_io_page_range, to mmap legacy IO space (first meg of bus space) into application virtual memory space. Returns -ENOSYS if the operation isn't supported
pci_adjust_legacy_attr() #
void adjustment of legacy file attributes
Parameters
struct pci_bus *b: bus to create files underenum pci_mmap_state mmap_type: I/O port or memory
Description
Stub implementation. Can be overridden by arch if necessary.
pci_create_legacy_files() #
void create legacy I/O port and memory files
Parameters
struct pci_bus *b: bus to create files under
Description
Some platforms allow access to legacy I/O port and ISA memory space on a per-bus basis. This routine creates the files and ties them into their associated read, write and mmap files from pci-sysfs.c
On error unwind, but don't propagate the error to the caller as it is ok to set up the PCI bus without these files.
pci_mmap_resource() #
int map a PCI resource into user memory space
Parameters
struct kobject *kobj: kobject for mappingconst struct bin_attribute *attr: struct bin_attribute for the file being mappedstruct vm_area_struct *vma: struct vm_area_struct passed into the mmapint write_combine: 1 for write_combine mapping
Description
Use the regular PCI mapping routines to map a PCI resource into userspace.
pci_remove_resource_files() #
void cleanup resource files
Parameters
struct pci_dev *pdev: dev to cleanup
Description
If we created resource files for pdev, remove them from sysfs and free their resources.
pci_create_resource_files() #
int create resource files in sysfs for dev
Parameters
struct pci_dev *pdev: dev in question
Description
Walk the resources in pdev creating files for each resource available.
pci_write_rom() #
ssize_t used to enable access to the PCI ROM display
Parameters
struct file *filp: sysfs filestruct kobject *kobj: kernel object handleconst struct bin_attribute *bin_attr: struct bin_attribute for this filechar *buf: user inputloff_t off: file offsetsize_t count: number of byte in input
Description
writing anything except 0 enables it
pci_read_rom() #
ssize_t read a PCI ROM
Parameters
struct file *filp: sysfs filestruct kobject *kobj: kernel object handleconst struct bin_attribute *bin_attr: struct bin_attribute for this filechar *buf: where to put the data we read from the ROMloff_t off: file offsetsize_t count: number of bytes to read
Description
Put count bytes starting at off into buf from the ROM in the PCI device corresponding to kobj.
pci_remove_sysfs_dev_files() #
void cleanup PCI specific sysfs files
Parameters
struct pci_dev *pdev: device whose entries we should free
Description
Cleanup when pdev is removed from sysfs.
pcie_tph_get_st_table_loc() #
u32 Return the device's ST table location
Parameters
struct pci_dev *pdev: PCI device to query
Return
PCI_TPH_LOC_NONE - Not present PCI_TPH_LOC_CAP - Located in the TPH Requester Extended Capability PCI_TPH_LOC_MSIX - Located in the MSI-X Table
pcie_tph_get_cpu_st() #
int Retrieve Steering Tag for a target memory associated with a specific CPU
Parameters
struct pci_dev *pdev: PCI deviceenum tph_mem_type mem_type: target memory type (volatile or persistent RAM)unsigned int cpu_uid: associated CPU idu16 *tag: Steering Tag to be returned
Description
Return the Steering Tag for a target memory that is associated with a specific CPU as indicated by cpu_uid.
Return
0 if success, otherwise negative value (-errno)
pcie_tph_set_st_entry() #
int Set Steering Tag in the ST table entry
Parameters
struct pci_dev *pdev: PCI deviceunsigned int index: ST table entry indexu16 tag: Steering Tag to be written
Description
Figure out the proper location of ST table, either in the MSI-X table or in the TPH Extended Capability space, and write the Steering Tag into the ST entry pointed by index.
Return
0 if success, otherwise negative value (-errno)
pcie_disable_tph() #
void Turn off TPH support for device
Parameters
struct pci_dev *pdev: PCI device
Return
none
pcie_enable_tph() #
int Enable TPH support for device using a specific ST mode
Parameters
struct pci_dev *pdev: PCI deviceint mode: ST 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 enabling and 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 requester capability and the Root Port's completer capability.
Return
0 on success, otherwise negative value (-errno)
PCI Hotplug Support Library #
__pci_hp_register() #
int register a hotplug_slot with the PCI hotplug subsystem
Parameters
struct hotplug_slot *slot: pointer to thestruct hotplug_slotto registerstruct pci_bus *bus: bus this slot is onint devnr: device numberconst char *name: name registered with kobject corestruct module *owner: caller module ownerconst char *mod_name: caller module name
Description
Prepares a hotplug slot for in-kernel use and immediately publishes it to
user space in one go. Drivers may alternatively carry out the two steps
separately by invoking pci_hp_initialize() and pci_hp_add().
Returns 0 if successful, anything else for an error.
__pci_hp_initialize() #
int prepare hotplug slot for in-kernel use
Parameters
struct hotplug_slot *slot: pointer to thestruct hotplug_slotto initializestruct pci_bus *bus: bus this slot is onint devnr: slot numberconst char *name: name registered with kobject corestruct module *owner: caller module ownerconst char *mod_name: caller module name
Description
Allocate and fill in a PCI slot for use by a hotplug driver. Once this has
been called, the driver may invoke hotplug_slot_name() to get the slot's
unique name. The driver must be prepared to handle a ->reset_slot callback
from this point on.
Returns 0 on success or a negative int on error.
pci_hp_add() #
int publish hotplug slot to user space
Parameters
struct hotplug_slot *slot: pointer to thestruct hotplug_slotto publish
Description
Make a hotplug slot's sysfs interface available and inform user space of its
addition by sending a uevent. The hotplug driver must be prepared to handle
all struct hotplug_slot_ops callbacks from this point on.
Returns 0 on success or a negative int on error.
pci_hp_deregister() #
void deregister a hotplug_slot with the PCI hotplug subsystem
Parameters
struct hotplug_slot *slot: pointer to thestruct hotplug_slotto deregister
Description
The slot must have been registered with the pci hotplug subsystem
previously with a call to pci_hp_register().
pci_hp_del() #
void unpublish hotplug slot from user space
Parameters
struct hotplug_slot *slot: pointer to thestruct hotplug_slotto unpublish
Description
Remove a hotplug slot's sysfs interface.
pci_hp_destroy() #
void remove hotplug slot from in-kernel use
Parameters
struct hotplug_slot *slot: pointer to thestruct hotplug_slotto destroy
Description
Destroy a PCI slot used by a hotplug driver. Once this has been called,
the driver may no longer invoke hotplug_slot_name() to get the slot's
unique name. The driver no longer needs to handle a ->reset_slot callback
from this point on.
PCI Trusted Execution Environment Security Manager (TSM)
Peios Kernel / Hardware and drivers / Driver development / PCI
Subsystem Interfaces #
struct pci_ide_partner #
Per port pair Selective IDE Stream settings
Definition
;
Members
rid_start: Partner Port Requester ID range startrid_end: Partner Port Requester ID range end (inclusive)stream_index: Selective IDE Stream Register Block selectionmem_assoc: PCI bus memory address association for targeting peer partnerpref_assoc: PCI bus prefetchable memory address association for targeting peer partnerdefault_stream: Endpoint uses this stream for all upstream TLPs regardless of address and RID association registerssetup: flag to track whether to runpci_ide_stream_teardown()for this partner slotenable: flag whether to runpci_ide_stream_disable()for this partner slot
Description
By default, pci_ide_stream_alloc() initializes mem_assoc and pref_assoc
with the immediate ancestor downstream port memory ranges (i.e. Type 1
Configuration Space Header values). Caller may zero size ({0, -1}) the range
to drop it from consideration at pci_ide_stream_setup() time.
struct pci_ide_regs #
Hardware register association settings for Selective IDE Streams
Definition
;
Members
rid1: IDE RID Association Register 1rid2: IDE RID Association Register 2addr: Up to two address association blocks (IDE Address Association Register 1 through 3) for MMIO and prefetchable MMIOnr_addr: Number of address association blocks initialized
Description
See pci_ide_stream_to_regs()
struct pci_ide #
PCIe Selective IDE Stream descriptor
Definition
;
Members
pdev: PCIe Endpoint in the pci_ide_partner pairpartner: per-partner settingshost_bridge_stream: allocated from host bridge ide_stream_ida poolstream_id: unique Stream ID (within Partner Port pairing)name: name of the established Selective IDE Stream in sysfs
Description
Negative stream_id values indicate "uninitialized" on the expectation that with TSM established IDE the TSM owns the stream_id allocation.
pci_ide_stream_alloc() #
struct pci_ide * Reserve stream indices and probe for settings
Parameters
struct pci_dev *pdev: IDE capable PCIe Endpoint Physical Function
Description
Retrieve the Requester ID range of pdev for programming its Root Port IDE RID Association registers, and conversely retrieve the Requester ID of the Root Port for programming pdev's IDE RID Association registers.
Allocate a Selective IDE Stream Register Block instance per port.
Allocate a platform stream resource from the associated host bridge. Retrieve stream association parameters for Requester ID range and address range restrictions for the stream.
pci_ide_stream_free() #
void unwind pci_ide_stream_alloc()
Parameters
struct pci_ide *ide: idle IDE settings descriptor
Description
Free all of the stream index (register block) allocations acquired by
pci_ide_stream_alloc(). The stream represented by ide is assumed to
be unregistered and not instantiated in any device.
pci_ide_stream_release() #
void unwind and release an ide context
Parameters
struct pci_ide *ide: partially or fully registered IDE settings descriptor
Description
In support of automatic cleanup of IDE setup routines perform IDE teardown in expected reverse order of setup and with respect to which aspects of IDE setup have successfully completed.
Be careful that setup order mirrors this shutdown order. Otherwise, open code releasing the IDE context.
pci_ide_stream_register() #
int Prepare to activate an IDE Stream
Parameters
struct pci_ide *ide: IDE settings descriptor
Description
After a Stream ID has been acquired for ide, record the presence of the stream in sysfs. The expectation is that ide is immutable while registered.
pci_ide_stream_unregister() #
void unwind pci_ide_stream_register()
Parameters
struct pci_ide *ide: idle IDE settings descriptor
Description
In preparation for freeing ide, remove sysfs enumeration for the stream.
pci_ide_stream_setup() #
void program settings to Selective IDE Stream registers
Parameters
struct pci_dev *pdev: PCIe device object for either a Root Port or Endpoint Partner Portstruct pci_ide *ide: registered IDE settings descriptor
Description
When pdev is a PCI_EXP_TYPE_ENDPOINT then the PCI_IDE_EP partner settings are written to pdev's Selective IDE Stream register block, and when pdev is a PCI_EXP_TYPE_ROOT_PORT, the PCI_IDE_RP settings are selected.
pci_ide_stream_teardown() #
void disable the stream and clear all settings
Parameters
struct pci_dev *pdev: PCIe device object for either a Root Port or Endpoint Partner Portstruct pci_ide *ide: registered IDE settings descriptor
Description
For stream destruction, zero all registers that may have been written
by pci_ide_stream_setup(). Consider pci_ide_stream_disable() to leave
settings in place while temporarily disabling the stream.
pci_ide_stream_enable() #
int enable a Selective IDE Stream
Parameters
struct pci_dev *pdev: PCIe device object for either a Root Port or Endpoint Partner Portstruct pci_ide *ide: registered and setup IDE settings descriptor
Description
Activate the stream by writing to the Selective IDE Stream Control Register.
Note that the state may go "insecure" at any point after returning 0, but those events are equivalent to a "link down" event and handled via asynchronous error reporting.
Caller is responsible to clear the enable bit in the -ENXIO case.
Return
0 if the stream successfully entered the "secure" state, and -EINVAL if ide is invalid, and -ENXIO if the stream fails to enter the secure state.
pci_ide_stream_disable() #
void disable a Selective IDE Stream
Parameters
struct pci_dev *pdev: PCIe device object for either a Root Port or Endpoint Partner Portstruct pci_ide *ide: registered and setup IDE settings descriptor
Description
Clear the Selective IDE Stream Control Register, but leave all other registers untouched.
pci_ide_set_nr_streams() #
void sets size of the pool of IDE Stream resources
Parameters
struct pci_host_bridge *hb: host bridge boundary for the stream poolu16 nr: number of streams
Description
Platform PCI init and/or expert test module use only. Limit IDE
Stream establishment by setting the number of stream resources
available at the host bridge. Platform init code must set this before
the first pci_ide_stream_alloc() call if the platform has less than the
default of 256 streams per host-bridge.
The "PCI_IDE" symbol namespace is required because this is typically a detail that is settled in early PCI init. I.e. this export is not for endpoint drivers.
struct pci_tdi #
Core TEE I/O Device Interface (TDI) context
Definition
;
Members
pdev: host side representation of guest-side TDIkvm: TEE VM context of bound TDItdi_id: Identifier (virtual BDF) for the TDI as referenced by the TSM and DSM
struct pci_tsm #
Core TSM context for a given PCIe endpoint
Definition
;
Members
pdev: Back ref to device function, distinguishes type of pci_tsm contextdsm_dev: PCI Device Security Manager for link operations on pdevtsm_dev: PCI TEE Security Manager device for Link Confidentiality or Device Function Security operationstdi: TDI context established by the bind link operation
Description
This structure is wrapped by low level TSM driver data and returned by
probe()/lock(), it is freed by the corresponding remove()/unlock().
For link operations it serves to cache the association between a Device Security Manager (DSM) and the functions that manager can assign to a TVM. That can be "self", for assigning function0 of a TEE I/O device, a sub-function (SR-IOV virtual function, or non-function0 multifunction-device), or a downstream endpoint (PCIe upstream switch-port as DSM).
struct pci_tsm_pf0 #
Physical Function 0 TDISP link context
Definition
;
Members
base_tsm: generic core "tsm" contextlock: mutual exclustion for pci_tsm_ops invocationdoe_mb: PCIe Data Object Exchange mailbox
enum pci_tsm_req_scope #
Scope of guest requests to be validated by TSM
Constants
-
PCI_TSM_REQ_INFO: Read-only, without side effects, request for typical TDISP collateral information like Device Interface Reports. No device secrets are permitted, and no device state is changed. -
PCI_TSM_REQ_STATE_CHANGE: Request to change the TDISP state from UNLOCKED->LOCKED, LOCKED->RUN, or other architecture specific state changes to support those transitions for a TDI. No other (unrelated to TDISP) device / host state, configuration, or data change is permitted. -
PCI_TSM_REQ_DEBUG_READ: Read-only request for debug informationA method to facilitate TVM information retrieval outside of typical TDISP operational requirements. No device secrets are permitted.
-
PCI_TSM_REQ_DEBUG_WRITE: Device state changes for debug purposesThe request may affect the operational state of the device outside of the TDISP operational model. If allowed, requires CAP_SYS_RAW_IO, and will taint the kernel.
Description
Guest requests are a transport for a TVM to communicate with a TSM + DSM for a given TDI. A TSM driver is responsible for maintaining the kernel security model and limit commands that may affect the host, or are otherwise outside the typical TDISP operational model.
pci_tsm_bind() #
int Bind pdev as a TDI for kvm
Parameters
struct pci_dev *pdev: PCI device function to bindstruct kvm *kvm: Private memory attach contextu32 tdi_id: Identifier (virtual BDF) for the TDI as referenced by the TSM and DSM
Description
Returns 0 on success, or a negative error code on failure.
Context
Caller is responsible for constraining the bind lifetime to the
registered state of the device. For example, pci_tsm_bind() /
pci_tsm_unbind() limited to the VFIO driver bound state of the device.
pci_tsm_guest_req() #
ssize_t helper to marshal guest requests to the TSM driver
Parameters
-
struct pci_dev *pdev:pdev representing a bound tdi
-
enum pci_tsm_req_scope scope: caller asserts this passthrough request is limited to TDISP operations -
sockptr_t req_in: Input payload forwarded from the guest -
size_t in_len: Length of req_in -
sockptr_t req_out: Output payload buffer response to the guest -
size_t out_len: Length of req_out on input, bytes filled in req_out on output -
u64 *tsm_code: Optional TSM arch specific result code for the guest TSM
Description
This is a common entry point for requests triggered by userspace KVM-exit service handlers responding to TDI information or state change requests. The scope parameter limits requests to TDISP state management, or limited debug. This path is only suitable for commands and results that are the host kernel has no use, the host is only facilitating guest to TSM communication.
Returns 0 on success and -error on failure and positive "residue" on success but req_out is filled with less then out_len, or req_out is NULL and a residue number of bytes were not consumed from req_in. On success or failure tsm_code may be populated with a TSM implementation specific result code for the guest to consume.
Context
Caller is responsible for calling this within the pci_tsm_bind()
state of the TDI.
pci_tsm_tdi_constructor() #
void base 'struct pci_tdi' initialization for link TSMs
Parameters
struct pci_dev *pdev: PCI device function representing the TDIstruct pci_tdi *tdi: context to initializestruct kvm *kvm: Private memory attach contextu32 tdi_id: Identifier (virtual BDF) for the TDI as referenced by the TSM and DSM
pci_tsm_link_constructor() #
int base 'struct pci_tsm' initialization for link TSMs
Parameters
struct pci_dev *pdev: The PCI devicestruct pci_tsm *tsm: context to initializestruct tsm_dev *tsm_dev: Platform TEE Security Manager, initiator of security operations
pci_tsm_pf0_constructor() #
int common 'struct pci_tsm_pf0' (DSM) initialization
Parameters
struct pci_dev *pdev: Physical Function 0 PCI device (as indicated byis_pci_tsm_pf0())struct pci_tsm_pf0 *tsm: context to initializestruct tsm_dev *tsm_dev: Platform TEE Security Manager, initiator of security operations