Attach a device
#include <pci/pci.h> pci_devhdl_t pci_device_attach( pci_bdf_t bdf, pci_attachFlags_t flags, pci_err_t *err );
Device attachment is required in order to perform any configuration and/or write operations on a device. It's also required in order to obtain any address space (memory and I/O BAR) or interrupt information. This is to allow the attachment flags to provide access control only to software that requires this information. Attachment isn't required to read most other configuration space information. Any APIs that require a pci_devhdl_t must be attached to.
The flags parameter controls the way in which the attachment occurs as follows (see also <pci/pci.h>). You must specify one of the following bitwise-exclusive values:
You can also OR in any of the following bits:
If you don't set this flag on the first attachment that has pci_attachFlags_e_OWNER set, then subsequent attaches with pci_attachFlags_e_OWNER set are rejected regardless of the inclusion of pci_attachFlags_e_MULTI. That is, all multiply-owned attachers must set both the pci_attachFlags_e_OWNER and pci_attachFlags_e_MULTI flags. It's an error to set pci_attachFlags_e_MULTI with pci_attachFlags_e_EXCLUSIVE or without pci_attachFlags_e_OWNER.
The following combinations are also defined:
pci_attachFlags_OWNER = (pci_attachFlags_e_SHARED | pci_attachFlags_e_OWNER) pci_attachFlags_MULTI_OWNER = (pci_attachFlags_e_SHARED | pci_attachFlags_e_OWNER | pci_attachFlags_e_MULTI) pci_attachFlags_EXCLUSIVE_OWNER = pci_attachFlags_e_EXCLUSIVE | pci_attachFlags_e_OWNER pci_attachFlags_DEFAULT = pci_attachFlags_OWNER
A handle of type pci_devhdl_t that you can use in subsequent calls to access the device, or NULL if an error occurred.
If err is non-NULL, then the reason for the failed attachment is provided as follows:
The following error codes are specifically related to internal resource availability and use, and hence you aren't likely to see them:
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |