On Tuesday, January 1, 2013, Sylwester Nawrocki <<a href="mailto:sylvester.nawrocki@gmail.com">sylvester.nawrocki@gmail.com</a>> wrote:<br>> On 12/26/2012 02:53 AM, Cho KyongHo wrote:<br>>> This commit adds device tree support for System MMU.<br>
>><br>>> Signed-off-by: KyongHo Cho<<a href="mailto:pullip.cho@samsung.com">pullip.cho@samsung.com</a>><br>><br>> Cc: <a href="mailto:devicetree-discuss@lists.ozlabs.org">devicetree-discuss@lists.ozlabs.org</a><br>
><br>> Please note any patches adding new device tree bindings should be sent<br>> to this mailing list. I have few comments, please see below.<br>><br>Ok. I got it. thank you.<br>>> ---<br>>> drivers/iommu/Kconfig | 2 +-<br>
>> drivers/iommu/exynos-iommu.c | 282 ++++++++++++++++++++++++++-----------------<br>>> 2 files changed, 174 insertions(+), 110 deletions(-)<br>>><br>>> diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig<br>
>> index e39f9db..64586f1 100644<br>>> --- a/drivers/iommu/Kconfig<br>>> +++ b/drivers/iommu/Kconfig<br>>> @@ -168,7 +168,7 @@ config TEGRA_IOMMU_SMMU<br>>><br>>> config EXYNOS_IOMMU<br>
>> bool "Exynos IOMMU Support"<br>>> - depends on ARCH_EXYNOS&& EXYNOS_DEV_SYSMMU<br>>> + depends on ARCH_EXYNOS<br>>> select IOMMU_API<br>>> help<br>
>> Support for the IOMMU(System MMU) of Samsung Exynos application<br>>> diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c<br>>> index 5847508..5b35820 100644<br>>> --- a/drivers/iommu/exynos-iommu.c<br>
>> +++ b/drivers/iommu/exynos-iommu.c<br>>> @@ -1,6 +1,6 @@<br>>> -/* linux/drivers/iommu/exynos_iommu.c<br>>> +/* linux/drivers/iommu/exynos-iommu.c<br>>> *<br>>> - * Copyright (c) 2011 Samsung Electronics Co., Ltd.<br>
>> + * Copyright (c) 2011-2012 Samsung Electronics Co., Ltd.<br>>> * <a href="http://www.samsung.com">http://www.samsung.com</a><br>>> *<br>>> * This program is free software; you can redistribute it and/or modify<br>
>> @@ -12,6 +12,7 @@<br>>> #define DEBUG<br>>> #endif<br>>><br>>> +#include<linux/kernel.h><br>>> #include<linux/io.h><br>>> #include<linux/interrupt.h><br>
>> #include<linux/platform_device.h><br>>> @@ -25,11 +26,10 @@<br>>> #include<linux/list.h><br>>> #include<linux/memblock.h><br>>> #include<linux/export.h><br>
>> +#include<linux/of.h><br>>> +#include<linux/of_platform.h><br>>><br>>> #include<asm/cacheflush.h><br>>> -#include<asm/pgtable.h><br>>> -<br>>> -#include<mach/sysmmu.h><br>
>><br>>> /* We does not consider super section mapping (16MB) */<br>>> #define SECT_ORDER 20<br>>> @@ -161,14 +161,13 @@ struct sysmmu_drvdata {<br>>> struct list_head node; /* entry of exynos_iommu_domain.clients */<br>
>> struct device *sysmmu; /* System MMU's device descriptor */<br>>> struct device *dev; /* Owner of system MMU */<br>>> - char *dbgname;<br>>> int nsfrs;<br>>> - void __iomem **sfrbases;<br>
>> - struct clk *clk[2];<br>>> + struct clk *clk;<br>>> int activations;<br>>> spinlock_t lock;<br>>> struct iommu_domain *domain;<br>>> unsigned long pgtable;<br>
>> + void __iomem *sfrbases[0];<br>>> };<br>>><br>>> static bool set_sysmmu_active(struct sysmmu_drvdata *data)<br>>> @@ -373,10 +372,8 @@ static bool __exynos_sysmmu_disable(struct sysmmu_drvdata *data)<br>
>> for (i = 0; i< data->nsfrs; i++)<br>>> __raw_writel(CTRL_DISABLE, data->sfrbases[i] + REG_MMU_CTRL);<br>>><br>>> - if (data->clk[1])<br>>> - clk_disable(data->clk[1]);<br>
>> - if (data->clk[0])<br>>> - clk_disable(data->clk[0]);<br>>> + if (data->clk)<br>>> + clk_disable(data->clk);<br>>><br>>> disabled = true;<br>
>> data->pgtable = 0;<br>>> @@ -385,10 +382,10 @@ finish:<br>>> spin_unlock_irqrestore(&data->lock, flags);<br>>><br>>> if (disabled)<br>>> - dev_dbg(data->sysmmu, "(%s) Disabled\n", data->dbgname);<br>
>> + dev_dbg(data->sysmmu, "Disabled\n");<br>>> else<br>>> - dev_dbg(data->sysmmu, "(%s) %d times left to be disabled\n",<br>>> - data->dbgname, data->activations);<br>
>> + dev_dbg(data->sysmmu, "%d times left to be disabled\n",<br>>> + data->activations);<br>>><br>>> return disabled;<br>>> }<br>
>> @@ -415,14 +412,12 @@ static int __exynos_sysmmu_enable(struct sysmmu_drvdata *data,<br>>> ret = 1;<br>>> }<br>>><br>>> - dev_dbg(data->sysmmu, "(%s) Already enabled\n", data->dbgname);<br>
>> + dev_dbg(data->sysmmu, "Already enabled\n");<br>>> goto finish;<br>>> }<br>>><br>>> - if (data->clk[0])<br>>> - clk_enable(data->clk[0]);<br>
>> - if (data->clk[1])<br>>> - clk_enable(data->clk[1]);<br>>> + if (data->clk)<br>>> + clk_enable(data->clk);<br>>><br>>> data->pgtable = pgtable;<br>
>><br>>> @@ -442,7 +437,7 @@ static int __exynos_sysmmu_enable(struct sysmmu_drvdata *data,<br>>><br>>> data->domain = domain;<br>>><br>>> - dev_dbg(data->sysmmu, "(%s) Enabled\n", data->dbgname);<br>
>> + dev_dbg(data->sysmmu, "Enabled\n");<br>>> finish:<br>>> spin_unlock_irqrestore(&data->lock, flags);<br>>><br>>> @@ -458,7 +453,7 @@ int exynos_sysmmu_enable(struct device *dev, unsigned long pgtable)<br>
>><br>>> ret = pm_runtime_get_sync(data->sysmmu);<br>>> if (ret< 0) {<br>>> - dev_dbg(data->sysmmu, "(%s) Failed to enable\n", data->dbgname);<br>>> + dev_dbg(data->sysmmu, "Failed to enable\n");<br>
>> return ret;<br>>> }<br>>><br>>> @@ -466,8 +461,8 @@ int exynos_sysmmu_enable(struct device *dev, unsigned long pgtable)<br>>> if (WARN_ON(ret< 0)) {<br>>> pm_runtime_put(data->sysmmu);<br>
>> dev_err(data->sysmmu,<br>>> - "(%s) Already enabled with page table %#lx\n",<br>>> - data->dbgname, data->pgtable);<br>>> + "Already enabled with page table %#lx\n",<br>
>> + data->pgtable);<br>>> } else {<br>>> data->dev = dev;<br>>> }<br>>> @@ -504,8 +499,7 @@ static void sysmmu_tlb_invalidate_entry(struct device *dev, unsigned long iova)<br>
>> }<br>>> } else {<br>>> dev_dbg(data->sysmmu,<br>>> - "(%s) Disabled. Skipping invalidating TLB.\n",<br>>> - data->dbgname);<br>
>> + "Disabled. Skipping invalidating TLB.\n");<br>>> }<br>>><br>>> spin_unlock_irqrestore(&data->lock, flags);<br>>> @@ -528,138 +522,208 @@ void exynos_sysmmu_tlb_invalidate(struct device *dev)<br>
>> }<br>>> } else {<br>>> dev_dbg(data->sysmmu,<br>>> - "(%s) Disabled. Skipping invalidating TLB.\n",<br>>> - data->dbgname);<br>
>> + "Disabled. Skipping invalidating TLB.\n");<br>>> }<br>>><br>>> spin_unlock_irqrestore(&data->lock, flags);<br>>> }<br>>><br>>> -static int exynos_sysmmu_probe(struct platform_device *pdev)<br>
>> +static int __init __sysmmu_init_clock(struct device *sysmmu,<br>>> + struct sysmmu_drvdata *drvdata,<br>>> + struct device *master)<br>
>> {<br>>> - int i, ret;<br>>> - struct device *dev;<br>>> - struct sysmmu_drvdata *data;<br>>> + char *conid;<br>>> + struct clk *parent_clk;<br>>> + int ret;<br>
>><br>>> - dev =&pdev->dev;<br>>> + drvdata->clk = clk_get(sysmmu, "sysmmu");<br>>> + if (IS_ERR(drvdata->clk)) {<br>>> + dev_dbg(sysmmu, "No gating clock found.\n");<br>
>> + drvdata->clk = NULL;<br>>> + return 0;<br>>> + }<br>>><br>>> - data = kzalloc(sizeof(*data), GFP_KERNEL);<br>>> - if (!data) {<br>>> - dev_dbg(dev, "Not enough memory\n");<br>
>> - ret = -ENOMEM;<br>>> - goto err_alloc;<br>>> + if (!master)<br>>> + return 0;<br>>> +<br>>> + conid = dev_get_platdata(sysmmu);<br>>> + if (!conid) {<br>
>> + dev_dbg(sysmmu, "No parent clock specified.\n");<br>>> + return 0;<br>>> }<br>>><br>>> - ret = dev_set_drvdata(dev, data);<br>>> + parent_clk = clk_get(master, conid);<br>
>> + if (IS_ERR(parent_clk)) {<br>>> + parent_clk = clk_get(NULL, conid);<br>>> + if (IS_ERR(parent_clk)) {<br>>> + clk_put(drvdata->clk);<br>>> + dev_err(sysmmu, "No parent clock '%s,%s' found\n",<br>
>> + dev_name(master), conid);<br>>> + return PTR_ERR(parent_clk);<br>>> + }<br>>> + }<br>>> +<br>>> + ret = clk_set_parent(drvdata->clk, parent_clk);<br>
>> if (ret) {<br>>> - dev_dbg(dev, "Unabled to initialize driver data\n");<br>>> - goto err_init;<br>>> + clk_put(drvdata->clk);<br>>> + dev_err(sysmmu, "Failed to set parent clock '%s,%s'\n",<br>
>> + dev_name(master), conid);<br>>> }<br>>><br>>> - data->nsfrs = pdev->num_resources / 2;<br>>> - data->sfrbases = kmalloc(sizeof(*data->sfrbases) * data->nsfrs,<br>
>> - GFP_KERNEL);<br>>> - if (data->sfrbases == NULL) {<br>>> - dev_dbg(dev, "Not enough memory\n");<br>>> - ret = -ENOMEM;<br>
>> - goto err_init;<br>>> + clk_put(parent_clk);<br>>> +<br>>> + return ret;<br>>> +}<br>>> +<br>>> +static int __init __sysmmu_setup(struct device *sysmmu,<br>
>> + struct sysmmu_drvdata *drvdata)<br>>> +{<br>>> + struct device_node *master_node;<br>>> + const char *compat;<br>>> + struct platform_device *pmaster = NULL;<br>
>> + u32 master_inst_no = -1;<br>>> + int ret;<br>>> +<br>>> + master_node = of_parse_phandle(sysmmu->of_node, "mmu-master", 0);<br>>> + if (!master_node&& !of_property_read_string(<br>
>> + sysmmu->of_node, "mmu-master-compat",&compat)) {<br>>> + of_property_read_u32_array(sysmmu->of_node,<br>>> + "mmu-master-no",&master_inst_no, 1);<br>
>> + for_each_compatible_node(master_node, NULL, compat) {<br>>> + pmaster = of_find_device_by_node(master_node);<br>>> + if (pmaster&& (pmaster->id == master_inst_no))<br>
>> + break;<br>>> + of_dev_put(pmaster);<br>>> + pmaster = NULL;<br>>> + }<br>>> + } else if (master_node) {<br>
>> + pmaster = of_find_device_by_node(master_node);<br>>> + }<br>>> +<br>>> + if (!pmaster) {<br>>> + dev_dbg(sysmmu, "No master device is specified.\n");<br>
>> + return __sysmmu_init_clock(sysmmu, drvdata, NULL);<br>>> + }<br>>> +<br>>> + pmaster->dev.archdata.iommu = sysmmu;<br>>> +<br>>> + ret = __sysmmu_init_clock(sysmmu, drvdata,&pmaster->dev);<br>
>> + if (ret)<br>>> + dev_err(sysmmu, "Failed to initialize gating clocks\n");<br>>> +<br>>> + of_dev_put(pmaster);<br>>> +<br>>> + return ret;<br>>> +}<br>
>> +<br>>> +static int __init exynos_sysmmu_probe(struct platform_device *pdev)<br>>> +{<br>>> + int i, ret;<br>>> + struct device *dev =&pdev->dev;<br>>> + struct sysmmu_drvdata *data;<br>
>> +<br>>> + if (pdev->num_resources == 0) {<br>>> + dev_err(dev, "No System MMU resource defined\n");<br>>> + return -ENODEV;<br>>> + }<br>>> +<br>
>> + data = devm_kzalloc(dev,<br>>> + sizeof(*data)<br>>> + + sizeof(*data->sfrbases) * (pdev->num_resources / 2),<br>>> + GFP_KERNEL);<br>
>> + if (!data) {<br>>> + dev_err(dev, "Not enough memory\n");<br>>> + return -ENOMEM;<br>>> }<br>>><br>>> + data->nsfrs = pdev->num_resources / 2;<br>
>> +<br>>> for (i = 0; i< data->nsfrs; i++) {<br>>> struct resource *res;<br>>> res = platform_get_resource(pdev, IORESOURCE_MEM, i);<br>>> if (!res) {<br>
>> - dev_dbg(dev, "Unable to find IOMEM region\n");<br>>> - ret = -ENOENT;<br>>> - goto err_res;<br>>> + dev_err(dev, "Unable to find IOMEM region\n");<br>
>> + return -ENOENT;<br>>> }<br>>><br>>> - data->sfrbases[i] = ioremap(res->start, resource_size(res));<br>>> + data->sfrbases[i] = devm_request_and_ioremap(dev, res);<br>
>> if (!data->sfrbases[i]) {<br>>> - dev_dbg(dev, "Unable to map IOMEM @ PA:%#x\n",<br>>> + dev_err(dev, "Unable to map IOMEM @ PA:%#x\n",<br>
>> res->start);<br>>> - ret = -ENOENT;<br>>> - goto err_res;<br>>> + return -EBUSY;<br>
>> }<br>>> }<br>>><br>>> for (i = 0; i< data->nsfrs; i++) {<br>>> ret = platform_get_irq(pdev, i);<br>>> if (ret<= 0) {<br>
>> - dev_dbg(dev, "Unable to find IRQ resource\n");<br>>> - goto err_irq;<br>>> + dev_err(dev, "Unable to find IRQ resource\n");<br>
>> + return ret;<br>>> }<br>>><br>>> - ret = request_irq(ret, exynos_sysmmu_irq, 0,<br>>> + ret = devm_request_irq(dev, ret, exynos_sysmmu_irq, 0,<br>
>> dev_name(dev), data);<br>>> if (ret) {<br>>> - dev_dbg(dev, "Unabled to register interrupt handler\n");<br>>> - goto err_irq;<br>
>> + dev_err(dev, "Unabled to register interrupt handler\n");<br>>> + return ret;<br>>> }<br>>> }<br>>><br>>> - if (dev_get_platdata(dev)) {<br>
>> - char *deli, *beg;<br>>> - struct sysmmu_platform_data *platdata = dev_get_platdata(dev);<br>>> -<br>>> - beg = platdata->clockname;<br>>> -<br>>> - for (deli = beg; (*deli != '\0')&& (*deli != ','); deli++)<br>
>> - /* NOTHING */;<br>>> -<br>>> - if (*deli == '\0')<br>>> - deli = NULL;<br>>> - else<br>>> - *deli = '\0';<br>
>> -<br>>> - data->clk[0] = clk_get(dev, beg);<br>>> - if (IS_ERR(data->clk[0])) {<br>>> - data->clk[0] = NULL;<br>>> - dev_dbg(dev, "No clock descriptor registered\n");<br>
>> - }<br>>> -<br>>> - if (data->clk[0]&& deli) {<br>>> - *deli = ',';<br>>> - data->clk[1] = clk_get(dev, deli + 1);<br>
>> - if (IS_ERR(data->clk[1]))<br>>> - data->clk[1] = NULL;<br>>> - }<br>>> -<br>>> - data->dbgname = platdata->dbgname;<br>
>> - }<br>>><br>>> - data->sysmmu = dev;<br>>> - spin_lock_init(&data->lock);<br>>> - INIT_LIST_HEAD(&data->node);<br>>> + ret = __sysmmu_setup(dev, data);<br>
>> + if (!ret) {<br>>> + data->sysmmu = dev;<br>>> + spin_lock_init(&data->lock);<br>>> + INIT_LIST_HEAD(&data->node);<br>>><br>>> - if (dev->parent)<br>
>> pm_runtime_enable(dev);<br>>><br>>> - dev_dbg(dev, "(%s) Initialized\n", data->dbgname);<br>>> - return 0;<br>>> -err_irq:<br>>> - while (i--> 0) {<br>
>> - int irq;<br>>> + platform_set_drvdata(pdev, data);<br>>><br>>> - irq = platform_get_irq(pdev, i);<br>>> - free_irq(irq, data);<br>>> + dev_dbg(dev, "Initialized\n");<br>
>> }<br>>> -err_res:<br>>> - while (data->nsfrs--> 0)<br>>> - iounmap(data->sfrbases[data->nsfrs]);<br>>> - kfree(data->sfrbases);<br>>> -err_init:<br>
>> - kfree(data);<br>>> -err_alloc:<br>>> - dev_err(dev, "Failed to initialize\n");<br>>> +<br>>> return ret;<br>>> }<br>>><br>>> -static struct platform_driver exynos_sysmmu_driver = {<br>
>> +/*<br>>> + * Descriptions of Device Tree node for System MMU<br>>> + *<br>>> + * A System MMU should be described by a single tree node.<br>>> + *<br>>> + * A System MMU node should have the following properties:<br>
>> + * - reg: tuples of the base address and the size of the IO region of System MMU<br>>> + * - compatible: it must be "samsung,exynos-sysmmu".<br>><br>> I think this compatible property is too generic. It should include<br>
> specific SoC<br>> name in it, e.g. samsung,exynos4210-sysmmu. Please refer to this thread<br>> <a href="http://www.spinics.net/lists/linux-omap/msg83512.html">http://www.spinics.net/lists/linux-omap/msg83512.html</a>, which discusses<br>
> similar issue.<br><br>Ok, I got the point. BTW , I think this will cause adding a compatibility property whenever a SoC is released even though it has completely sameSystem MMU. Is it inevitable?<br><br>>> + * - interrupt-parent = specify if the interrupt of System MMU is generated by<br>
>> + * interrupt combiner or interrupt controller.<br>>> + * - interrupts: tuples of interrupt numbers. a tuple has 2 elements if<br>>> + * @interrupt-parent is '<&combiner>', 3 elements otherwise.<br>
><br>> It's probably enough to say that format of the interrupts property is<br>> dependant on<br>> the interrupt controller used.<br><br>I agree that :)<br><br>>> + *<br>>> + * 'mmuname', 'reg' and 'interrupts' properties can be an array if the System<br>
>> + * MMU driver controls several number of System MMUs at the same time. Note that<br>>> + * the number of elements in those three properties must be the same.<br>><br>> It might be useful to provide some example here.<br>
<br>examples are there in Documentations directory.<br><br>>> + * The following properties are optional:<br>>> + * - mmuname: name of the System MMU for debugging purpose<br>><br>> Not sure if it is something that is supposed to be included in FDT. You<br>
> could<br>> probably derive it from the 'compatible' property, if it is really<br>> needed. The device<br>> tree bindings should not be treated as direct replacement for platform data<br>> structures.<br>
<br>actually it is just for debugging purpose.<br>I understand that it should not be there.<br>Thank you.<br><br>>> + * - mmu-master: reference to the node of the master device.<br>>> + * - mmu-master-compat: 'compatible' proberty of the node of the master device<br>
>> + * of System MMU. This is ignored if @mmu-master is currectly specified.<br>>> + * - mmu-master-no: instance number of the master device of System MMU. This is<br>>> + * ignored if @mmu-master is correctly specified. This is '0' by default.<br>
><br>> Maybe device node aliases would be better alternative here ? But what<br>> would be<br>> a use case where you can't set 'mmu-master' and 'mmu-master-no' is needed ?<br><br>It is for platform devices that are not specified in FDT.<br>
Don't we need consider that? <br><br>>> + */<br>>> +#ifdef CONFIG_OF<br>>> +static struct of_device_id sysmmu_of_match[] __initconst = {<br>>> + { .compatible = "samsung,exynos-sysmmu", },<br>
>> + { },<br>>> +};<br>>> +#endif<br>>> +<br>>> +static struct platform_driver exynos_sysmmu_driver __refdata = {<br>>> .probe = exynos_sysmmu_probe,<br>>> .driver = {<br>
>> .owner = THIS_MODULE,<br>>> .name = "exynos-sysmmu",<br>>> + .of_match_table = of_match_ptr(sysmmu_of_match),<br>>> }<br>
>> };<br>