Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
 4.2.99
controller.h
Go to the documentation of this file.
1
6
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 <zephyr/device.h>
18
19#ifdef CONFIG_PCIE_MSI
21#endif
22
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
45typedef uint32_t (*pcie_ctrl_conf_read_t)(const struct device *dev, pcie_bdf_t bdf,
46 unsigned int reg);
47
59typedef void (*pcie_ctrl_conf_write_t)(const struct device *dev, pcie_bdf_t bdf,
60 unsigned int reg, uint32_t data);
61
79typedef bool (*pcie_ctrl_region_allocate_t)(const struct device *dev, pcie_bdf_t bdf,
80 bool mem, bool mem64, size_t bar_size,
81 uintptr_t *bar_bus_addr);
82
99 bool mem, bool mem64, size_t align,
100 uintptr_t *bar_base_addr);
101
121typedef bool (*pcie_ctrl_region_translate_t)(const struct device *dev, pcie_bdf_t bdf,
122 bool mem, bool mem64, uintptr_t bar_bus_addr,
123 uintptr_t *bar_addr);
124
125#ifdef CONFIG_PCIE_MSI
126typedef uint8_t (*pcie_ctrl_msi_device_setup_t)(const struct device *dev, unsigned int priority,
127 msi_vector_t *vectors, uint8_t n_vector);
128#endif
129
143
144
158 unsigned int reg, uint32_t data);
159
170void pcie_generic_ctrl_enumerate(const struct device *dev, pcie_bdf_t bdf_start);
171
185
197static inline uint32_t pcie_ctrl_conf_read(const struct device *dev, pcie_bdf_t bdf,
198 unsigned int reg)
199{
200 const struct pcie_ctrl_driver_api *api =
201 (const struct pcie_ctrl_driver_api *)dev->api;
202
203 return api->conf_read(dev, bdf, reg);
204}
205
217static inline void pcie_ctrl_conf_write(const struct device *dev, pcie_bdf_t bdf,
218 unsigned int reg, uint32_t data)
219{
220 const struct pcie_ctrl_driver_api *api =
221 (const struct pcie_ctrl_driver_api *)dev->api;
222
223 api->conf_write(dev, bdf, reg, data);
224}
225
243static inline bool pcie_ctrl_region_allocate(const struct device *dev, pcie_bdf_t bdf,
244 bool mem, bool mem64, size_t bar_size,
245 uintptr_t *bar_bus_addr)
246{
247 const struct pcie_ctrl_driver_api *api =
248 (const struct pcie_ctrl_driver_api *)dev->api;
249
250 return api->region_allocate(dev, bdf, mem, mem64, bar_size, bar_bus_addr);
251}
252
268static inline bool pcie_ctrl_region_get_allocate_base(const struct device *dev, pcie_bdf_t bdf,
269 bool mem, bool mem64, size_t align,
270 uintptr_t *bar_base_addr)
271{
272 const struct pcie_ctrl_driver_api *api =
273 (const struct pcie_ctrl_driver_api *)dev->api;
274
275 return api->region_get_allocate_base(dev, bdf, mem, mem64, align, bar_base_addr);
276}
277
296static inline bool pcie_ctrl_region_translate(const struct device *dev, pcie_bdf_t bdf,
297 bool mem, bool mem64, uintptr_t bar_bus_addr,
298 uintptr_t *bar_addr)
299{
300 const struct pcie_ctrl_driver_api *api =
301 (const struct pcie_ctrl_driver_api *)dev->api;
302
303 if (!api->region_translate) {
304 *bar_addr = bar_bus_addr;
305 return true;
306 } else {
307 return api->region_translate(dev, bdf, mem, mem64, bar_bus_addr, bar_addr);
308 }
309}
310
311#ifdef CONFIG_PCIE_MSI
312static inline uint8_t pcie_ctrl_msi_device_setup(const struct device *dev, unsigned int priority,
313 msi_vector_t *vectors, uint8_t n_vector)
314{
315 const struct pcie_ctrl_driver_api *api =
316 (const struct pcie_ctrl_driver_api *)dev->api;
317
318 return api->msi_device_setup(dev, priority, vectors, n_vector);
319}
320#endif
321
325#ifdef CONFIG_PCIE_MSI
326 const struct device *msi_parent;
327#endif
328 /* Configuration space physical address */
330 /* Configuration space physical size */
331 size_t cfg_size;
332 /* BAR regions translation ranges count */
334 /* BAR regions translation ranges table */
335 struct {
336 /* Flags as defined in the PCI Bus Binding to IEEE Std 1275-1994 */
338 /* bus-centric offset from the start of the region */
340 /* CPU-centric offset from the start of the region */
342 /* region size */
345};
346
347/*
348 * Fills the pcie_ctrl_config.ranges table from DT
349 */
350#define PCIE_RANGE_FORMAT(node_id, idx) \
351{ \
352 .flags = DT_RANGES_CHILD_BUS_FLAGS_BY_IDX(node_id, idx), \
353 .pcie_bus_addr = DT_RANGES_CHILD_BUS_ADDRESS_BY_IDX(node_id, idx), \
354 .host_map_addr = DT_RANGES_PARENT_BUS_ADDRESS_BY_IDX(node_id, idx), \
355 .map_length = DT_RANGES_LENGTH_BY_IDX(node_id, idx), \
356},
357
358#ifdef __cplusplus
359}
360#endif
361
365
366#endif /* ZEPHYR_INCLUDE_DRIVERS_PCIE_CONTROLLERS_H_ */
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:197
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:243
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:59
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:217
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:79
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:98
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:121
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:45
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:296
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:268
uint32_t pcie_bdf_t
A unique PCI(e) endpoint (bus, device, function).
Definition pcie.h:37
struct msi_vector msi_vector_t
Definition msi.h:60
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
void * data
Address of the device instance private data.
Definition device.h:520
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
Structure describing a device that supports the PCI Express Controller API.
Definition controller.h:324
struct pcie_ctrl_config::@233346376111331064333012004165050322010071233050 ranges[]
uintptr_t cfg_addr
Definition controller.h:329
uintptr_t pcie_bus_addr
Definition controller.h:339
size_t ranges_count
Definition controller.h:333
uint32_t flags
Definition controller.h:337
uintptr_t host_map_addr
Definition controller.h:341
size_t cfg_size
Definition controller.h:331
size_t map_length
Definition controller.h:343
Structure providing callbacks to be implemented for devices that supports the PCI Express Controller ...
Definition controller.h:175
pcie_ctrl_conf_read_t conf_read
Definition controller.h:176
pcie_ctrl_region_allocate_t region_allocate
Definition controller.h:178
pcie_ctrl_conf_write_t conf_write
Definition controller.h:177
pcie_ctrl_region_get_allocate_base_t region_get_allocate_base
Definition controller.h:179
pcie_ctrl_region_translate_t region_translate
Definition controller.h:180
uintptr_t mm_reg_t
Definition sys_io.h:20