#include <stddef.h>
#include <dt-bindings/pcie/pcie.h>
#include <zephyr/types.h>
Go to the source code of this file.
|
pcie_bdf_t | pcie_bdf_lookup (pcie_id_t id) |
| Look up the BDF based on PCI(e) vendor & device ID. More...
|
|
uint32_t | pcie_conf_read (pcie_bdf_t bdf, unsigned int reg) |
| Read a 32-bit word from an endpoint's configuration space. More...
|
|
void | pcie_conf_write (pcie_bdf_t bdf, unsigned int reg, uint32_t data) |
| Write a 32-bit word to an endpoint's configuration space. More...
|
|
bool | pcie_probe (pcie_bdf_t bdf, pcie_id_t id) |
| Probe for the presence of a PCI(e) endpoint. More...
|
|
bool | pcie_get_mbar (pcie_bdf_t bdf, unsigned int bar_index, struct pcie_mbar *mbar) |
| Get the MBAR at a specific BAR index. More...
|
|
bool | pcie_probe_mbar (pcie_bdf_t bdf, unsigned int index, struct pcie_mbar *mbar) |
| Probe the nth MMIO address assigned to an endpoint. More...
|
|
void | pcie_set_cmd (pcie_bdf_t bdf, uint32_t bits, bool on) |
| Set or reset bits in the endpoint command/status register. More...
|
|
unsigned int | pcie_alloc_irq (pcie_bdf_t bdf) |
| Allocate an IRQ for an endpoint. More...
|
|
unsigned int | pcie_get_irq (pcie_bdf_t bdf) |
| Return the IRQ assigned by the firmware/board to an endpoint. More...
|
|
void | pcie_irq_enable (pcie_bdf_t bdf, unsigned int irq) |
| Enable the PCI(e) endpoint to generate the specified IRQ. More...
|
|
uint32_t | pcie_get_cap (pcie_bdf_t bdf, uint32_t cap_id) |
| Find a PCI(e) capability in an endpoint's configuration space. More...
|
|
uint32_t | pcie_get_ext_cap (pcie_bdf_t bdf, uint32_t cap_id) |
| Find an Extended PCI(e) capability in an endpoint's configuration space. More...
|
|
◆ PCIE_CONF_BAR0
#define PCIE_CONF_BAR0 4U |
◆ PCIE_CONF_BAR1
#define PCIE_CONF_BAR1 5U |
◆ PCIE_CONF_BAR2
#define PCIE_CONF_BAR2 6U |
◆ PCIE_CONF_BAR3
#define PCIE_CONF_BAR3 7U |
◆ PCIE_CONF_BAR4
#define PCIE_CONF_BAR4 8U |
◆ PCIE_CONF_BAR5
#define PCIE_CONF_BAR5 9U |
◆ PCIE_CONF_BAR_64
#define PCIE_CONF_BAR_64 |
( |
|
w | ) |
(((w) & 0x00000006U) == 0x00000004U) |
◆ PCIE_CONF_BAR_ADDR
#define PCIE_CONF_BAR_ADDR |
( |
|
w | ) |
((w) & ~0xfUL) |
◆ PCIE_CONF_BAR_FLAGS
#define PCIE_CONF_BAR_FLAGS |
( |
|
w | ) |
((w) & 0xfUL) |
◆ PCIE_CONF_BAR_INVAL
#define PCIE_CONF_BAR_INVAL 0xFFFFFFF0U |
◆ PCIE_CONF_BAR_INVAL64
#define PCIE_CONF_BAR_INVAL64 0xFFFFFFFFFFFFFFF0UL |
◆ PCIE_CONF_BAR_INVAL_FLAGS
#define PCIE_CONF_BAR_INVAL_FLAGS |
( |
|
w | ) |
|
Value: ((((w) & 0x00000006U) == 0x00000006U) || \
(((w) & 0x00000006U) == 0x00000002U))
◆ PCIE_CONF_BAR_IO
#define PCIE_CONF_BAR_IO |
( |
|
w | ) |
(((w) & 0x00000001U) == 0x00000001U) |
◆ PCIE_CONF_BAR_MEM
#define PCIE_CONF_BAR_MEM |
( |
|
w | ) |
(((w) & 0x00000001U) != 0x00000001U) |
◆ PCIE_CONF_BAR_NONE
#define PCIE_CONF_BAR_NONE 0U |
◆ PCIE_CONF_CAP_ID
#define PCIE_CONF_CAP_ID |
( |
|
w | ) |
((w) & 0xFFU) |
◆ PCIE_CONF_CAP_NEXT
#define PCIE_CONF_CAP_NEXT |
( |
|
w | ) |
(((w) >> 10) & 0x3FU) |
◆ PCIE_CONF_CAPPTR
#define PCIE_CONF_CAPPTR 13U /* capabilities pointer */ |
◆ PCIE_CONF_CAPPTR_FIRST
#define PCIE_CONF_CAPPTR_FIRST |
( |
|
w | ) |
(((w) >> 2) & 0x3FU) |
◆ PCIE_CONF_CLASSREV
#define PCIE_CONF_CLASSREV 2U /* class/revision register */ |
◆ PCIE_CONF_CLASSREV_CLASS
#define PCIE_CONF_CLASSREV_CLASS |
( |
|
w | ) |
(((w) >> 24) & 0xFFU) |
◆ PCIE_CONF_CLASSREV_PROGIF
#define PCIE_CONF_CLASSREV_PROGIF |
( |
|
w | ) |
(((w) >> 8) & 0xFFU) |
◆ PCIE_CONF_CLASSREV_REV
#define PCIE_CONF_CLASSREV_REV |
( |
|
w | ) |
((w) & 0xFFU) |
◆ PCIE_CONF_CLASSREV_SUBCLASS
#define PCIE_CONF_CLASSREV_SUBCLASS |
( |
|
w | ) |
(((w) >> 16) & 0xFFU) |
◆ PCIE_CONF_CMDSTAT
#define PCIE_CONF_CMDSTAT 1U /* command/status register */ |
◆ PCIE_CONF_CMDSTAT_CAPS
#define PCIE_CONF_CMDSTAT_CAPS 0x00100000U /* capabilities list */ |
◆ PCIE_CONF_CMDSTAT_IO
#define PCIE_CONF_CMDSTAT_IO 0x00000001U /* I/O access enable */ |
◆ PCIE_CONF_CMDSTAT_MASTER
#define PCIE_CONF_CMDSTAT_MASTER 0x00000004U /* bus master enable */ |
◆ PCIE_CONF_CMDSTAT_MEM
#define PCIE_CONF_CMDSTAT_MEM 0x00000002U /* mem access enable */ |
◆ PCIE_CONF_EXT_CAP_ID
#define PCIE_CONF_EXT_CAP_ID |
( |
|
w | ) |
((w) & 0xFFFFU) |
◆ PCIE_CONF_EXT_CAP_NEXT
#define PCIE_CONF_EXT_CAP_NEXT |
( |
|
w | ) |
(((w) >> 20) & 0xFFFU) |
◆ PCIE_CONF_EXT_CAP_VER
#define PCIE_CONF_EXT_CAP_VER |
( |
|
w | ) |
(((w) >> 16) & 0xFU) |
◆ PCIE_CONF_EXT_CAPPTR
#define PCIE_CONF_EXT_CAPPTR 64U |
◆ PCIE_CONF_ID
◆ PCIE_CONF_INTR
#define PCIE_CONF_INTR 15U |
◆ PCIE_CONF_INTR_IRQ
#define PCIE_CONF_INTR_IRQ |
( |
|
w | ) |
((w) & 0xFFU) |
◆ PCIE_CONF_INTR_IRQ_NONE
#define PCIE_CONF_INTR_IRQ_NONE 0xFFU /* no interrupt routed */ |
◆ PCIE_CONF_TYPE
#define PCIE_CONF_TYPE 3U |
◆ PCIE_CONF_TYPE_BRIDGE
#define PCIE_CONF_TYPE_BRIDGE |
( |
|
w | ) |
(((w) & 0x007F0000U) != 0U) |
◆ PCIE_MAX_BUS
◆ PCIE_MAX_DEV
◆ PCIE_MAX_FUNC
◆ pcie_bdf_t
A unique PCI(e) endpoint (bus, device, function).
A PCI(e) endpoint is uniquely identified topologically using a (bus, device, function) tuple. The internal structure is documented in include/dt-bindings/pcie/pcie.h: see PCIE_BDF() and friends, since these tuples are referenced from devicetree.
◆ pcie_id_t
A unique PCI(e) identifier (vendor ID, device ID).
The PCIE_CONF_ID register for each endpoint is a (vendor ID, device ID) pair, which is meant to tell the system what the PCI(e) endpoint is. Again, look to PCIE_ID_* macros in include/dt-bindings/pcie/pcie.h for more.
◆ pcie_alloc_irq()
Allocate an IRQ for an endpoint.
This function first checks the IRQ register and if it contains a valid value this is returned. If the register does not contain a valid value allocation of a new one is attempted.
- Parameters
-
- Returns
- the IRQ number, or PCIE_CONF_INTR_IRQ_NONE if allocation failed.
◆ pcie_bdf_lookup()
Look up the BDF based on PCI(e) vendor & device ID.
This function is used to look up the BDF for a device given its vendor and device ID.
- Parameters
-
id | PCI(e) vendor & device ID encoded using PCIE_ID() |
- Returns
- The BDF for the device, or PCIE_BDF_NONE if it was not found
◆ pcie_conf_read()
Read a 32-bit word from an endpoint's configuration space.
This function is exported by the arch/SoC/board code.
- Parameters
-
bdf | PCI(e) endpoint |
reg | the configuration word index (not address) |
- Returns
- the word read (0xFFFFFFFFU if nonexistent endpoint or word)
◆ pcie_conf_write()
Write a 32-bit word to an endpoint's configuration space.
This function is exported by the arch/SoC/board code.
- Parameters
-
bdf | PCI(e) endpoint |
reg | the configuration word index (not address) |
data | the value to write |
◆ pcie_get_cap()
Find a PCI(e) capability in an endpoint's configuration space.
- Parameters
-
bdf | the PCI endpoint to examine |
cap_id | the capability ID of interest |
- Returns
- the index of the configuration word, or 0 if no capability.
◆ pcie_get_ext_cap()
Find an Extended PCI(e) capability in an endpoint's configuration space.
- Parameters
-
bdf | the PCI endpoint to examine |
cap_id | the capability ID of interest |
- Returns
- the index of the configuration word, or 0 if no capability.
◆ pcie_get_irq()
Return the IRQ assigned by the firmware/board to an endpoint.
- Parameters
-
- Returns
- the IRQ number, or PCIE_CONF_INTR_IRQ_NONE if unknown.
◆ pcie_get_mbar()
Get the MBAR at a specific BAR index.
- Parameters
-
bdf | the PCI(e) endpoint |
bar_index | 0-based BAR index |
mbar | Pointer to struct pcie_mbar |
- Returns
- true if the mbar was found and is valid, false otherwise
◆ pcie_irq_enable()
Enable the PCI(e) endpoint to generate the specified IRQ.
- Parameters
-
bdf | the PCI(e) endpoint |
irq | the IRQ to generate |
If MSI is enabled and the endpoint supports it, the endpoint will be configured to generate the specified IRQ via MSI. Otherwise, it is assumed that the IRQ has been routed by the boot firmware to the specified IRQ, and the IRQ is enabled (at the I/O APIC, or wherever appropriate).
◆ pcie_probe()
Probe for the presence of a PCI(e) endpoint.
- Parameters
-
bdf | the endpoint to probe |
id | the endpoint ID to expect, or PCIE_ID_NONE for "any device" |
- Returns
- true if the device is present, false otherwise
◆ pcie_probe_mbar()
Probe the nth MMIO address assigned to an endpoint.
- Parameters
-
bdf | the PCI(e) endpoint |
index | (0-based) index |
mbar | Pointer to struct pcie_mbar |
- Returns
- true if the mbar was found and is valid, false otherwise
A PCI(e) endpoint has 0 or more memory-mapped regions. This function allows the caller to enumerate them by calling with index=0..n. Value of n has to be below 6, as there is a maximum of 6 BARs. The indices are order-preserving with respect to the endpoint BARs: e.g., index 0 will return the lowest-numbered memory BAR on the endpoint.
◆ pcie_set_cmd()
Set or reset bits in the endpoint command/status register.
- Parameters
-
bdf | the PCI(e) endpoint |
bits | the powerset of bits of interest |
on | use true to set bits, false to reset them |