public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: m.szyprowski@samsung•com (Marek Szyprowski)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH v6 1/8] iommu: provide early initialisation hook for IOMMU drivers
Date: Tue, 02 Dec 2014 10:23:00 +0100	[thread overview]
Message-ID: <547D84F4.8030204@samsung.com> (raw)
In-Reply-To: <CAL_JsqKHvh9KSTYrrs1Pts5Kg=8dA1V6NiW57_2vdDH173qQGg@mail.gmail.com>

Hello,

On 2014-12-02 00:54, Rob Herring wrote:
> Adding Grant and Pantelis...
>
> On Mon, Dec 1, 2014 at 10:57 AM, Will Deacon <will.deacon@arm•com> wrote:
>> IOMMU drivers must be initialised before any of their upstream devices,
>> otherwise the relevant iommu_ops won't be configured for the bus in
>> question. To solve this, a number of IOMMU drivers use initcalls to
>> initialise the driver before anything has a chance to be probed.
>>
>> Whilst this solves the immediate problem, it leaves the job of probing
>> the IOMMU completely separate from the iommu_ops to configure the IOMMU,
>> which are called on a per-bus basis and require the driver to figure out
>> exactly which instance of the IOMMU is being requested. In particular,
>> the add_device callback simply passes a struct device to the driver,
>> which then has to parse firmware tables or probe buses to identify the
>> relevant IOMMU instance.
>>
>> This patch takes the first step in addressing this problem by adding an
>> early initialisation pass for IOMMU drivers, giving them the ability to
>> store some per-instance data in their iommu_ops structure and store that
>> in their of_node. This can later be used when parsing OF masters to
>> identify the IOMMU instance in question.
>>
>> Acked-by: Arnd Bergmann <arnd@arndb•de>
>> Acked-by: Joerg Roedel <jroedel@suse•de>
>> Acked-by: Marek Szyprowski <m.szyprowski@samsung•com>
>> Tested-by: Robin Murphy <robin.murphy@arm•com>
>> Signed-off-by: Will Deacon <will.deacon@arm•com>
>> ---
>>   drivers/iommu/of_iommu.c          | 17 +++++++++++++++++
>>   include/asm-generic/vmlinux.lds.h |  2 ++
>>   include/linux/iommu.h             |  2 ++
>>   include/linux/of_iommu.h          | 25 +++++++++++++++++++++++++
>>   4 files changed, 46 insertions(+)
>>
>> diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
>> index e550ccb7634e..89b903406968 100644
>> --- a/drivers/iommu/of_iommu.c
>> +++ b/drivers/iommu/of_iommu.c
>> @@ -22,6 +22,9 @@
>>   #include <linux/of.h>
>>   #include <linux/of_iommu.h>
>>
>> +static const struct of_device_id __iommu_of_table_sentinel
>> +       __used __section(__iommu_of_table_end);
>> +
>>   /**
>>    * of_get_dma_window - Parse *dma-window property and returns 0 if found.
>>    *
>> @@ -89,3 +92,17 @@ int of_get_dma_window(struct device_node *dn, const char *prefix, int index,
>>          return 0;
>>   }
>>   EXPORT_SYMBOL_GPL(of_get_dma_window);
>> +
>> +void __init of_iommu_init(void)
>> +{
>> +       struct device_node *np;
>> +       const struct of_device_id *match, *matches = &__iommu_of_table;
>> +
>> +       for_each_matching_node_and_match(np, matches, &match) {
>> +               const of_iommu_init_fn init_fn = match->data;
>> +
>> +               if (init_fn(np))
>> +                       pr_err("Failed to initialise IOMMU %s\n",
>> +                               of_node_full_name(np));
>> +       }
>> +}
>> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
>> index aa70cbda327c..bee5d683074d 100644
>> --- a/include/asm-generic/vmlinux.lds.h
>> +++ b/include/asm-generic/vmlinux.lds.h
>> @@ -164,6 +164,7 @@
>>   #define CLKSRC_OF_TABLES()     OF_TABLE(CONFIG_CLKSRC_OF, clksrc)
>>   #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)
>>   #define CLK_OF_TABLES()                OF_TABLE(CONFIG_COMMON_CLK, clk)
>> +#define IOMMU_OF_TABLES()      OF_TABLE(CONFIG_OF_IOMMU, iommu)
>>   #define RESERVEDMEM_OF_TABLES()        OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)
>>   #define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method)
>>   #define EARLYCON_OF_TABLES()   OF_TABLE(CONFIG_SERIAL_EARLYCON, earlycon)
>> @@ -497,6 +498,7 @@
>>          CLK_OF_TABLES()                                                 \
>>          RESERVEDMEM_OF_TABLES()                                         \
>>          CLKSRC_OF_TABLES()                                              \
>> +       IOMMU_OF_TABLES()                                               \
>>          CPU_METHOD_OF_TABLES()                                          \
>>          KERNEL_DTB()                                                    \
>>          IRQCHIP_OF_MATCH_TABLE()                                        \
>> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
>> index e6a7c9ff72f2..7b83f9f8e11d 100644
>> --- a/include/linux/iommu.h
>> +++ b/include/linux/iommu.h
>> @@ -103,6 +103,7 @@ enum iommu_attr {
>>    * @domain_get_attr: Query domain attributes
>>    * @domain_set_attr: Change domain attributes
>>    * @pgsize_bitmap: bitmap of supported page sizes
>> + * @priv: per-instance data private to the iommu driver
>>    */
>>   struct iommu_ops {
>>          bool (*capable)(enum iommu_cap);
>> @@ -133,6 +134,7 @@ struct iommu_ops {
>>          u32 (*domain_get_windows)(struct iommu_domain *domain);
>>
>>          unsigned long pgsize_bitmap;
>> +       void *priv;
>>   };
>>
>>   #define IOMMU_GROUP_NOTIFY_ADD_DEVICE          1 /* Device added */
>> diff --git a/include/linux/of_iommu.h b/include/linux/of_iommu.h
>> index 51a560f34bca..5762cdc8effe 100644
>> --- a/include/linux/of_iommu.h
>> +++ b/include/linux/of_iommu.h
>> @@ -1,12 +1,17 @@
>>   #ifndef __OF_IOMMU_H
>>   #define __OF_IOMMU_H
>>
>> +#include <linux/iommu.h>
>> +#include <linux/of.h>
>> +
>>   #ifdef CONFIG_OF_IOMMU
>>
>>   extern int of_get_dma_window(struct device_node *dn, const char *prefix,
>>                               int index, unsigned long *busno, dma_addr_t *addr,
>>                               size_t *size);
>>
>> +extern void of_iommu_init(void);
>> +
>>   #else
>>
>>   static inline int of_get_dma_window(struct device_node *dn, const char *prefix,
>> @@ -16,6 +21,26 @@ static inline int of_get_dma_window(struct device_node *dn, const char *prefix,
>>          return -EINVAL;
>>   }
>>
>> +static inline void of_iommu_init(void) { }
>> +
>>   #endif /* CONFIG_OF_IOMMU */
>>
>> +static inline void of_iommu_set_ops(struct device_node *np,
>> +                                   const struct iommu_ops *ops)
>> +{
>> +       np->data = (struct iommu_ops *)ops;
>> +}
>> +
>> +static inline struct iommu_ops *of_iommu_get_ops(struct device_node *np)
>> +{
>> +       return np->data;
>> +}
> This may collide with other users. While use of it is rare, PPC uses
> it in its PCI code. The OF_DYNAMIC code frees it but never actually
> sets it. There may be some coming usage with the DT overlay code or
> that's just a bug. Pantelis or Grant can comment. If not, I think we
> really should try to get rid of this pointer rather than expand it's
> usage.

I think that for the initial version it is ok to use np->data. When 
per-iommu
controller structure is introduced later, it can be reused also for 
performing
of_node to iommu_ops lookup, because IOMMU framework will need to keep track
on all such iommu controllers anyway.

> I didn't see a user of this. I'm guessing that is coming in a SMMU patch?

It is used in of_iommu_configure() function from "[PATCH v6 4/8] iommu:
provide helper function to configure an IOMMU for an of master". Example
driver converted to this framework is available here:
http://www.spinics.net/lists/linux-samsung-soc/msg39168.html

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland

  reply	other threads:[~2014-12-02  9:23 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-01 16:57 [PATCH v6 0/8] Introduce automatic DMA configuration for IOMMU masters Will Deacon
2014-12-01 16:57 ` [PATCH v6 1/8] iommu: provide early initialisation hook for IOMMU drivers Will Deacon
2014-12-01 23:54   ` Rob Herring
2014-12-02  9:23     ` Marek Szyprowski [this message]
2014-12-02  9:36       ` Arnd Bergmann
2014-12-02  9:43         ` Will Deacon
2014-12-02 12:05         ` Thierry Reding
2014-12-02 10:30     ` Pantelis Antoniou
2014-12-02 14:16     ` Grant Likely
2014-12-03 19:57       ` Arnd Bergmann
2014-12-04  9:49         ` Will Deacon
2014-12-04 10:10           ` Arnd Bergmann
2014-12-04 10:21             ` Will Deacon
2014-12-04 11:19               ` Arnd Bergmann
2014-12-04 11:25                 ` Grant Likely
2014-12-04 11:52                   ` Will Deacon
2014-12-04 12:43                     ` Grant Likely
2014-12-04 12:26         ` Robin Murphy
2014-12-04 12:42           ` Grant Likely
2014-12-04 13:43             ` Robin Murphy
2014-12-04 13:58               ` Grant Likely
2014-12-04 14:49               ` Thierry Reding
2014-12-04 17:42                 ` Robin Murphy
2014-12-04 17:58                   ` Grant Likely
2014-12-04 19:42                     ` Robin Murphy
2014-12-05 12:10                       ` Will Deacon
2014-12-05 12:21                         ` Arnd Bergmann
2014-12-05 12:35                         ` Robin Murphy
2014-12-05 13:06                           ` Grant Likely
2014-12-05 13:18                             ` Thierry Reding
2014-12-05 13:21                               ` Grant Likely
2014-12-05 13:31                                 ` Thierry Reding
2014-12-05 13:49                               ` Marek Szyprowski
2014-12-04 12:51           ` Arnd Bergmann
2014-12-01 16:57 ` [PATCH v6 2/8] dma-mapping: replace set_arch_dma_coherent_ops with arch_setup_dma_ops Will Deacon
2014-12-01 22:58   ` Rob Herring
2014-12-02  9:16     ` Arnd Bergmann
2014-12-01 16:57 ` [PATCH v6 3/8] iommu: add new iommu_ops callback for adding an OF device Will Deacon
2014-12-01 16:57 ` [PATCH v6 4/8] iommu: provide helper function to configure an IOMMU for an of master Will Deacon
2014-12-01 16:57 ` [PATCH v6 5/8] iommu: fix initialization without 'add_device' callback Will Deacon
2014-12-01 16:57 ` [PATCH v6 6/8] dma-mapping: detect and configure IOMMU in of_dma_configure Will Deacon
2014-12-01 23:06   ` Rob Herring
2014-12-10 14:52   ` Rob Clark
2014-12-10 15:08     ` Will Deacon
2014-12-10 15:54       ` Robin Murphy
2014-12-10 15:56         ` Laurent Pinchart
2014-12-14 15:49       ` Laurent Pinchart
2014-12-14 15:59         ` Laurent Pinchart
2014-12-15 17:10           ` Will Deacon
2014-12-15 16:40         ` Will Deacon
2014-12-15 17:16           ` Laurent Pinchart
2014-12-15 18:09             ` Will Deacon
2014-12-16 12:08               ` Arnd Bergmann
2014-12-17 12:09                 ` Will Deacon
2014-12-17 14:15                   ` Arnd Bergmann
2014-12-17 14:45                     ` Will Deacon
2014-12-17 15:35                       ` Arnd Bergmann
2014-12-17 17:17                         ` Will Deacon
2014-12-17 19:48                           ` Arnd Bergmann
2014-12-21 10:04                             ` Will Deacon
2014-12-22 13:36                               ` Arnd Bergmann
2015-01-07 18:57                                 ` Will Deacon
2015-01-07 19:29                                   ` Arnd Bergmann
2015-01-08 10:53                                     ` Will Deacon
2014-12-17 14:27                   ` Robin Murphy
2014-12-17 15:01                     ` Will Deacon
2014-12-17 15:38                       ` Arnd Bergmann
2014-12-17 17:20                         ` Will Deacon
2014-12-17  0:05               ` Laurent Pinchart
2014-12-14 15:51   ` Laurent Pinchart
2014-12-15 11:32     ` Will Deacon
2014-12-17  0:19       ` Laurent Pinchart
2014-12-17 11:14         ` Will Deacon
2014-12-01 16:57 ` [PATCH v6 7/8] arm: call iommu_init before of_platform_populate Will Deacon
2014-12-01 16:57 ` [PATCH v6 8/8] arm: dma-mapping: plumb our iommu mapping ops into arch_setup_dma_ops Will Deacon
2015-01-14  9:00   ` Alexandre Courbot
2015-01-14 10:46     ` Will Deacon
2015-01-14 13:51       ` Heiko Stübner
2015-01-14 19:17         ` Will Deacon
2015-01-15  8:30           ` Thierry Reding
2015-01-15 11:13             ` Will Deacon
2015-01-15  2:57       ` Alexandre Courbot
2015-01-15  8:28       ` Thierry Reding
2015-01-15 11:12         ` Will Deacon
2015-01-15 23:18           ` Laurent Pinchart
2015-01-18  6:54             ` Alexandre Courbot
2015-01-18 11:18               ` Laurent Pinchart
2015-01-19 11:12                 ` Will Deacon
2015-01-19 11:34                   ` Laurent Pinchart
2015-01-19 12:31                     ` Thierry Reding
2015-01-20 15:14                       ` Laurent Pinchart
2015-01-20 15:19                         ` Will Deacon
2015-01-20 15:21                           ` Will Deacon
2015-01-20 15:35                           ` Laurent Pinchart
2015-01-19 12:43                 ` Thierry Reding
2015-01-19 12:50                   ` Will Deacon
2015-01-19 13:36                     ` Thierry Reding
2015-01-20 13:50                       ` Laurent Pinchart
2015-01-19 16:13                 ` Arnd Bergmann
2015-01-20 16:41                   ` Laurent Pinchart
2015-01-19 12:36             ` Thierry Reding
2015-01-19 15:52               ` Arnd Bergmann
2015-01-19 16:21                 ` Thierry Reding
2015-01-19 17:02                   ` Arnd Bergmann
2015-01-20 13:47                   ` Laurent Pinchart
2015-01-19 12:49             ` Thierry Reding
2015-01-20 14:05               ` Laurent Pinchart
2014-12-05  7:12 ` [PATCH v6 0/8] Introduce automatic DMA configuration for IOMMU masters Olof Johansson
2014-12-05 12:11   ` Will Deacon
2014-12-15  0:24 ` [PATCH/RFC] iommu/ipmmu-vmsa: Use DT-based instantiation Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=547D84F4.8030204@samsung.com \
    --to=m.szyprowski@samsung$(echo .)com \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox