Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_PCIE_MSI_H_
14#define ZEPHYR_INCLUDE_DRIVERS_PCIE_MSI_H_
15
22
23#include <zephyr/kernel.h>
24#include <zephyr/types.h>
25#include <stdbool.h>
26
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#ifdef CONFIG_PCIE_CONTROLLER
34struct msi_vector_generic {
35 unsigned int irq;
36 uint32_t address;
37 uint16_t eventid;
38 unsigned int priority;
39};
40
41typedef struct msi_vector_generic arch_msi_vector_t;
42
43#define PCI_DEVID(bus, dev, fn) ((((bus) & 0xff) << 8) | (((dev) & 0x1f) << 3) | ((fn) & 0x07))
44#define PCI_BDF_TO_DEVID(bdf) PCI_DEVID(PCIE_BDF_TO_BUS(bdf), \
45 PCIE_BDF_TO_DEV(bdf), \
46 PCIE_BDF_TO_FUNC(bdf))
47
48#endif
49
56
57struct msi_vector {
59 arch_msi_vector_t arch;
60#ifdef CONFIG_PCIE_MSI_X
62 bool msix;
63#endif /* CONFIG_PCIE_MSI_X */
64};
65
66typedef struct msi_vector msi_vector_t;
67
68#ifdef CONFIG_PCIE_MSI_MULTI_VECTOR
69
80extern uint8_t pcie_msi_vectors_allocate(pcie_bdf_t bdf,
81 unsigned int priority,
82 msi_vector_t *vectors,
83 uint8_t n_vector);
84
96extern bool pcie_msi_vector_connect(pcie_bdf_t bdf,
97 msi_vector_t *vector,
98 void (*routine)(const void *parameter),
99 const void *parameter,
101
102#endif /* CONFIG_PCIE_MSI_MULTI_VECTOR */
103
114extern uint32_t pcie_msi_map(unsigned int irq,
115 msi_vector_t *vector,
116 uint8_t n_vector);
117
127extern uint16_t pcie_msi_mdr(unsigned int irq,
128 msi_vector_t *vector);
129
140 msi_vector_t *vectors,
141 uint8_t n_vector,
142 unsigned int irq);
143
151
152/*
153 * The first word of the MSI capability is shared with the
154 * capability ID and list link. The high 16 bits are the MCR.
155 */
156
157#define PCIE_MSI_MCR 0U
158
159#define PCIE_MSI_MCR_EN 0x00010000U /* enable MSI */
160#define PCIE_MSI_MCR_MMC 0x000E0000U /* Multi Messages Capable mask */
161#define PCIE_MSI_MCR_MMC_SHIFT 17
162#define PCIE_MSI_MCR_MME 0x00700000U /* mask of # of enabled IRQs */
163#define PCIE_MSI_MCR_MME_SHIFT 20
164#define PCIE_MSI_MCR_64 0x00800000U /* 64-bit MSI */
165
166/*
167 * The MAP follows the MCR. If PCIE_MSI_MCR_64, then the MAP
168 * is two words long. The MDR follows immediately after the MAP.
169 */
170
171#define PCIE_MSI_MAP0 1U
172#define PCIE_MSI_MAP1_64 2U
173#define PCIE_MSI_MDR_32 2U
174#define PCIE_MSI_MDR_64 3U
175
176/*
177 * As for MSI, he first word of the MSI-X capability is shared
178 * with the capability ID and list link. The high 16 bits are the MCR.
179 */
180
181#define PCIE_MSIX_MCR 0U
182
183#define PCIE_MSIX_MCR_EN 0x80000000U /* Enable MSI-X */
184#define PCIE_MSIX_MCR_FMASK 0x40000000U /* Function Mask */
185#define PCIE_MSIX_MCR_TSIZE 0x07FF0000U /* Table size mask */
186#define PCIE_MSIX_MCR_TSIZE_SHIFT 16
187#define PCIE_MSIR_TABLE_ENTRY_SIZE 16
188
189#define PCIE_MSIX_TR 1U
190#define PCIE_MSIX_TR_BIR 0x00000007U /* Table BIR mask */
191#define PCIE_MSIX_TR_OFFSET 0xFFFFFFF8U /* Offset mask */
192
193#define PCIE_MSIX_PBA 2U
194#define PCIE_MSIX_PBA_BIR 0x00000007U /* PBA BIR mask */
195#define PCIE_MSIX_PBA_OFFSET 0xFFFFFFF8U /* Offset mask */
196
197#define PCIE_VTBL_MA 0U /* Msg Address offset */
198#define PCIE_VTBL_MUA 4U /* Msg Upper Address offset */
199#define PCIE_VTBL_MD 8U /* Msg Data offset */
200#define PCIE_VTBL_VCTRL 12U /* Vector control offset */
201
202#ifdef __cplusplus
203}
204#endif
205
209
210#endif /* ZEPHYR_INCLUDE_DRIVERS_PCIE_MSI_H_ */
Header file for the PCIe driver APIs.
uint32_t pcie_bdf_t
A unique PCI(e) endpoint (bus, device, function).
Definition pcie.h:48
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.
struct msi_vector msi_vector_t
Definition msi.h:66
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.
Public kernel APIs.
flags
Definition parser.h:97
__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:57
pcie_bdf_t bdf
Definition msi.h:58
arch_msi_vector_t arch
Definition msi.h:59
Definition msi.h:50
uint32_t msg_addr
Definition msi.h:51
uint32_t msg_up_addr
Definition msi.h:52
uint32_t vector_ctrl
Definition msi.h:54
uint32_t msg_data
Definition msi.h:53