7#ifndef ZEPHYR_INCLUDE_DRIVERS_PCIE_PCIE_H_ 
    8#define ZEPHYR_INCLUDE_DRIVERS_PCIE_PCIE_H_ 
   47#define PCIE_ID_IS_VALID(id) ((id != PCIE_ID_NONE) && \ 
   48                              (id != PCIE_ID(0x0000, 0x0000)) && \ 
   49                              (id != PCIE_ID(0xFFFF, 0x0000)) && \ 
   50                              (id != PCIE_ID(0x0000, 0xFFFF))) 
   59#define Z_DEVICE_PCIE_NAME(node_id) _CONCAT(pcie_dev_, DT_DEP_ORD(node_id)) 
   67#define PCIE_DT_ID(node_id) PCIE_ID(DT_PROP_OR(node_id, vendor_id, 0xffff), \ 
   68                                    DT_PROP_OR(node_id, device_id, 0xffff)) 
   79#define PCIE_DT_INST_ID(inst) PCIE_DT_ID(DT_DRV_INST(inst)) 
   89#define DEVICE_PCIE_DECLARE(node_id)                                        \ 
   90        STRUCT_SECTION_ITERABLE(pcie_dev, Z_DEVICE_PCIE_NAME(node_id)) = {  \ 
   91                .bdf = PCIE_BDF_NONE,                                       \ 
   92                .id = PCIE_DT_ID(node_id),                                  \ 
   93                .class_rev = DT_PROP_OR(node_id, class_rev, 0),             \ 
   94                .class_rev_mask = DT_PROP_OR(node_id, class_rev_mask, 0),   \ 
  105#define DEVICE_PCIE_INST_DECLARE(inst) DEVICE_PCIE_DECLARE(DT_DRV_INST(inst)) 
  131#define DEVICE_PCIE_INIT(node_id, name) .name = &Z_DEVICE_PCIE_NAME(node_id) 
  142#define DEVICE_PCIE_INST_INIT(inst, name) \ 
  143        DEVICE_PCIE_INIT(DT_DRV_INST(inst), name) 
  251                          unsigned int bar_index,
 
  279                           unsigned int bar_index,
 
  308#ifndef CONFIG_PCIE_CONTROLLER 
  378                                     unsigned int priority,
 
  379                                     void (*routine)(
const void *parameter),
 
  380                                     const void *parameter,
 
  393#define PCIE_HOST_CONTROLLER(n) PCIE_BDF(0, 0, n) 
  399#define PCIE_CONF_CAPPTR        13U      
  400#define PCIE_CONF_CAPPTR_FIRST(w)       (((w) >> 2) & 0x3FU) 
  407#define PCIE_CONF_CAP_ID(w)             ((w) & 0xFFU) 
  408#define PCIE_CONF_CAP_NEXT(w)           (((w) >> 10) & 0x3FU) 
  414#define PCIE_CONF_EXT_CAPPTR    64U 
  421#define PCIE_CONF_EXT_CAP_ID(w)         ((w) & 0xFFFFU) 
  422#define PCIE_CONF_EXT_CAP_VER(w)        (((w) >> 16) & 0xFU) 
  423#define PCIE_CONF_EXT_CAP_NEXT(w)       (((w) >> 20) & 0xFFFU) 
  429#define PCIE_CONF_ID            0U 
  435#define PCIE_CONF_CMDSTAT       1U       
  437#define PCIE_CONF_CMDSTAT_IO            0x00000001U   
  438#define PCIE_CONF_CMDSTAT_MEM           0x00000002U   
  439#define PCIE_CONF_CMDSTAT_MASTER        0x00000004U   
  440#define PCIE_CONF_CMDSTAT_INTERRUPT     0x00080000U   
  441#define PCIE_CONF_CMDSTAT_CAPS          0x00100000U   
  448#define PCIE_CONF_CLASSREV      2U       
  450#define PCIE_CONF_CLASSREV_CLASS(w)     (((w) >> 24) & 0xFFU) 
  451#define PCIE_CONF_CLASSREV_SUBCLASS(w)  (((w) >> 16) & 0xFFU) 
  452#define PCIE_CONF_CLASSREV_PROGIF(w)    (((w) >> 8) & 0xFFU) 
  453#define PCIE_CONF_CLASSREV_REV(w)       ((w) & 0xFFU) 
  461#define PCIE_CONF_TYPE          3U 
  463#define PCIE_CONF_MULTIFUNCTION(w)      (((w) & 0x00800000U) != 0U) 
  464#define PCIE_CONF_TYPE_BRIDGE(w)        (((w) & 0x007F0000U) != 0U) 
  465#define PCIE_CONF_TYPE_GET(w)           (((w) >> 16) & 0x7F) 
  467#define PCIE_CONF_TYPE_STANDARD         0x0U 
  468#define PCIE_CONF_TYPE_PCI_BRIDGE       0x1U 
  469#define PCIE_CONF_TYPE_CARDBUS_BRIDGE   0x2U 
  477#define PCIE_CONF_BAR0          4U 
  478#define PCIE_CONF_BAR1          5U 
  479#define PCIE_CONF_BAR2          6U 
  480#define PCIE_CONF_BAR3          7U 
  481#define PCIE_CONF_BAR4          8U 
  482#define PCIE_CONF_BAR5          9U 
  484#define PCIE_CONF_BAR_IO(w)             (((w) & 0x00000001U) == 0x00000001U) 
  485#define PCIE_CONF_BAR_MEM(w)            (((w) & 0x00000001U) != 0x00000001U) 
  486#define PCIE_CONF_BAR_64(w)             (((w) & 0x00000006U) == 0x00000004U) 
  487#define PCIE_CONF_BAR_ADDR(w)           ((w) & ~0xfUL) 
  488#define PCIE_CONF_BAR_IO_ADDR(w)        ((w) & ~0x3UL) 
  489#define PCIE_CONF_BAR_FLAGS(w)          ((w) & 0xfUL) 
  490#define PCIE_CONF_BAR_NONE              0U 
  492#define PCIE_CONF_BAR_INVAL             0xFFFFFFF0U 
  493#define PCIE_CONF_BAR_INVAL64           0xFFFFFFFFFFFFFFF0UL 
  495#define PCIE_CONF_BAR_INVAL_FLAGS(w)                    \ 
  496        ((((w) & 0x00000006U) == 0x00000006U) ||        \ 
  497         (((w) & 0x00000006U) == 0x00000002U)) 
  502#define PCIE_BUS_NUMBER         6U 
  504#define PCIE_BUS_PRIMARY_NUMBER(w)      ((w) & 0xffUL) 
  505#define PCIE_BUS_SECONDARY_NUMBER(w)    (((w) >> 8) & 0xffUL) 
  506#define PCIE_BUS_SUBORDINATE_NUMBER(w)  (((w) >> 16) & 0xffUL) 
  507#define PCIE_SECONDARY_LATENCY_TIMER(w) (((w) >> 24) & 0xffUL) 
  509#define PCIE_BUS_NUMBER_VAL(prim, sec, sub, lat) \ 
  510        (((prim) & 0xffUL) |                     \ 
  511         (((sec) & 0xffUL) << 8) |               \ 
  512         (((sub) & 0xffUL) << 16) |              \ 
  513         (((lat) & 0xffUL) << 24)) 
  518#define PCIE_IO_SEC_STATUS      7U 
  520#define PCIE_IO_BASE(w)         ((w) & 0xffUL) 
  521#define PCIE_IO_LIMIT(w)        (((w) >> 8) & 0xffUL) 
  522#define PCIE_SEC_STATUS(w)      (((w) >> 16) & 0xffffUL) 
  524#define PCIE_IO_SEC_STATUS_VAL(iob, iol, sec_status) \ 
  525        (((iob) & 0xffUL) |                          \ 
  526         (((iol) & 0xffUL) << 8) |                   \ 
  527         (((sec_status) & 0xffffUL) << 16)) 
  529#define PCIE_MEM_BASE_LIMIT     8U 
  531#define PCIE_MEM_BASE(w)        ((w) & 0xffffUL) 
  532#define PCIE_MEM_LIMIT(w)       (((w) >> 16) & 0xffffUL) 
  534#define PCIE_MEM_BASE_LIMIT_VAL(memb, meml) \ 
  535        (((memb) & 0xffffUL) |              \ 
  536         (((meml) & 0xffffUL) << 16)) 
  538#define PCIE_PREFETCH_BASE_LIMIT        9U 
  540#define PCIE_PREFETCH_BASE(w)   ((w) & 0xffffUL) 
  541#define PCIE_PREFETCH_LIMIT(w)  (((w) >> 16) & 0xffffUL) 
  543#define PCIE_PREFETCH_BASE_LIMIT_VAL(pmemb, pmeml) \ 
  544        (((pmemb) & 0xffffUL) |                    \ 
  545         (((pmeml) & 0xffffUL) << 16)) 
  547#define PCIE_PREFETCH_BASE_UPPER        10U 
  549#define PCIE_PREFETCH_LIMIT_UPPER       11U 
  551#define PCIE_IO_BASE_LIMIT_UPPER        12U 
  553#define PCIE_IO_BASE_UPPER(w)   ((w) & 0xffffUL) 
  554#define PCIE_IO_LIMIT_UPPER(w)  (((w) >> 16) & 0xffffUL) 
  556#define PCIE_IO_BASE_LIMIT_UPPER_VAL(iobu, iolu) \ 
  557        (((iobu) & 0xffffUL) |                   \ 
  558         (((iolu) & 0xffffUL) << 16)) 
  567#define PCIE_CONF_INTR          15U 
  569#define PCIE_CONF_INTR_IRQ(w)   ((w) & 0xFFU) 
  570#define PCIE_CONF_INTR_IRQ_NONE 0xFFU   
  572#define PCIE_MAX_BUS  (0xFFFFFFFFU & PCIE_BDF_BUS_MASK) 
  573#define PCIE_MAX_DEV  (0xFFFFFFFFU & PCIE_BDF_DEV_MASK) 
  574#define PCIE_MAX_FUNC (0xFFFFFFFFU & PCIE_BDF_FUNC_MASK) 
  590#define PCIE_IRQ_CONNECT(bdf_p, irq_p, priority_p,                      \ 
  591                         isr_p, isr_param_p, flags_p)                   \ 
  592        ARCH_PCIE_IRQ_CONNECT(bdf_p, irq_p, priority_p,                 \ 
  593                              isr_p, isr_param_p, flags_p) 
