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_DT_BINDINGS_PCIE_PCIE_H_
8#define ZEPHYR_INCLUDE_DT_BINDINGS_PCIE_PCIE_H_
9
10/*
11 * Set the device's IRQ (in devicetree, or whatever) to PCIE_IRQ_DETECT
12 * if the device doesn't support MSI and we don't/can't know the wired IRQ
13 * allocated by the firmware ahead of time. Use of this functionality will
14 * generally also require CONFIG_DYNAMIC_INTERRUPTS.
15 */
16
17#define PCIE_IRQ_DETECT 0xFFFFFFFU
18
19/*
20 * We represent a PCI device ID as [31:16] device ID, [15:0] vendor ID. Not
21 * coincidentally, this is same representation used in PCI configuration space.
22 */
23
24#define PCIE_ID_VEND_SHIFT 0U
25#define PCIE_ID_VEND_MASK 0xFFFFU
26#define PCIE_ID_DEV_SHIFT 16U
27#define PCIE_ID_DEV_MASK 0xFFFFU
28
29#define PCIE_ID(vend, dev) \
30 ((((vend) & PCIE_ID_VEND_MASK) << PCIE_ID_VEND_SHIFT) | \
31 (((dev) & PCIE_ID_DEV_MASK) << PCIE_ID_DEV_SHIFT))
32
33#define PCIE_ID_TO_VEND(id) (((id) >> PCIE_ID_VEND_SHIFT) & PCIE_ID_VEND_MASK)
34#define PCIE_ID_TO_DEV(id) (((id) >> PCIE_ID_DEV_SHIFT) & PCIE_ID_DEV_MASK)
35
36#define PCIE_ID_NONE PCIE_ID(0xFFFF, 0xFFFF)
37
38#define PCIE_BDF_NONE 0xFFFFFFFFU
39
40/*
41 * Since our internal representation of bus/device/function is arbitrary,
42 * we choose the same format employed in the x86 Configuration Address Port:
43 *
44 * [23:16] bus number, [15:11] device number, [10:8] function number
45 *
46 * All other bits must be zero.
47 *
48 * The x86 (the only arch, at present, that supports PCI) takes advantage
49 * of this shared format to avoid unnecessary layers of abstraction.
50 */
51
52#define PCIE_BDF_BUS_SHIFT 16U
53#define PCIE_BDF_BUS_MASK 0xFFU
54#define PCIE_BDF_DEV_SHIFT 11U
55#define PCIE_BDF_DEV_MASK 0x1FU
56#define PCIE_BDF_FUNC_SHIFT 8U
57#define PCIE_BDF_FUNC_MASK 0x7U
58
59#define PCIE_BDF(bus, dev, func) \
60 ((((bus) & PCIE_BDF_BUS_MASK) << PCIE_BDF_BUS_SHIFT) | \
61 (((dev) & PCIE_BDF_DEV_MASK) << PCIE_BDF_DEV_SHIFT) | \
62 (((func) & PCIE_BDF_FUNC_MASK) << PCIE_BDF_FUNC_SHIFT))
63
64#define PCIE_BDF_TO_BUS(bdf) (((bdf) >> PCIE_BDF_BUS_SHIFT) & PCIE_BDF_BUS_MASK)
65#define PCIE_BDF_TO_DEV(bdf) (((bdf) >> PCIE_BDF_DEV_SHIFT) & PCIE_BDF_DEV_MASK)
66
67#define PCIE_BDF_TO_FUNC(bdf) \
68 (((bdf) >> PCIE_BDF_FUNC_SHIFT) & PCIE_BDF_FUNC_MASK)
69
70#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_PCIE_PCIE_H_ */