From 9ddf7033b091ee0ae57b13b6f099745f4832d186 Mon Sep 17 00:00:00 2001 From: Seokju Yoon Date: Thu, 18 Jun 2015 23:09:12 +0900 Subject: [PATCH] dma: of-dma: Support to set number of dma mask bit property. Change-Id: I329b65fa71cacddbc1be4df5bc32d142a8598c6d Signed-off-by: Seokju Yoon --- drivers/dma/of-dma.c | 147 +++++++++++++++++++++++++++++++++++++++++ drivers/dma/pl330.c | 7 +- include/linux/of_dma.h | 36 ++++++++++ 3 files changed, 189 insertions(+), 1 deletion(-) diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c index 91fd395c90c4..0a459731632f 100644 --- a/drivers/dma/of-dma.c +++ b/drivers/dma/of-dma.c @@ -227,6 +227,153 @@ static int of_dma_match_channel(struct device_node *np, const char *name, return 0; } +/** + * of_dma_get_mcode_addr - Get the DMA micro code buffer address. + * @np: device node of DMA controller + * + * Return the physical address. + */ +unsigned int of_dma_get_mcode_addr(struct device_node *np) +{ + unsigned int addr = 0; + const __be32 *prop; + + prop = of_get_property(np, "#dma-mcode-addr", NULL); + if (prop) + addr = be32_to_cpup(prop); + + return addr; +} +EXPORT_SYMBOL_GPL(of_dma_get_mcode_addr); + +/** + * of_dma_secure_dma_ch- Get the DMA micro code buffer address. + * @np: device node of DMA controller + * + * Return the physical address. + */ +bool of_dma_secure_mode(struct device_node *np) +{ + bool ret = 0; + const __be32 *prop; + + prop = of_get_property(np, "#dma-secure-mode", NULL); + if (prop) + ret = be32_to_cpup(prop); + + return ret; +} +EXPORT_SYMBOL_GPL(of_dma_secure_mode); + +/** + * of_dma_get_arwrapper_address - Get the DMA WAPPER AR address + * @np: device node of DMA controller + * @num: DMA channel thread number + * + * Return the virtual address. + */ +void __iomem *of_dma_get_arwrapper_address(struct device_node *np, unsigned int num) +{ + const __be32 *reg_list; + unsigned int length, count; + + reg_list = of_get_property(np, "dma-arwrapper", &length); + count = (unsigned int)(length / sizeof(unsigned int)); + + if (!reg_list || num >= count) + return NULL; + + return ioremap(be32_to_cpup(reg_list + num), SZ_32); +} +EXPORT_SYMBOL_GPL(of_dma_get_arwrapper_address); + +/** + * of_dma_get_arwrapper_address - Get the DMA WAPPER AW address + * @np: device node of DMA controller + * @num: DMA channel thread number + * + * Return the virtual address. + */ +void __iomem *of_dma_get_awwrapper_address(struct device_node *np, unsigned int num) +{ + const __be32 *reg_list; + unsigned int length, count; + + reg_list = of_get_property(np, "dma-awwrapper", &length); + count = (unsigned int)(length / sizeof(unsigned int)); + + if (!reg_list || num >= count) + return NULL; + + return ioremap(be32_to_cpup(reg_list + num), SZ_32); +} +EXPORT_SYMBOL_GPL(of_dma_get_awwrapper_address); + +/** + * of_dma_get_arwrapper_address - Get the DMA WAPPER AR address of DMA instruction + * @np: device node of DMA controller + * + * Return the virtual address. + */ +void __iomem *of_dma_get_instwrapper_address(struct device_node *np) +{ + const __be32 *reg_list; + int ret = 0; + + reg_list = of_get_property(np, "dma-instwrapper", NULL); + + if (!reg_list) + return NULL; + + ret = be32_to_cpup(reg_list); + if (!ret) + return NULL; + + return ioremap(ret, SZ_32); +} +EXPORT_SYMBOL_GPL(of_dma_get_instwrapper_address); + +/** + * of_dma_get_arwrapper_address - Get the DMA WAPPER availableilable + * @np: device node of DMA controller + * + */ +bool of_dma_get_wrapper_available(struct device_node *np) +{ + const __be32 *reg_list; + int ret = 0; + + reg_list = of_get_property(np, "dma-instwrapper", NULL); + + if (!reg_list) + return false; + + ret = be32_to_cpup(reg_list); + if (ret) + return true; + else + return false; +} +EXPORT_SYMBOL_GPL(of_dma_get_wrapper_available); + +/** + * of_dma_get_arwrapper_address - Get the DMA WAPPER availableilable + * @np: device node of DMA controller + * + */ +u64 of_dma_get_mask(struct device_node *np, char *name) +{ + int bit_cnt = 0; + + of_property_read_u32(np, name, &bit_cnt); + + if (bit_cnt) + return ((u64)1 << bit_cnt) - 1; + else + return -1; +} +EXPORT_SYMBOL_GPL(of_dma_get_mask); + /** * of_dma_request_slave_channel - Get the DMA slave channel * @np: device node to get DMA request from diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c index 5f5886972702..96fe56eb2c28 100644 --- a/drivers/dma/pl330.c +++ b/drivers/dma/pl330.c @@ -3050,8 +3050,13 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id) } } - if (adev->dev.of_node) + if (adev->dev.of_node){ + *adev->dev.dma_mask = of_dma_get_mask(adev->dev.of_node, + "dma-mask-bit"); + adev->dev.coherent_dma_mask = of_dma_get_mask(adev->dev.of_node, + "coherent-mask-bit"); pl330->wrapper = of_dma_get_wrapper_available(adev->dev.of_node); + } pcfg = &pl330->pcfg; diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h index b90d8ec57c1f..05d3c6114806 100644 --- a/include/linux/of_dma.h +++ b/include/linux/of_dma.h @@ -54,6 +54,13 @@ extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec, extern struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec, struct of_dma *ofdma); +extern unsigned int of_dma_get_mcode_addr(struct device_node *np); +extern bool of_dma_secure_mode(struct device_node *np); +extern void __iomem *of_dma_get_arwrapper_address(struct device_node *np, unsigned int num); +extern void __iomem *of_dma_get_awwrapper_address(struct device_node *np, unsigned int num); +extern void __iomem *of_dma_get_instwrapper_address(struct device_node *np); +extern bool of_dma_get_wrapper_available(struct device_node *np); +extern u64 of_dma_get_mask(struct device_node *np, char *name); #else static inline int of_dma_controller_register(struct device_node *np, struct dma_chan *(*of_dma_xlate) @@ -89,6 +96,35 @@ static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_s return NULL; } +static inline void __iomem *of_dma_get_wrapper_address(struct device_node *np, unsigned int num) +{ + return NULL; +} + +static inline void __iomem *of_dma_get_arwrapper_address(struct device_node *np, unsigned int num) +{ + return NULL; +} + +static inline void __iomem *of_dma_get_awwrapper_address(struct device_node *np, unsigned int num) +{ + return NULL; +} + +static inline void __iomem *of_dma_get_instwrapper_address(struct device_node *np) +{ + return NULL; +} + +static inline bool of_dma_get_wrapper_available(struct device_node *np) +{ + return NULL; +} + +static u64 of_dma_get_mask(struct device_node *np, char *name) +{ + return NULL; +} #define of_dma_xlate_by_chan_id NULL #endif -- 2.20.1