Zephyr API Documentation 4.0.0-rc3
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
pcie_ep.h
Go to the documentation of this file.
1
7/*
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Copyright 2020 Broadcom
11 *
12 */
13#ifndef ZEPHYR_INCLUDE_DRIVERS_PCIE_EP_H_
14#define ZEPHYR_INCLUDE_DRIVERS_PCIE_EP_H_
15
16#include <zephyr/device.h>
17#include <zephyr/init.h>
18#include <zephyr/kernel.h>
19#include <stdint.h>
20
26
32
37
44
57typedef void (*pcie_ep_reset_callback_t)(void *arg);
58
59__subsystem struct pcie_ep_driver_api {
60 int (*conf_read)(const struct device *dev, uint32_t offset,
61 uint32_t *data);
62 void (*conf_write)(const struct device *dev, uint32_t offset,
63 uint32_t data);
64 int (*map_addr)(const struct device *dev, uint64_t pcie_addr,
65 uint64_t *mapped_addr, uint32_t size,
66 enum pcie_ob_mem_type ob_mem_type);
67 void (*unmap_addr)(const struct device *dev, uint64_t mapped_addr);
68 int (*raise_irq)(const struct device *dev,
69 enum pci_ep_irq_type irq_type,
70 uint32_t irq_num);
71 int (*register_reset_cb)(const struct device *dev,
72 enum pcie_reset reset,
73 pcie_ep_reset_callback_t cb, void *arg);
74 int (*dma_xfer)(const struct device *dev, uint64_t mapped_addr,
75 uintptr_t local_addr, uint32_t size,
76 enum xfer_direction dir);
77};
78
91static inline int pcie_ep_conf_read(const struct device *dev,
92 uint32_t offset, uint32_t *data)
93{
94 const struct pcie_ep_driver_api *api =
95 (const struct pcie_ep_driver_api *)dev->api;
96
97 return api->conf_read(dev, offset, data);
98}
99
110static inline void pcie_ep_conf_write(const struct device *dev,
111 uint32_t offset, uint32_t data)
112{
113 const struct pcie_ep_driver_api *api =
114 (const struct pcie_ep_driver_api *)dev->api;
115
116 api->conf_write(dev, offset, data);
117}
118
144static inline int pcie_ep_map_addr(const struct device *dev,
145 uint64_t pcie_addr,
146 uint64_t *mapped_addr, uint32_t size,
147 enum pcie_ob_mem_type ob_mem_type)
148{
149 const struct pcie_ep_driver_api *api =
150 (const struct pcie_ep_driver_api *)dev->api;
151
152 return api->map_addr(dev, pcie_addr, mapped_addr, size, ob_mem_type);
153}
154
166static inline void pcie_ep_unmap_addr(const struct device *dev,
167 uint64_t mapped_addr)
168{
169 const struct pcie_ep_driver_api *api =
170 (const struct pcie_ep_driver_api *)dev->api;
171
172 api->unmap_addr(dev, mapped_addr);
173}
174
187static inline int pcie_ep_raise_irq(const struct device *dev,
188 enum pci_ep_irq_type irq_type,
189 uint32_t irq_num)
190{
191 const struct pcie_ep_driver_api *api =
192 (const struct pcie_ep_driver_api *)dev->api;
193 return api->raise_irq(dev, irq_type, irq_num);
194}
195
211static inline int pcie_ep_register_reset_cb(const struct device *dev,
212 enum pcie_reset reset,
214 void *arg)
215{
216 const struct pcie_ep_driver_api *api =
217 (const struct pcie_ep_driver_api *)dev->api;
218
219 if (api->register_reset_cb) {
220 return api->register_reset_cb(dev, reset, cb, arg);
221 }
222
223 return -ENOTSUP;
224}
225
246static inline int pcie_ep_dma_xfer(const struct device *dev,
247 uint64_t mapped_addr,
248 uintptr_t local_addr, uint32_t size,
249 const enum xfer_direction dir)
250{
251 const struct pcie_ep_driver_api *api =
252 (const struct pcie_ep_driver_api *)dev->api;
253
254 if (api->dma_xfer) {
255 return api->dma_xfer(dev, mapped_addr, local_addr, size, dir);
256 }
257
258 return -ENOTSUP;
259}
260
279int pcie_ep_xfer_data_memcpy(const struct device *dev, uint64_t pcie_addr,
280 uintptr_t *local_addr, uint32_t size,
281 enum pcie_ob_mem_type ob_mem_type,
282 enum xfer_direction dir);
283
301int pcie_ep_xfer_data_dma(const struct device *dev, uint64_t pcie_addr,
302 uintptr_t *local_addr, uint32_t size,
303 enum pcie_ob_mem_type ob_mem_type,
304 enum xfer_direction dir);
305
306#endif /* ZEPHYR_INCLUDE_DRIVERS_PCIE_EP_H_ */
#define ENOTSUP
Unsupported value.
Definition errno.h:114
Public kernel APIs.
static void pcie_ep_unmap_addr(const struct device *dev, uint64_t mapped_addr)
Remove mapping to PCIe outbound region.
Definition pcie_ep.h:166
static int pcie_ep_register_reset_cb(const struct device *dev, enum pcie_reset reset, pcie_ep_reset_callback_t cb, void *arg)
Register callback function for reset interrupts.
Definition pcie_ep.h:211
pcie_reset
Definition pcie_ep.h:38
@ PCIE_RESET_MAX
Definition pcie_ep.h:42
@ PCIE_PERST
Cold reset.
Definition pcie_ep.h:39
@ PCIE_FLR
Functional Level Reset.
Definition pcie_ep.h:41
@ PCIE_PERST_INB
Inband hot reset.
Definition pcie_ep.h:40
static int pcie_ep_map_addr(const struct device *dev, uint64_t pcie_addr, uint64_t *mapped_addr, uint32_t size, enum pcie_ob_mem_type ob_mem_type)
Map a host memory buffer to PCIe outbound region.
Definition pcie_ep.h:144
static int pcie_ep_dma_xfer(const struct device *dev, uint64_t mapped_addr, uintptr_t local_addr, uint32_t size, const enum xfer_direction dir)
Data transfer between mapped Host memory and device memory with "System DMA".
Definition pcie_ep.h:246
static void pcie_ep_conf_write(const struct device *dev, uint32_t offset, uint32_t data)
Write PCIe EP configuration space.
Definition pcie_ep.h:110
pcie_ob_mem_type
Definition pcie_ep.h:21
@ PCIE_OB_HIGHMEM
PCIe OB window above 32-bit address range.
Definition pcie_ep.h:24
@ PCIE_OB_ANYMEM
PCIe OB window within any address range.
Definition pcie_ep.h:22
@ PCIE_OB_LOWMEM
PCIe OB window within 32-bit address range.
Definition pcie_ep.h:23
pci_ep_irq_type
Definition pcie_ep.h:27
@ PCIE_EP_IRQ_MSI
Raise MSI interrupt.
Definition pcie_ep.h:29
@ PCIE_EP_IRQ_MSIX
Raise MSIX interrupt.
Definition pcie_ep.h:30
@ PCIE_EP_IRQ_LEGACY
Raise Legacy interrupt.
Definition pcie_ep.h:28
int pcie_ep_xfer_data_memcpy(const struct device *dev, uint64_t pcie_addr, uintptr_t *local_addr, uint32_t size, enum pcie_ob_mem_type ob_mem_type, enum xfer_direction dir)
Data transfer using memcpy.
xfer_direction
Definition pcie_ep.h:33
@ DEVICE_TO_HOST
Write to Host.
Definition pcie_ep.h:35
@ HOST_TO_DEVICE
Read from Host.
Definition pcie_ep.h:34
int pcie_ep_xfer_data_dma(const struct device *dev, uint64_t pcie_addr, uintptr_t *local_addr, uint32_t size, enum pcie_ob_mem_type ob_mem_type, enum xfer_direction dir)
Data transfer using system DMA.
static int pcie_ep_conf_read(const struct device *dev, uint32_t offset, uint32_t *data)
Read PCIe EP configuration space.
Definition pcie_ep.h:91
static int pcie_ep_raise_irq(const struct device *dev, enum pci_ep_irq_type irq_type, uint32_t irq_num)
Raise interrupt to Host.
Definition pcie_ep.h:187
void(* pcie_ep_reset_callback_t)(void *arg)
Callback API for PCIe reset interrupts.
Definition pcie_ep.h:57
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
void * data
Address of the device instance private data.
Definition device.h:422
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:418
Definition pcie_ep.h:59
int(* map_addr)(const struct device *dev, uint64_t pcie_addr, uint64_t *mapped_addr, uint32_t size, enum pcie_ob_mem_type ob_mem_type)
Definition pcie_ep.h:64
void(* unmap_addr)(const struct device *dev, uint64_t mapped_addr)
Definition pcie_ep.h:67
int(* raise_irq)(const struct device *dev, enum pci_ep_irq_type irq_type, uint32_t irq_num)
Definition pcie_ep.h:68
int(* conf_read)(const struct device *dev, uint32_t offset, uint32_t *data)
Definition pcie_ep.h:60
int(* dma_xfer)(const struct device *dev, uint64_t mapped_addr, uintptr_t local_addr, uint32_t size, enum xfer_direction dir)
Definition pcie_ep.h:74
void(* conf_write)(const struct device *dev, uint32_t offset, uint32_t data)
Definition pcie_ep.h:62
int(* register_reset_cb)(const struct device *dev, enum pcie_reset reset, pcie_ep_reset_callback_t cb, void *arg)
Definition pcie_ep.h:71