Get the translation between CPU memory addresses and PCI addresses
#include <pci/pci.h> pci_err_t pci_device_map_as( pci_devhdl_t hdl, const pci_ba_t * const as, pci_ba_t *as_xlate );
The pci_device_map_as() function is used by driver software to obtain the required translations between CPU memory addresses and PCI addresses. It's used (for example) when you've allocated a set of memory buffers that a PCI device should transfer in to. In this case, you need to program the PCI device with the inbound physical addresses of the memory buffers, but depending on how the hardware is configured, there may be translation hardware that maps the PCI address that must be targeted in order to resolve to the memory buffer addresses.
You should always call this function in this or any other similar scenario. If there's no translation required, as_xlate will effectively be the same as as.
The pci_ba_t structure is defined as follows:
typedef struct { pci_ba_val_t addr; uint64_t size; pci_asType_e type; pci_asAttr_e attr; int_t bar_num; } pci_ba_t;
The members include:
You can also OR in any of the following:
The as attributes (defined in <pci/pci.h> as type pci_asAttr_e) should fully specify in the as->attr field whether the driver is requesting translation for an outbound transfer (from CPU memory to PCI device) or inbound transfer (from PCI device to CPU memory). You should also specify other attributes, such as pci_asAttr_e_CONTIG, the alignment requirements, and so on. In addition to the as->attr field, you should also properly initialize the type, size, and addr fields. Note that all addresses are specified as physical addresses.
If any error occurs, you should assume that storage you provided for as_xlate contains invalid data.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |