diff options
Diffstat (limited to 'include/dm')
-rw-r--r-- | include/dm/device.h | 13 | ||||
-rw-r--r-- | include/dm/of_addr.h | 17 | ||||
-rw-r--r-- | include/dm/ofnode.h | 16 | ||||
-rw-r--r-- | include/dm/read.h | 21 |
4 files changed, 67 insertions, 0 deletions
diff --git a/include/dm/device.h b/include/dm/device.h index 28533ce0b6..bb9faa0ed9 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -159,6 +159,8 @@ enum { * When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will * add to this list. Memory so-allocated will be freed * automatically when the device is removed / unbound + * @dma_offset: Offset between the physical address space (CPU's) and the + * device's bus address space */ struct udevice { const struct driver *driver; @@ -183,6 +185,9 @@ struct udevice { #ifdef CONFIG_DEVRES struct list_head devres_head; #endif +#if CONFIG_IS_ENABLED(DM_DMA) + ulong dma_offset; +#endif }; /* Maximum sequence number supported */ @@ -224,6 +229,14 @@ static inline ofnode dev_ofnode(const struct udevice *dev) /* Returns non-zero if the device is active (probed and not removed) */ #define device_active(dev) (dev_get_flags(dev) & DM_FLAG_ACTIVATED) +#if CONFIG_IS_ENABLED(DM_DMA) +#define dev_set_dma_offset(_dev, _offset) _dev->dma_offset = _offset +#define dev_get_dma_offset(_dev) _dev->dma_offset +#else +#define dev_set_dma_offset(_dev, _offset) +#define dev_get_dma_offset(_dev) 0 +#endif + static inline int dev_of_offset(const struct udevice *dev) { #if !CONFIG_IS_ENABLED(OF_PLATDATA) diff --git a/include/dm/of_addr.h b/include/dm/of_addr.h index 3fa1ffce81..ee21d5cf4f 100644 --- a/include/dm/of_addr.h +++ b/include/dm/of_addr.h @@ -44,6 +44,23 @@ u64 of_translate_address(const struct device_node *no, const __be32 *in_addr); */ u64 of_translate_dma_address(const struct device_node *no, const __be32 *in_addr); + +/** + * of_get_dma_range() - get dma-ranges for a specific DT node + * + * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and + * cpu->bus address translations + * + * @param blob Pointer to device tree blob + * @param node_offset Node DT offset + * @param cpu Pointer to variable storing the range's cpu address + * @param bus Pointer to variable storing the range's bus address + * @param size Pointer to variable storing the range's size + * @return translated DMA address or OF_BAD_ADDR on error + */ +int of_get_dma_range(const struct device_node *dev, phys_addr_t *cpu, + dma_addr_t *bus, u64 *size); + /** * of_get_address() - obtain an address from a node * diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 5318d65035..2c0597c407 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -999,6 +999,22 @@ u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr); u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr); /** + * ofnode_get_dma_range() - get dma-ranges for a specific DT node + * + * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and + * cpu->bus address translations + * + * @param blob Pointer to device tree blob + * @param node_offset Node DT offset + * @param cpu Pointer to variable storing the range's cpu address + * @param bus Pointer to variable storing the range's bus address + * @param size Pointer to variable storing the range's size + * @return translated DMA address or OF_BAD_ADDR on error + */ +int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus, + u64 *size); + +/** * ofnode_device_is_compatible() - check if the node is compatible with compat * * This allows to check whether the node is comaptible with the compat. diff --git a/include/dm/read.h b/include/dm/read.h index 97575bcad0..5bf3405614 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -648,6 +648,21 @@ u64 dev_translate_dma_address(const struct udevice *dev, const fdt32_t *in_addr); /** + * dev_get_dma_range() - Get a device's DMA constraints + * + * Provide the address bases and size of the linear mapping between the CPU and + * a device's BUS address space. + * + * @dev: device giving the context in which to translate the DMA address + * @cpu: base address for CPU's view of memory + * @bus: base address for BUS's view of memory + * @size: size of the address space + * @return 0 if ok, negative on error + */ +int dev_get_dma_range(const struct udevice *dev, phys_addr_t *cpu, + dma_addr_t *bus, u64 *size); + +/** * dev_read_alias_highest_id - Get highest alias id for the given stem * @stem: Alias stem to be examined * @@ -1005,6 +1020,12 @@ static inline u64 dev_translate_dma_address(const struct udevice *dev, return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); } +static inline int dev_get_dma_range(const struct udevice *dev, phys_addr_t *cpu, + dma_addr_t *bus, u64 *size) +{ + return ofnode_get_dma_range(dev_ofnode(dev), cpu, bus, size); +} + static inline int dev_read_alias_highest_id(const char *stem) { if (!CONFIG_IS_ENABLED(OF_LIBFDT) || !gd->fdt_blob) |