Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
pcie.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DRIVERS_PCIE_PCIE_H_
8#define ZEPHYR_INCLUDE_DRIVERS_PCIE_PCIE_H_
9
10#include <stddef.h>
12#include <zephyr/types.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
28
38
39struct pcie_mbar {
41 size_t size;
42};
43
44/*
45 * These functions are arch-, board-, or SoC-specific.
46 */
47
58
68extern uint32_t pcie_conf_read(pcie_bdf_t bdf, unsigned int reg);
69
79extern void pcie_conf_write(pcie_bdf_t bdf, unsigned int reg, uint32_t data);
80
88extern bool pcie_probe(pcie_bdf_t bdf, pcie_id_t id);
89
97extern bool pcie_get_mbar(pcie_bdf_t bdf,
98 unsigned int bar_index,
99 struct pcie_mbar *mbar);
100
115 unsigned int index,
116 struct pcie_mbar *mbar);
117
125extern void pcie_set_cmd(pcie_bdf_t bdf, uint32_t bits, bool on);
126
137extern unsigned int pcie_alloc_irq(pcie_bdf_t bdf);
138
145extern unsigned int pcie_get_irq(pcie_bdf_t bdf);
146
159extern void pcie_irq_enable(pcie_bdf_t bdf, unsigned int irq);
160
169
178
179/*
180 * Configuration word 13 contains the head of the capabilities list.
181 */
182
183#define PCIE_CONF_CAPPTR 13U /* capabilities pointer */
184#define PCIE_CONF_CAPPTR_FIRST(w) (((w) >> 2) & 0x3FU)
185
186/*
187 * The first word of every capability contains a capability identifier,
188 * and a link to the next capability (or 0) in configuration space.
189 */
190
191#define PCIE_CONF_CAP_ID(w) ((w) & 0xFFU)
192#define PCIE_CONF_CAP_NEXT(w) (((w) >> 10) & 0x3FU)
193
194/*
195 * The extended PCI Express capabilies lies at the end of the PCI configuration space
196 */
197
198#define PCIE_CONF_EXT_CAPPTR 64U
199
200/*
201 * The first word of every capability contains an extended capability identifier,
202 * and a link to the next capability (or 0) in the extended configuration space.
203 */
204
205#define PCIE_CONF_EXT_CAP_ID(w) ((w) & 0xFFFFU)
206#define PCIE_CONF_EXT_CAP_VER(w) (((w) >> 16) & 0xFU)
207#define PCIE_CONF_EXT_CAP_NEXT(w) (((w) >> 20) & 0xFFFU)
208
209/*
210 * Configuration word 0 aligns directly with pcie_id_t.
211 */
212
213#define PCIE_CONF_ID 0U
214
215/*
216 * Configuration word 1 contains command and status bits.
217 */
218
219#define PCIE_CONF_CMDSTAT 1U /* command/status register */
220
221#define PCIE_CONF_CMDSTAT_IO 0x00000001U /* I/O access enable */
222#define PCIE_CONF_CMDSTAT_MEM 0x00000002U /* mem access enable */
223#define PCIE_CONF_CMDSTAT_MASTER 0x00000004U /* bus master enable */
224#define PCIE_CONF_CMDSTAT_CAPS 0x00100000U /* capabilities list */
225
226/*
227 * Configuration word 2 has additional function identification that
228 * we only care about for debug output (PCIe shell commands).
229 */
230
231#define PCIE_CONF_CLASSREV 2U /* class/revision register */
232
233#define PCIE_CONF_CLASSREV_CLASS(w) (((w) >> 24) & 0xFFU)
234#define PCIE_CONF_CLASSREV_SUBCLASS(w) (((w) >> 16) & 0xFFU)
235#define PCIE_CONF_CLASSREV_PROGIF(w) (((w) >> 8) & 0xFFU)
236#define PCIE_CONF_CLASSREV_REV(w) ((w) & 0xFFU)
237
238/*
239 * The only part of configuration word 3 that is of interest to us is
240 * the header type, as we use it to distinguish functional endpoints
241 * from bridges (which are, for our purposes, transparent).
242 */
243
244#define PCIE_CONF_TYPE 3U
245
246#define PCIE_CONF_TYPE_BRIDGE(w) (((w) & 0x007F0000U) != 0U)
247
248/*
249 * Words 4-9 are BARs are I/O or memory decoders. Memory decoders may
250 * be 64-bit decoders, in which case the next configuration word holds
251 * the high-order bits (and is, thus, not a BAR itself).
252 */
253
254#define PCIE_CONF_BAR0 4U
255#define PCIE_CONF_BAR1 5U
256#define PCIE_CONF_BAR2 6U
257#define PCIE_CONF_BAR3 7U
258#define PCIE_CONF_BAR4 8U
259#define PCIE_CONF_BAR5 9U
260
261#define PCIE_CONF_BAR_IO(w) (((w) & 0x00000001U) == 0x00000001U)
262#define PCIE_CONF_BAR_MEM(w) (((w) & 0x00000001U) != 0x00000001U)
263#define PCIE_CONF_BAR_64(w) (((w) & 0x00000006U) == 0x00000004U)
264#define PCIE_CONF_BAR_ADDR(w) ((w) & ~0xfUL)
265#define PCIE_CONF_BAR_FLAGS(w) ((w) & 0xfUL)
266#define PCIE_CONF_BAR_NONE 0U
267
268#define PCIE_CONF_BAR_INVAL 0xFFFFFFF0U
269#define PCIE_CONF_BAR_INVAL64 0xFFFFFFFFFFFFFFF0UL
270
271#define PCIE_CONF_BAR_INVAL_FLAGS(w) \
272 ((((w) & 0x00000006U) == 0x00000006U) || \
273 (((w) & 0x00000006U) == 0x00000002U))
274
275/*
276 * Word 15 contains information related to interrupts.
277 *
278 * We're only interested in the low byte, which is [supposed to be] set by
279 * the firmware to indicate which wire IRQ the device interrupt is routed to.
280 */
281
282#define PCIE_CONF_INTR 15U
283
284#define PCIE_CONF_INTR_IRQ(w) ((w) & 0xFFU)
285#define PCIE_CONF_INTR_IRQ_NONE 0xFFU /* no interrupt routed */
286
287#define PCIE_MAX_BUS (0xFFFFFFFF & PCIE_BDF_BUS_MASK)
288#define PCIE_MAX_DEV (0xFFFFFFFF & PCIE_BDF_DEV_MASK)
289#define PCIE_MAX_FUNC (0xFFFFFFFF & PCIE_BDF_FUNC_MASK)
290
291#ifdef __cplusplus
292}
293#endif
294
295#endif /* ZEPHYR_INCLUDE_DRIVERS_PCIE_PCIE_H_ */
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.
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_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:37
bool pcie_get_mbar(pcie_bdf_t bdf, unsigned int bar_index, struct pcie_mbar *mbar)
Get the MBAR at a specific BAR index.
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:27
pcie_bdf_t pcie_bdf_lookup(pcie_id_t id)
Look up the BDF based on PCI(e) vendor & device ID.
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_mbar *mbar)
Probe the nth MMIO address assigned to an endpoint.
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.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:75
Definition: pcie.h:39
size_t size
Definition: pcie.h:41
uintptr_t phys_addr
Definition: pcie.h:40
static fdata_t data[2]
Definition: test_fifo_contexts.c:15