ZTEST_BMEM int index[(3)]
Definition: main.c:32
 
uint32_t pcie_conf_read(pcie_bdf_t bdf, unsigned int reg)
Read a 32-bit word from an endpoint's configuration space.
 
bool pcie_connect_dynamic_irq(pcie_bdf_t bdf, unsigned int irq, unsigned int priority, void(*routine)(const void *parameter), const void *parameter, uint32_t flags)
Dynamically connect a PCIe endpoint IRQ to an ISR handler.
 
void pcie_set_cmd(pcie_bdf_t bdf, uint32_t bits, bool on)
Set or reset bits in the endpoint command/status register.
 
bool pcie_get_iobar(pcie_bdf_t bdf, unsigned int bar_index, struct pcie_bar *iobar)
Get the I/O BAR at a specific BAR index.
 
bool pcie_probe(pcie_bdf_t bdf, pcie_id_t id)
Probe for the presence of a PCI(e) endpoint.
 
uint32_t pcie_id_t
A unique PCI(e) identifier (vendor ID, device ID).
Definition: pcie.h:40
 
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.
 
uint32_t pcie_get_cap(pcie_bdf_t bdf, uint32_t cap_id)
Find a PCI(e) capability in an endpoint's configuration space.
 
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.
 
uint32_t pcie_bdf_t
A unique PCI(e) endpoint (bus, device, function).
Definition: pcie.h:30
 
