Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
controller.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2021 BayLibre, SAS
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12#ifndef ZEPHYR_INCLUDE_DRIVERS_PCIE_CONTROLLERS_H_
13#define ZEPHYR_INCLUDE_DRIVERS_PCIE_CONTROLLERS_H_
14
15#include <zephyr/types.h>
16#include <device.h>
17
25#ifdef __cplusplus
26extern "C" {
27#endif
28
40typedef uint32_t (*pcie_ctrl_conf_read_t)(const struct device *dev, pcie_bdf_t bdf,
41 unsigned int reg);
42
54typedef void (*pcie_ctrl_conf_write_t)(const struct device *dev, pcie_bdf_t bdf,
55 unsigned int reg, uint32_t data);
56
74typedef bool (*pcie_ctrl_region_allocate_t)(const struct device *dev, pcie_bdf_t bdf,
75 bool mem, bool mem64, size_t bar_size,
76 uintptr_t *bar_bus_addr);
77
94 bool mem, bool mem64, size_t align,
95 uintptr_t *bar_base_addr);
96
116typedef bool (*pcie_ctrl_region_translate_t)(const struct device *dev, pcie_bdf_t bdf,
117 bool mem, bool mem64, uintptr_t bar_bus_addr,
118 uintptr_t *bar_addr);
119
133
134
148 unsigned int reg, uint32_t data);
149
160void pcie_generic_ctrl_enumerate(const struct device *dev, pcie_bdf_t bdf_start);
161
165__subsystem struct pcie_ctrl_driver_api {
171};
172
184static inline uint32_t pcie_ctrl_conf_read(const struct device *dev, pcie_bdf_t bdf,
185 unsigned int reg)
186{
187 const struct pcie_ctrl_driver_api *api =
188 (const struct pcie_ctrl_driver_api *)dev->api;
189
190 return api->conf_read(dev, bdf, reg);
191}
192
204static inline void pcie_ctrl_conf_write(const struct device *dev, pcie_bdf_t bdf,
205 unsigned int reg, uint32_t data)
206{
207 const struct pcie_ctrl_driver_api *api =
208 (const struct pcie_ctrl_driver_api *)dev->api;
209
210 api->conf_write(dev, bdf, reg, data);
211}
212
230static inline bool pcie_ctrl_region_allocate(const struct device *dev, pcie_bdf_t bdf,
231 bool mem, bool mem64, size_t bar_size,
232 uintptr_t *bar_bus_addr)
233{
234 const struct pcie_ctrl_driver_api *api =
235 (const struct pcie_ctrl_driver_api *)dev->api;
236
237 return api->region_allocate(dev, bdf, mem, mem64, bar_size, bar_bus_addr);
238}
239
255static inline bool pcie_ctrl_region_get_allocate_base(const struct device *dev, pcie_bdf_t bdf,
256 bool mem, bool mem64, size_t align,
257 uintptr_t *bar_base_addr)
258{
259 const struct pcie_ctrl_driver_api *api =
260 (const struct pcie_ctrl_driver_api *)dev->api;
261
262 return api->region_get_allocate_base(dev, bdf, mem, mem64, align, bar_base_addr);
263}
264
283static inline bool pcie_ctrl_region_translate(const struct device *dev, pcie_bdf_t bdf,
284 bool mem, bool mem64, uintptr_t bar_bus_addr,
285 uintptr_t *bar_addr)
286{
287 const struct pcie_ctrl_driver_api *api =
288 (const struct pcie_ctrl_driver_api *)dev->api;
289
290 if (!api->region_translate) {
291 *bar_addr = bar_bus_addr;
292 return true;
293 } else {
294 return api->region_translate(dev, bdf, mem, mem64, bar_bus_addr, bar_addr);
295 }
296}
297
301 /* Configuration space physical address */
303 /* Configuration space physical size */
304 size_t cfg_size;
305 /* BAR regions translation ranges count */
307 /* BAR regions translation ranges table */
308 struct {
309 /* Flags as defined in the PCI Bus Binding to IEEE Std 1275-1994 */
311 /* bus-centric offset from the start of the region */
313 /* CPU-centric offset from the start of the region */
315 /* region size */
318};
319
320/*
321 * Fills the pcie_ctrl_config.ranges table from DT
322 */
323#define PCIE_RANGE_FORMAT(node_id, idx) \
324{ \
325 .flags = DT_RANGES_CHILD_BUS_FLAGS_BY_IDX(node_id, idx), \
326 .pcie_bus_addr = DT_RANGES_CHILD_BUS_ADDRESS_BY_IDX(node_id, idx), \
327 .host_map_addr = DT_RANGES_PARENT_BUS_ADDRESS_BY_IDX(node_id, idx), \
328 .map_length = DT_RANGES_LENGTH_BY_IDX(node_id, idx), \
329},
330
331#ifdef __cplusplus
332}
333#endif
334
339#endif /* ZEPHYR_INCLUDE_DRIVERS_PCIE_CONTROLLERS_H_ */
uint32_t pcie_bdf_t
A unique PCI(e) endpoint (bus, device, function).
Definition: pcie.h:27
static uint32_t pcie_ctrl_conf_read(const struct device *dev, pcie_bdf_t bdf, unsigned int reg)
Read a 32-bit word from an endpoint's configuration space.
Definition: controller.h:184
static bool pcie_ctrl_region_allocate(const struct device *dev, pcie_bdf_t bdf, bool mem, bool mem64, size_t bar_size, uintptr_t *bar_bus_addr)
Allocate a memory region subset for an endpoint Base Address Register.
Definition: controller.h:230
void(* pcie_ctrl_conf_write_t)(const struct device *dev, pcie_bdf_t bdf, unsigned int reg, uint32_t data)
Function called to write a 32-bit word to an endpoint's configuration space.
Definition: controller.h:54
static void pcie_ctrl_conf_write(const struct device *dev, pcie_bdf_t bdf, unsigned int reg, uint32_t data)
Write a 32-bit word to an endpoint's configuration space.
Definition: controller.h:204
bool(* pcie_ctrl_region_allocate_t)(const struct device *dev, pcie_bdf_t bdf, bool mem, bool mem64, size_t bar_size, uintptr_t *bar_bus_addr)
Function called to allocate a memory region subset for an endpoint Base Address Register.
Definition: controller.h:74
void pcie_generic_ctrl_conf_write(mm_reg_t cfg_addr, pcie_bdf_t bdf, unsigned int reg, uint32_t data)
Write a 32-bit word to a Memory-Mapped endpoint's configuration space.
void pcie_generic_ctrl_enumerate(const struct device *dev, pcie_bdf_t bdf_start)
Start PCIe Endpoints enumeration.
uint32_t pcie_generic_ctrl_conf_read(mm_reg_t cfg_addr, pcie_bdf_t bdf, unsigned int reg)
Read a 32-bit word from a Memory-Mapped endpoint's configuration space.
bool(* pcie_ctrl_region_get_allocate_base_t)(const struct device *dev, pcie_bdf_t bdf, bool mem, bool mem64, size_t align, uintptr_t *bar_base_addr)
Function called to get the current allocation base of a memory region subset for an endpoint Base Add...
Definition: controller.h:93
bool(* pcie_ctrl_region_translate_t)(const struct device *dev, pcie_bdf_t bdf, bool mem, bool mem64, uintptr_t bar_bus_addr, uintptr_t *bar_addr)
Function called to translate an endpoint Base Address Register bus-centric address into Physical addr...
Definition: controller.h:116
uint32_t(* pcie_ctrl_conf_read_t)(const struct device *dev, pcie_bdf_t bdf, unsigned int reg)
Function called to read a 32-bit word from an endpoint's configuration space.
Definition: controller.h:40
static bool pcie_ctrl_region_translate(const struct device *dev, pcie_bdf_t bdf, bool mem, bool mem64, uintptr_t bar_bus_addr, uintptr_t *bar_addr)
Translate an endpoint Base Address Register bus-centric address into Physical address.
Definition: controller.h:283
static bool pcie_ctrl_region_get_allocate_base(const struct device *dev, pcie_bdf_t bdf, bool mem, bool mem64, size_t align, uintptr_t *bar_base_addr)
Function called to get the current allocation base of a memory region subset for an endpoint Base Add...
Definition: controller.h:255
struct shared_multi_heap_region * reg
Definition: main.c:17
#define bool
Definition: stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:75
Runtime device structure (in ROM) per driver instance.
Definition: device.h:450
const void * api
Definition: device.h:456
Structure describing a device that supports the PCI Express Controller API.
Definition: controller.h:300
uintptr_t cfg_addr
Definition: controller.h:302
uintptr_t pcie_bus_addr
Definition: controller.h:312
size_t ranges_count
Definition: controller.h:306
uint32_t flags
Definition: controller.h:310
struct pcie_ctrl_config::@113 ranges[]
uintptr_t host_map_addr
Definition: controller.h:314
size_t cfg_size
Definition: controller.h:304
size_t map_length
Definition: controller.h:316
Structure providing callbacks to be implemented for devices that supports the PCI Express Controller ...
Definition: controller.h:165
pcie_ctrl_conf_read_t conf_read
Definition: controller.h:166
pcie_ctrl_region_allocate_t region_allocate
Definition: controller.h:168
pcie_ctrl_conf_write_t conf_write
Definition: controller.h:167
pcie_ctrl_region_get_allocate_base_t region_get_allocate_base
Definition: controller.h:169
pcie_ctrl_region_translate_t region_translate
Definition: controller.h:170
uintptr_t mm_reg_t
Definition: sys_io.h:20
static fdata_t data[2]
Definition: test_fifo_contexts.c:15