Zephyr Project API  3.3.0
A Scalable Open Source RTOS
msi.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_MSI_H_
8#define ZEPHYR_INCLUDE_DRIVERS_PCIE_MSI_H_
9
10#include <zephyr/kernel.h>
11#include <zephyr/types.h>
12#include <stdbool.h>
13
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#ifdef CONFIG_PCIE_CONTROLLER
21struct msi_vector_generic {
22 unsigned int irq;
23 uint32_t address;
24 uint16_t eventid;
25 unsigned int priority;
26};
27
28typedef struct msi_vector_generic arch_msi_vector_t;
29
30#define PCI_DEVID(bus, dev, fn) ((((bus) & 0xff) << 8) | (((dev) & 0x1f) << 3) | ((fn) & 0x07))
31#define PCI_BDF_TO_DEVID(bdf) PCI_DEVID(PCIE_BDF_TO_BUS(bdf), \
32 PCIE_BDF_TO_DEV(bdf), \
33 PCIE_BDF_TO_FUNC(bdf))
34
35#endif
36
42} __packed;
43
44struct msi_vector {
46 arch_msi_vector_t arch;
47#ifdef CONFIG_PCIE_MSI_X
49 bool msix;
50#endif /* CONFIG_PCIE_MSI_X */
51};
52
53typedef struct msi_vector msi_vector_t;
54
55#ifdef CONFIG_PCIE_MSI_MULTI_VECTOR
56
67extern uint8_t pcie_msi_vectors_allocate(pcie_bdf_t bdf,
68 unsigned int priority,
69 msi_vector_t *vectors,
70 uint8_t n_vector);
71
83extern bool pcie_msi_vector_connect(pcie_bdf_t bdf,
84 msi_vector_t *vector,
85 void (*routine)(const void *parameter),
86 const void *parameter,
88
89#endif /* CONFIG_PCIE_MSI_MULTI_VECTOR */
90
101extern uint32_t pcie_msi_map(unsigned int irq,
102 msi_vector_t *vector,
103 uint8_t n_vector);
104
114extern uint16_t pcie_msi_mdr(unsigned int irq,
115 msi_vector_t *vector);
116
127 msi_vector_t *vectors,
128 uint8_t n_vector,
129 unsigned int irq);
130
138
139/*
140 * The first word of the MSI capability is shared with the
141 * capability ID and list link. The high 16 bits are the MCR.
142 */
143
144#define PCIE_MSI_MCR 0U
145
146#define PCIE_MSI_MCR_EN 0x00010000U /* enable MSI */
147#define PCIE_MSI_MCR_MMC 0x000E0000U /* Multi Messages Capable mask */
148#define PCIE_MSI_MCR_MMC_SHIFT 17
149#define PCIE_MSI_MCR_MME 0x00700000U /* mask of # of enabled IRQs */
150#define PCIE_MSI_MCR_MME_SHIFT 20
151#define PCIE_MSI_MCR_64 0x00800000U /* 64-bit MSI */
152
153/*
154 * The MAP follows the MCR. If PCIE_MSI_MCR_64, then the MAP
155 * is two words long. The MDR follows immediately after the MAP.
156 */
157
158#define PCIE_MSI_MAP0 1U
159#define PCIE_MSI_MAP1_64 2U
160#define PCIE_MSI_MDR_32 2U
161#define PCIE_MSI_MDR_64 3U
162
163/*
164 * As for MSI, he first word of the MSI-X capability is shared
165 * with the capability ID and list link. The high 16 bits are the MCR.
166 */
167
168#define PCIE_MSIX_MCR 0U
169
170#define PCIE_MSIX_MCR_EN 0x80000000U /* Enable MSI-X */
171#define PCIE_MSIX_MCR_FMASK 0x40000000U /* Function Mask */
172#define PCIE_MSIX_MCR_TSIZE 0x07FF0000U /* Table size mask */
173#define PCIE_MSIX_MCR_TSIZE_SHIFT 16
174#define PCIE_MSIR_TABLE_ENTRY_SIZE 16
175
176#define PCIE_MSIX_TR 1U
177#define PCIE_MSIX_TR_BIR 0x00000007U /* Table BIR mask */
178#define PCIE_MSIX_TR_OFFSET 0xFFFFFFF8U /* Offset mask */
179
180#define PCIE_MSIX_PBA 2U
181#define PCIE_MSIX_PBA_BIR 0x00000007U /* PBA BIR mask */
182#define PCIE_MSIX_PBA_OFFSET 0xFFFFFFF8U /* Offset mask */
183
184#define PCIE_VTBL_MA 0U /* Msg Address offset */
185#define PCIE_VTBL_MUA 4U /* Msg Upper Address offset */
186#define PCIE_VTBL_MD 8U /* Msg Data offset */
187#define PCIE_VTBL_VCTRL 12U /* Vector control offset */
188
189#ifdef __cplusplus
190}
191#endif
192
193#endif /* ZEPHYR_INCLUDE_DRIVERS_PCIE_MSI_H_ */
uint32_t pcie_bdf_t
A unique PCI(e) endpoint (bus, device, function).
Definition: pcie.h:29
Public kernel APIs.
uint32_t pcie_msi_map(unsigned int irq, msi_vector_t *vector, uint8_t n_vector)
Compute the target address for an MSI posted write.
bool pcie_msi_enable(pcie_bdf_t bdf, msi_vector_t *vectors, uint8_t n_vector, unsigned int irq)
Configure the given PCI endpoint to generate MSIs.
bool pcie_is_msi(pcie_bdf_t bdf)
Check if the given PCI endpoint supports MSI/MSI-X.
uint16_t pcie_msi_mdr(unsigned int irq, msi_vector_t *vector)
Compute the data for an MSI posted write.
flags
Definition: parser.h:96
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Definition: msi.h:44
pcie_bdf_t bdf
Definition: msi.h:45
arch_msi_vector_t arch
Definition: msi.h:46
Definition: msi.h:37
uint32_t msg_addr
Definition: msi.h:38
uint32_t msg_up_addr
Definition: msi.h:39
uint32_t vector_ctrl
Definition: msi.h:41
uint32_t msg_data
Definition: msi.h:40