bool(* pcie_scan_cb_t)(pcie_bdf_t bdf, pcie_id_t id, void *cb_data)
Definition: pcie.h:198
 
int pcie_scan(const struct pcie_scan_opt *opt)
 
bool pcie_probe_iobar(pcie_bdf_t bdf, unsigned int index, struct pcie_bar *iobar)
Probe the nth I/O BAR address assigned to an endpoint.
 
pcie_bdf_t pcie_bdf_lookup(pcie_id_t id)
Look up the BDF based on PCI(e) vendor & device ID.
 
@ PCIE_SCAN_RECURSIVE
Definition: pcie.h:202
 
@ PCIE_SCAN_CB_ALL
Definition: pcie.h:204
 
unsigned int pcie_alloc_irq(pcie_bdf_t bdf)
Allocate an IRQ for an endpoint.
 
bool pcie_probe_mbar(pcie_bdf_t bdf, unsigned int index, struct pcie_bar *mbar)
Probe the nth MMIO address assigned to an endpoint.
 
bool pcie_get_mbar(pcie_bdf_t bdf, unsigned int bar_index, struct pcie_bar *mbar)
Get the MBAR at a specific BAR index.
 
unsigned int pcie_get_irq(pcie_bdf_t bdf)
Return the IRQ assigned by the firmware/board to an endpoint.
 
void pcie_irq_enable(pcie_bdf_t bdf, unsigned int irq)
Enable the PCI(e) endpoint to generate the specified IRQ.
 
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
 
flags
Definition: parser.h:96
 
#define bool
Definition: stdbool.h:13
 
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
 
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
 
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:105
 
uintptr_t phys_addr
Definition: pcie.h:146
 
size_t size
Definition: pcie.h:147
 
pcie_id_t id
Definition: pcie.h:54
 
uint32_t class_rev_mask
Definition: pcie.h:56
 
pcie_bdf_t bdf
Definition: pcie.h:53
 
uint32_t class_rev
Definition: pcie.h:55
 
uint8_t bus
Definition: pcie.h:210
 
void * cb_data
Definition: pcie.h:216
 
pcie_scan_cb_t cb
Definition: pcie.h:213
 
uint32_t flags
Definition: pcie.h:219
 
static fdata_t data[2]
Definition: test_fifo_contexts.c:15