Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
controller.h
Go to the documentation of this file.
1
7
8/*
9 * Copyright (c) 2021 BayLibre, SAS
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13#ifndef ZEPHYR_INCLUDE_DRIVERS_PCIE_CONTROLLERS_H_
14#define ZEPHYR_INCLUDE_DRIVERS_PCIE_CONTROLLERS_H_
15
16#include <zephyr/types.h>
17#include <zephyr/device.h>
19
20#ifdef CONFIG_PCIE_MSI
22#endif
23
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
40
52typedef uint32_t (*pcie_ctrl_conf_read_t)(const struct device *dev, pcie_bdf_t bdf,
53 unsigned int reg);
54
66typedef void (*pcie_ctrl_conf_write_t)(const struct device *dev, pcie_bdf_t bdf,
67 unsigned int reg, uint32_t data);
68
86typedef bool (*pcie_ctrl_region_allocate_t)(const struct device *dev, pcie_bdf_t bdf,
87 bool mem, bool mem64, size_t bar_size,
88 uintptr_t *bar_bus_addr);
89
106 bool mem, bool mem64, size_t align,
107 uintptr_t *bar_base_addr);
108
128typedef bool (*pcie_ctrl_region_translate_t)(const struct device *dev, pcie_bdf_t bdf,
129 bool mem, bool mem64, uintptr_t bar_bus_addr,
130 uintptr_t *bar_addr);
131
132#ifdef CONFIG_PCIE_MSI
133typedef uint8_t (*pcie_ctrl_msi_device_setup_t)(const struct device *dev, unsigned int priority,
134 msi_vector_t *vectors, uint8_t n_vector);
135#endif
136
150
151
165 unsigned int reg, uint32_t data);
166
177void pcie_generic_ctrl_enumerate(const struct device *dev, pcie_bdf_t bdf_start);
178
201
203
215static inline uint32_t pcie_ctrl_conf_read(const struct device *dev, pcie_bdf_t bdf,
216 unsigned int reg)
217{
218 return DEVICE_API_GET(pcie_ctrl, dev)->conf_read(dev, bdf, reg);
219}
220
232static inline void pcie_ctrl_conf_write(const struct device *dev, pcie_bdf_t bdf,
233 unsigned int reg, uint32_t data)
234{
235 DEVICE_API_GET(pcie_ctrl, dev)->conf_write(dev, bdf, reg, data);
236}
237
255static inline bool pcie_ctrl_region_allocate(const struct device *dev, pcie_bdf_t bdf,
256 bool mem, bool mem64, size_t bar_size,
257 uintptr_t *bar_bus_addr)
258{
259 return DEVICE_API_GET(pcie_ctrl, dev)->region_allocate(dev, bdf, mem, mem64, bar_size,
260 bar_bus_addr);
261}
262
278static inline bool pcie_ctrl_region_get_allocate_base(const struct device *dev, pcie_bdf_t bdf,
279 bool mem, bool mem64, size_t align,
280 uintptr_t *bar_base_addr)
281{
282 return DEVICE_API_GET(pcie_ctrl, dev)->region_get_allocate_base(dev, bdf, mem, mem64, align,
283 bar_base_addr);
284}
285
304static inline bool pcie_ctrl_region_translate(const struct device *dev, pcie_bdf_t bdf,
305 bool mem, bool mem64, uintptr_t bar_bus_addr,
306 uintptr_t *bar_addr)
307{
308 const struct pcie_ctrl_driver_api *api = DEVICE_API_GET(pcie_ctrl, dev);
309
310 if (!api->region_translate) {
311 *bar_addr = bar_bus_addr;
312 return true;
313 } else {
314 return api->region_translate(dev, bdf, mem, mem64, bar_bus_addr, bar_addr);
315 }
316}
317
318#if defined(CONFIG_PCIE_MSI) || defined(__DOXYGEN__)
330static inline uint8_t pcie_ctrl_msi_device_setup(const struct device *dev, unsigned int priority,
331 msi_vector_t *vectors, uint8_t n_vector)
332{
333 return DEVICE_API_GET(pcie_ctrl, dev)->msi_device_setup(dev, priority, vectors, n_vector);
334}
335#endif
336
340#if defined(CONFIG_PCIE_MSI) || defined(__DOXYGEN__)
345 const struct device *msi_parent;
346#endif
350 size_t cfg_size;
354 struct {
364};
365
375#define PCIE_RANGE_FORMAT(node_id, idx) \
376{ \
377 .flags = DT_RANGES_CHILD_BUS_FLAGS_BY_IDX(node_id, idx), \
378 .pcie_bus_addr = DT_RANGES_CHILD_BUS_ADDRESS_BY_IDX(node_id, idx), \
379 .host_map_addr = DT_RANGES_PARENT_BUS_ADDRESS_BY_IDX(node_id, idx), \
380 .map_length = DT_RANGES_LENGTH_BY_IDX(node_id, idx), \
381},
382
383#ifdef __cplusplus
384}
385#endif
386
390
391#endif /* ZEPHYR_INCLUDE_DRIVERS_PCIE_CONTROLLERS_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1449
Header file for the PCIe driver APIs.
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:66
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:86
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:105
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:128
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:52
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:215
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:255
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:232
static uint8_t pcie_ctrl_msi_device_setup(const struct device *dev, unsigned int priority, msi_vector_t *vectors, uint8_t n_vector)
Configure the given PCI endpoint to generate MSIs.
Definition controller.h:330
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:304
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:278
uint32_t pcie_bdf_t
A unique PCI(e) endpoint (bus, device, function).
Definition pcie.h:48
struct msi_vector msi_vector_t
Definition msi.h:66
uintptr_t mm_reg_t
Memory-mapped register address.
Definition sys_io.h:40
Header file for the PCIe MSI and MSI-X support APIs.
#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:513
void * data
Address of the device instance private data.
Definition device.h:523
Structure describing a device that supports the PCI Express Controller API.
Definition controller.h:339
struct pcie_ctrl_config::@233346376111331064333012004165050322010071233050 ranges[]
BAR regions translation ranges table.
uintptr_t cfg_addr
Configuration space physical address.
Definition controller.h:348
uintptr_t pcie_bus_addr
bus-centric offset from the start of the region
Definition controller.h:358
size_t ranges_count
BAR regions translation ranges count.
Definition controller.h:352
const struct device * msi_parent
MSI parent device.
Definition controller.h:345
uint32_t flags
Flags as defined in the PCI Bus Binding to IEEE Std 1275-1994.
Definition controller.h:356
uintptr_t host_map_addr
CPU-centric offset from the start of the region.
Definition controller.h:360
size_t cfg_size
Configuration space physical size.
Definition controller.h:350
size_t map_length
region size
Definition controller.h:362
<span class="mlabel">Driver Operations</span> PCIe Controller driver operations
Definition controller.h:182
pcie_ctrl_msi_device_setup_t msi_device_setup
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition controller.h:198
pcie_ctrl_conf_read_t conf_read
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition controller.h:184
pcie_ctrl_region_allocate_t region_allocate
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition controller.h:188
pcie_ctrl_conf_write_t conf_write
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition controller.h:186
pcie_ctrl_region_get_allocate_base_t region_get_allocate_base
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition controller.h:190
pcie_ctrl_region_translate_t region_translate
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition controller.h:192