* Re: [PATCH 1/6] uvcvideo: Set error_idx properly for extended controls API failures
From: Laurent Pinchart @ 2012-12-25 11:23 UTC (permalink / raw)
To: Hans Verkuil; +Cc: linux-media, Hans Verkuil
In-Reply-To: <201212251215.25674.hverkuil@xs4all.nl>
Hi Hans,
On Tuesday 25 December 2012 12:15:25 Hans Verkuil wrote:
> On Mon December 24 2012 13:27:08 Laurent Pinchart wrote:
> > On Thursday 27 September 2012 17:16:15 Laurent Pinchart wrote:
> > > When one of the requested controls doesn't exist the error_idx field
> > > must reflect that situation. For G_EXT_CTRLS and S_EXT_CTRLS, error_idx
> > > must be set to the control count. For TRY_EXT_CTRLS, it must be set to
> > > the index of the unexisting control.
> > >
> > > This issue was found by the v4l2-compliance tool.
> >
> > I'm revisiting this patch as it has been reverted in v3.8-rc1.
> >
> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > ---
> > >
> > > drivers/media/usb/uvc/uvc_ctrl.c | 17 ++++++++++-------
> > > drivers/media/usb/uvc/uvc_v4l2.c | 19 ++++++++++++-------
> > > 2 files changed, 22 insertions(+), 14 deletions(-)
> >
> > [snip]
> >
> > > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c
> > > b/drivers/media/usb/uvc/uvc_v4l2.c index f00db30..e5817b9 100644
> > > --- a/drivers/media/usb/uvc/uvc_v4l2.c
> > > +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> > > @@ -591,8 +591,10 @@ static long uvc_v4l2_do_ioctl(struct file *file,
> >
> > [snip]
> >
> > > @@ -637,8 +639,9 @@ static long uvc_v4l2_do_ioctl(struct file *file,
> > > unsigned int cmd, void *arg) ret = uvc_ctrl_get(chain, ctrl);
> > >
> > > if (ret < 0) {
> > >
> > > uvc_ctrl_rollback(handle);
> > >
> > > - ctrls->error_idx = i;
> > > - return ret;
> > > + ctrls->error_idx = ret == -ENOENT
> > > + ? ctrls->count : i;
> > > + return ret == -ENOENT ? -EINVAL : ret;
> > >
> > > }
> > >
> > > }
> > > ctrls->error_idx = 0;
> > >
> > > @@ -661,8 +664,10 @@ static long uvc_v4l2_do_ioctl(struct file *file,
> > > unsigned int cmd, void *arg) ret = uvc_ctrl_set(chain, ctrl);
> > >
> > > if (ret < 0) {
> > >
> > > uvc_ctrl_rollback(handle);
> > >
> > > - ctrls->error_idx = i;
> > > - return ret;
> > > + ctrls->error_idx = (ret == -ENOENT &&
> > > + cmd == VIDIOC_S_EXT_CTRLS)
> > > + ? ctrls->count : i;
> > > + return ret == -ENOENT ? -EINVAL : ret;
> > >
> > > }
> > >
> > > }
> >
> > I've reread the V4L2 specification, and the least I can say is that the
> > text is pretty ambiguous. Let's clarify it.
> >
> > Is there a reason to differentiate between invalid control IDs and other
> > errors as far as error_idx is concerned ? It would be simpler if error_idx
> > was set to the index of the first error for get and try operations,
> > regardless of the error type. What do you think ?
>
> There is a good reason for doing this: the G/S_EXT_CTRLS ioctls have to be
> as atomic as possible, i.e. it should try hard to prevent leaving the
> hardware in an inconsistent state because not all controls could be set. It
> can never be fully atomic since writing multiple registers over usb or i2c
> can always return errors for one of those writes, but it should certainly
> check for all the obvious errors first that do not require actually writing
> to the hardware, such as whether all the controls in the control list
> actually exist.
>
> And for such errors error_idx should be set to the number of controls to
> indicate that none of the controls were actually set but that there was a
> problem with the list of controls itself.
For S_EXT_CTRLS, sure, but G_EXT_CTRLS doesn't modify the hardware state, so
it could get all controls up to the erroneous one.
> Since TRY_EXT_CTRLS doesn't touch the hardware at all the error_idx can be
> set to the index of the control that caused the problem.
>
> The documentation can definitely be improved as the difference between G/S
> and TRY with regards to error_idx is not made explicit.
--
Regards,
Laurent Pinchart
^ permalink raw reply
* Re: [PATCH v7 06/27] x86, 64bit: early #PF handler set page table
From: Borislav Petkov @ 2012-12-25 11:20 UTC (permalink / raw)
To: Yinghai Lu
Cc: H. Peter Anvin, Jason Wessel, Jan Kiszka, Thomas Gleixner,
Ingo Molnar, Eric W. Biederman, Andrew Morton, linux-kernel
In-Reply-To: <CAE9FiQW_mjUr6F0q7PhZWCcDzZ+NJpi0-xjxvwJoZ1K+XAUjSQ@mail.gmail.com>
On Mon, Dec 24, 2012 at 08:04:18PM -0800, Yinghai Lu wrote:
> well, I updated for-x86-boot-v7 that stop #PF handler after
> init_mem_mapping.
>
> it has fix for AMD system aka reverting far jmp to ret.
-v7?
You told me yesterday -v8 is the current branch. Do you have -v7 which
does break KGDB and -v8 which breaks it and both branches are current?
Thanks.
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
^ permalink raw reply
* [PATCH v5 4/4] ARM: mach-shmobile: r8a7740: Add IPMMU device
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This patch adds an IPMMU device and notifies the IPMMU driver which
devices are connected via the IPMMU module. All devices connected to the main
memory bus via the IPMMU module MUST be registered when SHMOBILE_IPMMU and
SHMOBILE_IOMMU are enabled because physical address cannot be used
while the IPMMU module's MMU function is enabled.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
arch/arm/mach-shmobile/setup-r8a7740.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/arch/arm/mach-shmobile/setup-r8a7740.c b/arch/arm/mach-shmobile/setup-r8a7740.c
index 0952224..b85bea5 100644
--- a/arch/arm/mach-shmobile/setup-r8a7740.c
+++ b/arch/arm/mach-shmobile/setup-r8a7740.c
@@ -28,6 +28,7 @@
#include <linux/sh_dma.h>
#include <linux/sh_timer.h>
#include <linux/dma-mapping.h>
+#include <linux/platform_data/sh_ipmmu.h>
#include <mach/dma-register.h>
#include <mach/r8a7740.h>
#include <mach/pm-rmobile.h>
@@ -262,6 +263,37 @@ static struct platform_device cmt10_device = {
.num_resources = ARRAY_SIZE(cmt10_resources),
};
+/* IPMMUI (an IPMMU module for ICB/LMB) */
+static struct resource ipmmu_resources[] = {
+ [0] = {
+ .name = "IPMMUI",
+ .start = 0xfe951000,
+ .end = 0xfe9510ff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static const char * const ipmmu_dev_names[] = {
+ "sh_mobile_lcdc_fb.0",
+ "sh_mobile_lcdc_fb.1",
+ "sh_mobile_ceu.0",
+};
+
+static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
+ .dev_names = ipmmu_dev_names,
+ .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
+};
+
+static struct platform_device ipmmu_device = {
+ .name = "ipmmu",
+ .id = -1,
+ .dev = {
+ .platform_data = &ipmmu_platform_data,
+ },
+ .resource = ipmmu_resources,
+ .num_resources = ARRAY_SIZE(ipmmu_resources),
+};
+
static struct platform_device *r8a7740_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
@@ -273,6 +305,7 @@ static struct platform_device *r8a7740_early_devices[] __initdata = {
&scif7_device,
&scifb_device,
&cmt10_device,
+ &ipmmu_device,
};
/* DMA */
--
1.8.0
^ permalink raw reply related
* [PATCH v5 4/4] ARM: mach-shmobile: r8a7740: Add IPMMU device
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This patch adds an IPMMU device and notifies the IPMMU driver which
devices are connected via the IPMMU module. All devices connected to the main
memory bus via the IPMMU module MUST be registered when SHMOBILE_IPMMU and
SHMOBILE_IOMMU are enabled because physical address cannot be used
while the IPMMU module's MMU function is enabled.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
arch/arm/mach-shmobile/setup-r8a7740.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/arch/arm/mach-shmobile/setup-r8a7740.c b/arch/arm/mach-shmobile/setup-r8a7740.c
index 0952224..b85bea5 100644
--- a/arch/arm/mach-shmobile/setup-r8a7740.c
+++ b/arch/arm/mach-shmobile/setup-r8a7740.c
@@ -28,6 +28,7 @@
#include <linux/sh_dma.h>
#include <linux/sh_timer.h>
#include <linux/dma-mapping.h>
+#include <linux/platform_data/sh_ipmmu.h>
#include <mach/dma-register.h>
#include <mach/r8a7740.h>
#include <mach/pm-rmobile.h>
@@ -262,6 +263,37 @@ static struct platform_device cmt10_device = {
.num_resources = ARRAY_SIZE(cmt10_resources),
};
+/* IPMMUI (an IPMMU module for ICB/LMB) */
+static struct resource ipmmu_resources[] = {
+ [0] = {
+ .name = "IPMMUI",
+ .start = 0xfe951000,
+ .end = 0xfe9510ff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static const char * const ipmmu_dev_names[] = {
+ "sh_mobile_lcdc_fb.0",
+ "sh_mobile_lcdc_fb.1",
+ "sh_mobile_ceu.0",
+};
+
+static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
+ .dev_names = ipmmu_dev_names,
+ .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
+};
+
+static struct platform_device ipmmu_device = {
+ .name = "ipmmu",
+ .id = -1,
+ .dev = {
+ .platform_data = &ipmmu_platform_data,
+ },
+ .resource = ipmmu_resources,
+ .num_resources = ARRAY_SIZE(ipmmu_resources),
+};
+
static struct platform_device *r8a7740_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
@@ -273,6 +305,7 @@ static struct platform_device *r8a7740_early_devices[] __initdata = {
&scif7_device,
&scifb_device,
&cmt10_device,
+ &ipmmu_device,
};
/* DMA */
--
1.8.0
^ permalink raw reply related
* [PATCH v5 4/4] ARM: mach-shmobile: r8a7740: Add IPMMU device
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: Paul Mundt, Magnus Damm, Russell King, Simon Horman,
Laurent Pinchart
Cc: linux-sh, iommu, linux-arm-kernel, linux-kernel, Marek Szyprowski,
Katsuya MATSUBARA, Damian Hobson-Garcia, Hideki EIRAKU
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This patch adds an IPMMU device and notifies the IPMMU driver which
devices are connected via the IPMMU module. All devices connected to the main
memory bus via the IPMMU module MUST be registered when SHMOBILE_IPMMU and
SHMOBILE_IOMMU are enabled because physical address cannot be used
while the IPMMU module's MMU function is enabled.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
arch/arm/mach-shmobile/setup-r8a7740.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/arch/arm/mach-shmobile/setup-r8a7740.c b/arch/arm/mach-shmobile/setup-r8a7740.c
index 0952224..b85bea5 100644
--- a/arch/arm/mach-shmobile/setup-r8a7740.c
+++ b/arch/arm/mach-shmobile/setup-r8a7740.c
@@ -28,6 +28,7 @@
#include <linux/sh_dma.h>
#include <linux/sh_timer.h>
#include <linux/dma-mapping.h>
+#include <linux/platform_data/sh_ipmmu.h>
#include <mach/dma-register.h>
#include <mach/r8a7740.h>
#include <mach/pm-rmobile.h>
@@ -262,6 +263,37 @@ static struct platform_device cmt10_device = {
.num_resources = ARRAY_SIZE(cmt10_resources),
};
+/* IPMMUI (an IPMMU module for ICB/LMB) */
+static struct resource ipmmu_resources[] = {
+ [0] = {
+ .name = "IPMMUI",
+ .start = 0xfe951000,
+ .end = 0xfe9510ff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static const char * const ipmmu_dev_names[] = {
+ "sh_mobile_lcdc_fb.0",
+ "sh_mobile_lcdc_fb.1",
+ "sh_mobile_ceu.0",
+};
+
+static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
+ .dev_names = ipmmu_dev_names,
+ .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
+};
+
+static struct platform_device ipmmu_device = {
+ .name = "ipmmu",
+ .id = -1,
+ .dev = {
+ .platform_data = &ipmmu_platform_data,
+ },
+ .resource = ipmmu_resources,
+ .num_resources = ARRAY_SIZE(ipmmu_resources),
+};
+
static struct platform_device *r8a7740_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
@@ -273,6 +305,7 @@ static struct platform_device *r8a7740_early_devices[] __initdata = {
&scif7_device,
&scifb_device,
&cmt10_device,
+ &ipmmu_device,
};
/* DMA */
--
1.8.0
^ permalink raw reply related
* [PATCH v5 3/4] ARM: mach-shmobile: sh73a0: Add IPMMU device
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This patch adds an IPMMU device and notifies the IPMMU driver which
devices are connected via the IPMMU module. All devices connected to the main
memory bus via the IPMMU module MUST be registered when SHMOBILE_IPMMU and
SHMOBILE_IOMMU are enabled because physical address cannot be used
while the IPMMU module's MMU function is enabled.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
arch/arm/mach-shmobile/setup-sh73a0.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/arch/arm/mach-shmobile/setup-sh73a0.c b/arch/arm/mach-shmobile/setup-sh73a0.c
index db99a4a..36c2b2e 100644
--- a/arch/arm/mach-shmobile/setup-sh73a0.c
+++ b/arch/arm/mach-shmobile/setup-sh73a0.c
@@ -30,6 +30,7 @@
#include <linux/sh_dma.h>
#include <linux/sh_intc.h>
#include <linux/sh_timer.h>
+#include <linux/platform_data/sh_ipmmu.h>
#include <mach/dma-register.h>
#include <mach/hardware.h>
#include <mach/irqs.h>
@@ -754,6 +755,35 @@ static struct platform_device pmu_device = {
.resource = pmu_resources,
};
+/* an IPMMU module for ICB */
+static struct resource ipmmu_resources[] = {
+ [0] = {
+ .name = "IPMMU",
+ .start = 0xfe951000,
+ .end = 0xfe9510ff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static const char * const ipmmu_dev_names[] = {
+ "sh_mobile_lcdc_fb.0",
+};
+
+static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
+ .dev_names = ipmmu_dev_names,
+ .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
+};
+
+static struct platform_device ipmmu_device = {
+ .name = "ipmmu",
+ .id = -1,
+ .dev = {
+ .platform_data = &ipmmu_platform_data,
+ },
+ .resource = ipmmu_resources,
+ .num_resources = ARRAY_SIZE(ipmmu_resources),
+};
+
static struct platform_device *sh73a0_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
@@ -767,6 +797,7 @@ static struct platform_device *sh73a0_early_devices[] __initdata = {
&cmt10_device,
&tmu00_device,
&tmu01_device,
+ &ipmmu_device,
};
static struct platform_device *sh73a0_late_devices[] __initdata = {
--
1.8.0
^ permalink raw reply related
* [PATCH v5 3/4] ARM: mach-shmobile: sh73a0: Add IPMMU device
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This patch adds an IPMMU device and notifies the IPMMU driver which
devices are connected via the IPMMU module. All devices connected to the main
memory bus via the IPMMU module MUST be registered when SHMOBILE_IPMMU and
SHMOBILE_IOMMU are enabled because physical address cannot be used
while the IPMMU module's MMU function is enabled.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
arch/arm/mach-shmobile/setup-sh73a0.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/arch/arm/mach-shmobile/setup-sh73a0.c b/arch/arm/mach-shmobile/setup-sh73a0.c
index db99a4a..36c2b2e 100644
--- a/arch/arm/mach-shmobile/setup-sh73a0.c
+++ b/arch/arm/mach-shmobile/setup-sh73a0.c
@@ -30,6 +30,7 @@
#include <linux/sh_dma.h>
#include <linux/sh_intc.h>
#include <linux/sh_timer.h>
+#include <linux/platform_data/sh_ipmmu.h>
#include <mach/dma-register.h>
#include <mach/hardware.h>
#include <mach/irqs.h>
@@ -754,6 +755,35 @@ static struct platform_device pmu_device = {
.resource = pmu_resources,
};
+/* an IPMMU module for ICB */
+static struct resource ipmmu_resources[] = {
+ [0] = {
+ .name = "IPMMU",
+ .start = 0xfe951000,
+ .end = 0xfe9510ff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static const char * const ipmmu_dev_names[] = {
+ "sh_mobile_lcdc_fb.0",
+};
+
+static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
+ .dev_names = ipmmu_dev_names,
+ .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
+};
+
+static struct platform_device ipmmu_device = {
+ .name = "ipmmu",
+ .id = -1,
+ .dev = {
+ .platform_data = &ipmmu_platform_data,
+ },
+ .resource = ipmmu_resources,
+ .num_resources = ARRAY_SIZE(ipmmu_resources),
+};
+
static struct platform_device *sh73a0_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
@@ -767,6 +797,7 @@ static struct platform_device *sh73a0_early_devices[] __initdata = {
&cmt10_device,
&tmu00_device,
&tmu01_device,
+ &ipmmu_device,
};
static struct platform_device *sh73a0_late_devices[] __initdata = {
--
1.8.0
^ permalink raw reply related
* [PATCH v5 3/4] ARM: mach-shmobile: sh73a0: Add IPMMU device
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: Paul Mundt, Magnus Damm, Russell King, Simon Horman,
Laurent Pinchart
Cc: linux-sh, iommu, linux-arm-kernel, linux-kernel, Marek Szyprowski,
Katsuya MATSUBARA, Damian Hobson-Garcia, Hideki EIRAKU
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This patch adds an IPMMU device and notifies the IPMMU driver which
devices are connected via the IPMMU module. All devices connected to the main
memory bus via the IPMMU module MUST be registered when SHMOBILE_IPMMU and
SHMOBILE_IOMMU are enabled because physical address cannot be used
while the IPMMU module's MMU function is enabled.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
arch/arm/mach-shmobile/setup-sh73a0.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/arch/arm/mach-shmobile/setup-sh73a0.c b/arch/arm/mach-shmobile/setup-sh73a0.c
index db99a4a..36c2b2e 100644
--- a/arch/arm/mach-shmobile/setup-sh73a0.c
+++ b/arch/arm/mach-shmobile/setup-sh73a0.c
@@ -30,6 +30,7 @@
#include <linux/sh_dma.h>
#include <linux/sh_intc.h>
#include <linux/sh_timer.h>
+#include <linux/platform_data/sh_ipmmu.h>
#include <mach/dma-register.h>
#include <mach/hardware.h>
#include <mach/irqs.h>
@@ -754,6 +755,35 @@ static struct platform_device pmu_device = {
.resource = pmu_resources,
};
+/* an IPMMU module for ICB */
+static struct resource ipmmu_resources[] = {
+ [0] = {
+ .name = "IPMMU",
+ .start = 0xfe951000,
+ .end = 0xfe9510ff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static const char * const ipmmu_dev_names[] = {
+ "sh_mobile_lcdc_fb.0",
+};
+
+static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
+ .dev_names = ipmmu_dev_names,
+ .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
+};
+
+static struct platform_device ipmmu_device = {
+ .name = "ipmmu",
+ .id = -1,
+ .dev = {
+ .platform_data = &ipmmu_platform_data,
+ },
+ .resource = ipmmu_resources,
+ .num_resources = ARRAY_SIZE(ipmmu_resources),
+};
+
static struct platform_device *sh73a0_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
@@ -767,6 +797,7 @@ static struct platform_device *sh73a0_early_devices[] __initdata = {
&cmt10_device,
&tmu00_device,
&tmu01_device,
+ &ipmmu_device,
};
static struct platform_device *sh73a0_late_devices[] __initdata = {
--
1.8.0
^ permalink raw reply related
* [PATCH v5 2/4] ARM: mach-shmobile: sh7372: Add IPMMU device
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This patch adds an IPMMU device and notifies the IPMMU driver which
devices are connected via the IPMMU module. All devices connected to the main
memory bus via the IPMMU module MUST be registered when SHMOBILE_IPMMU and
SHMOBILE_IOMMU are enabled because physical address cannot be used
while the IPMMU module's MMU function is enabled.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
arch/arm/mach-shmobile/setup-sh7372.c | 39 +++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/arch/arm/mach-shmobile/setup-sh7372.c b/arch/arm/mach-shmobile/setup-sh7372.c
index c917882..04ad98e 100644
--- a/arch/arm/mach-shmobile/setup-sh7372.c
+++ b/arch/arm/mach-shmobile/setup-sh7372.c
@@ -33,6 +33,7 @@
#include <linux/sh_timer.h>
#include <linux/pm_domain.h>
#include <linux/dma-mapping.h>
+#include <linux/platform_data/sh_ipmmu.h>
#include <mach/dma-register.h>
#include <mach/hardware.h>
#include <mach/irqs.h>
@@ -982,6 +983,43 @@ static struct platform_device spu1_device = {
.num_resources = ARRAY_SIZE(spu1_resources),
};
+/* IPMMUI (an IPMMU module for ICB/LMB) */
+static struct resource ipmmu_resources[] = {
+ [0] = {
+ .name = "IPMMUI",
+ .start = 0xfe951000,
+ .end = 0xfe9510ff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static const char * const ipmmu_dev_names[] = {
+ "sh_mobile_lcdc_fb.0",
+ "sh_mobile_lcdc_fb.1",
+ "sh_mobile_ceu.0",
+ "uio_pdrv_genirq.0",
+ "uio_pdrv_genirq.1",
+ "uio_pdrv_genirq.2",
+ "uio_pdrv_genirq.3",
+ "uio_pdrv_genirq.4",
+ "uio_pdrv_genirq.5",
+};
+
+static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
+ .dev_names = ipmmu_dev_names,
+ .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
+};
+
+static struct platform_device ipmmu_device = {
+ .name = "ipmmu",
+ .id = -1,
+ .dev = {
+ .platform_data = &ipmmu_platform_data,
+ },
+ .resource = ipmmu_resources,
+ .num_resources = ARRAY_SIZE(ipmmu_resources),
+};
+
static struct platform_device *sh7372_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
@@ -993,6 +1031,7 @@ static struct platform_device *sh7372_early_devices[] __initdata = {
&cmt2_device,
&tmu00_device,
&tmu01_device,
+ &ipmmu_device,
};
static struct platform_device *sh7372_late_devices[] __initdata = {
--
1.8.0
^ permalink raw reply related
* [PATCH v5 2/4] ARM: mach-shmobile: sh7372: Add IPMMU device
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This patch adds an IPMMU device and notifies the IPMMU driver which
devices are connected via the IPMMU module. All devices connected to the main
memory bus via the IPMMU module MUST be registered when SHMOBILE_IPMMU and
SHMOBILE_IOMMU are enabled because physical address cannot be used
while the IPMMU module's MMU function is enabled.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
arch/arm/mach-shmobile/setup-sh7372.c | 39 +++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/arch/arm/mach-shmobile/setup-sh7372.c b/arch/arm/mach-shmobile/setup-sh7372.c
index c917882..04ad98e 100644
--- a/arch/arm/mach-shmobile/setup-sh7372.c
+++ b/arch/arm/mach-shmobile/setup-sh7372.c
@@ -33,6 +33,7 @@
#include <linux/sh_timer.h>
#include <linux/pm_domain.h>
#include <linux/dma-mapping.h>
+#include <linux/platform_data/sh_ipmmu.h>
#include <mach/dma-register.h>
#include <mach/hardware.h>
#include <mach/irqs.h>
@@ -982,6 +983,43 @@ static struct platform_device spu1_device = {
.num_resources = ARRAY_SIZE(spu1_resources),
};
+/* IPMMUI (an IPMMU module for ICB/LMB) */
+static struct resource ipmmu_resources[] = {
+ [0] = {
+ .name = "IPMMUI",
+ .start = 0xfe951000,
+ .end = 0xfe9510ff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static const char * const ipmmu_dev_names[] = {
+ "sh_mobile_lcdc_fb.0",
+ "sh_mobile_lcdc_fb.1",
+ "sh_mobile_ceu.0",
+ "uio_pdrv_genirq.0",
+ "uio_pdrv_genirq.1",
+ "uio_pdrv_genirq.2",
+ "uio_pdrv_genirq.3",
+ "uio_pdrv_genirq.4",
+ "uio_pdrv_genirq.5",
+};
+
+static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
+ .dev_names = ipmmu_dev_names,
+ .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
+};
+
+static struct platform_device ipmmu_device = {
+ .name = "ipmmu",
+ .id = -1,
+ .dev = {
+ .platform_data = &ipmmu_platform_data,
+ },
+ .resource = ipmmu_resources,
+ .num_resources = ARRAY_SIZE(ipmmu_resources),
+};
+
static struct platform_device *sh7372_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
@@ -993,6 +1031,7 @@ static struct platform_device *sh7372_early_devices[] __initdata = {
&cmt2_device,
&tmu00_device,
&tmu01_device,
+ &ipmmu_device,
};
static struct platform_device *sh7372_late_devices[] __initdata = {
--
1.8.0
^ permalink raw reply related
* [PATCH v5 2/4] ARM: mach-shmobile: sh7372: Add IPMMU device
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: Paul Mundt, Magnus Damm, Russell King, Simon Horman,
Laurent Pinchart
Cc: linux-sh, iommu, linux-arm-kernel, linux-kernel, Marek Szyprowski,
Katsuya MATSUBARA, Damian Hobson-Garcia, Hideki EIRAKU
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This patch adds an IPMMU device and notifies the IPMMU driver which
devices are connected via the IPMMU module. All devices connected to the main
memory bus via the IPMMU module MUST be registered when SHMOBILE_IPMMU and
SHMOBILE_IOMMU are enabled because physical address cannot be used
while the IPMMU module's MMU function is enabled.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
arch/arm/mach-shmobile/setup-sh7372.c | 39 +++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/arch/arm/mach-shmobile/setup-sh7372.c b/arch/arm/mach-shmobile/setup-sh7372.c
index c917882..04ad98e 100644
--- a/arch/arm/mach-shmobile/setup-sh7372.c
+++ b/arch/arm/mach-shmobile/setup-sh7372.c
@@ -33,6 +33,7 @@
#include <linux/sh_timer.h>
#include <linux/pm_domain.h>
#include <linux/dma-mapping.h>
+#include <linux/platform_data/sh_ipmmu.h>
#include <mach/dma-register.h>
#include <mach/hardware.h>
#include <mach/irqs.h>
@@ -982,6 +983,43 @@ static struct platform_device spu1_device = {
.num_resources = ARRAY_SIZE(spu1_resources),
};
+/* IPMMUI (an IPMMU module for ICB/LMB) */
+static struct resource ipmmu_resources[] = {
+ [0] = {
+ .name = "IPMMUI",
+ .start = 0xfe951000,
+ .end = 0xfe9510ff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static const char * const ipmmu_dev_names[] = {
+ "sh_mobile_lcdc_fb.0",
+ "sh_mobile_lcdc_fb.1",
+ "sh_mobile_ceu.0",
+ "uio_pdrv_genirq.0",
+ "uio_pdrv_genirq.1",
+ "uio_pdrv_genirq.2",
+ "uio_pdrv_genirq.3",
+ "uio_pdrv_genirq.4",
+ "uio_pdrv_genirq.5",
+};
+
+static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
+ .dev_names = ipmmu_dev_names,
+ .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
+};
+
+static struct platform_device ipmmu_device = {
+ .name = "ipmmu",
+ .id = -1,
+ .dev = {
+ .platform_data = &ipmmu_platform_data,
+ },
+ .resource = ipmmu_resources,
+ .num_resources = ARRAY_SIZE(ipmmu_resources),
+};
+
static struct platform_device *sh7372_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
@@ -993,6 +1031,7 @@ static struct platform_device *sh7372_early_devices[] __initdata = {
&cmt2_device,
&tmu00_device,
&tmu01_device,
+ &ipmmu_device,
};
static struct platform_device *sh7372_late_devices[] __initdata = {
--
1.8.0
^ permalink raw reply related
* [PATCH v5 1/4] iommu/shmobile: Add iommu driver for Renesas IPMMU modules
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This is the Renesas IPMMU driver and IOMMU API implementation.
The IPMMU module supports the MMU function and the PMB function. The
MMU function provides address translation by pagetable compatible with
ARMv6. The PMB function provides address translation including
tile-linear translation. This patch implements the MMU function.
The iommu driver does not register a platform driver directly because:
- the register space of the MMU function and the PMB function
have a common register (used for settings flush), so they should ideally
have a way to appropriately share this register.
- the MMU function uses the IOMMU API while the PMB function does not.
- the two functions may be used independently.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
drivers/iommu/Kconfig | 74 +++++++
drivers/iommu/Makefile | 2 +
drivers/iommu/shmobile-iommu.c | 341 +++++++++++++++++++++++++++++++++
drivers/iommu/shmobile-ipmmu.c | 136 +++++++++++++
drivers/iommu/shmobile-ipmmu.h | 37 ++++
include/linux/platform_data/sh_ipmmu.h | 18 ++
6 files changed, 608 insertions(+)
create mode 100644 drivers/iommu/shmobile-iommu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.h
create mode 100644 include/linux/platform_data/sh_ipmmu.h
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index e39f9db..d364494 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -187,4 +187,78 @@ config EXYNOS_IOMMU_DEBUG
Say N unless you need kernel log message for IOMMU debugging
+config SHMOBILE_IPMMU
+ bool
+
+config SHMOBILE_IPMMU_TLB
+ bool
+
+config SHMOBILE_IOMMU
+ bool "IOMMU for Renesas IPMMU/IPMMUI"
+ default n
+ depends on (ARM && ARCH_SHMOBILE)
+ select IOMMU_API
+ select ARM_DMA_USE_IOMMU
+ select SHMOBILE_IPMMU
+ select SHMOBILE_IPMMU_TLB
+ help
+ Support for Renesas IPMMU/IPMMUI. This option enables
+ remapping of DMA memory accesses from all of the IP blocks
+ on the ICB.
+
+ Warning: Drivers (including userspace drivers of UIO
+ devices) of the IP blocks on the ICB *must* use addresses
+ allocated from the IPMMU (iova) for DMA with this option
+ enabled.
+
+ If unsure, say N.
+
+choice
+ prompt "IPMMU/IPMMUI address space size"
+ default SHMOBILE_IOMMU_ADDRSIZE_2048MB
+ depends on SHMOBILE_IOMMU
+ help
+ This option sets IPMMU/IPMMUI address space size by
+ adjusting the 1st level page table size. The page table size
+ is calculated as follows:
+
+ page table size = number of page table entries * 4 bytes
+ number of page table entries = address space size / 1 MiB
+
+ For example, when the address space size is 2048 MiB, the
+ 1st level page table size is 8192 bytes.
+
+ config SHMOBILE_IOMMU_ADDRSIZE_2048MB
+ bool "2 GiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_1024MB
+ bool "1 GiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_512MB
+ bool "512 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_256MB
+ bool "256 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_128MB
+ bool "128 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_64MB
+ bool "64 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_32MB
+ bool "32 MiB"
+
+endchoice
+
+config SHMOBILE_IOMMU_L1SIZE
+ int
+ default 8192 if SHMOBILE_IOMMU_ADDRSIZE_2048MB
+ default 4096 if SHMOBILE_IOMMU_ADDRSIZE_1024MB
+ default 2048 if SHMOBILE_IOMMU_ADDRSIZE_512MB
+ default 1024 if SHMOBILE_IOMMU_ADDRSIZE_256MB
+ default 512 if SHMOBILE_IOMMU_ADDRSIZE_128MB
+ default 256 if SHMOBILE_IOMMU_ADDRSIZE_64MB
+ default 128 if SHMOBILE_IOMMU_ADDRSIZE_32MB
+
endif # IOMMU_SUPPORT
diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
index f66b816..ef0e520 100644
--- a/drivers/iommu/Makefile
+++ b/drivers/iommu/Makefile
@@ -13,3 +13,5 @@ obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o
obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o
obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o
obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o
+obj-$(CONFIG_SHMOBILE_IOMMU) += shmobile-iommu.o
+obj-$(CONFIG_SHMOBILE_IPMMU) += shmobile-ipmmu.o
diff --git a/drivers/iommu/shmobile-iommu.c b/drivers/iommu/shmobile-iommu.c
new file mode 100644
index 0000000..360a06f
--- /dev/null
+++ b/drivers/iommu/shmobile-iommu.c
@@ -0,0 +1,341 @@
+/*
+ * IOMMU for IPMMU/IPMMUI
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/dma-mapping.h>
+#include <linux/dmapool.h>
+#include <linux/io.h>
+#include <linux/iommu.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <asm/dma-iommu.h>
+#include "shmobile-ipmmu.h"
+
+#define L1_SIZE CONFIG_SHMOBILE_IOMMU_L1SIZE
+#define L1_LEN (L1_SIZE / 4)
+#define L1_ALIGN L1_SIZE
+#define L2_SIZE 0x400
+#define L2_LEN (L2_SIZE / 4)
+#define L2_ALIGN L2_SIZE
+
+struct shmobile_iommu_domain_pgtable {
+ uint32_t *pgtable;
+ dma_addr_t handle;
+};
+
+struct shmobile_iommu_domain {
+ struct shmobile_ipmmu *ipmmu;
+ struct shmobile_iommu_domain_pgtable l1, l2[L1_LEN];
+ spinlock_t map_lock;
+ atomic_t active;
+};
+
+static struct shmobile_ipmmu *platform_bus_ipmmu;
+static struct dma_pool *l1pool, *l2pool;
+static spinlock_t lock;
+static struct shmobile_iommu_domain *attached;
+static int num_attached_devices;
+
+static int shmobile_iommu_domain_init(struct iommu_domain *domain)
+{
+ struct shmobile_iommu_domain *sh_domain;
+ int i;
+
+ sh_domain = kmalloc(sizeof(*sh_domain), GFP_KERNEL);
+ if (!sh_domain)
+ return -ENOMEM;
+ sh_domain->l1.pgtable = dma_pool_alloc(l1pool, GFP_KERNEL,
+ &sh_domain->l1.handle);
+ if (!sh_domain->l1.pgtable) {
+ kfree(sh_domain);
+ return -ENOMEM;
+ }
+ for (i = 0; i < L1_LEN; i++)
+ sh_domain->l2[i].pgtable = NULL;
+ memset(sh_domain->l1.pgtable, 0, L1_SIZE);
+ spin_lock_init(&sh_domain->map_lock);
+ atomic_set(&sh_domain->active, 0);
+ domain->priv = sh_domain;
+ return 0;
+}
+
+static void shmobile_iommu_domain_destroy(struct iommu_domain *domain)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ int i;
+
+ for (i = 0; i < L1_LEN; i++) {
+ if (sh_domain->l2[i].pgtable)
+ dma_pool_free(l2pool, sh_domain->l2[i].pgtable,
+ sh_domain->l2[i].handle);
+ }
+ dma_pool_free(l1pool, sh_domain->l1.pgtable, sh_domain->l1.handle);
+ kfree(sh_domain);
+ domain->priv = NULL;
+}
+
+static int shmobile_iommu_attach_device(struct iommu_domain *domain,
+ struct device *dev)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ struct shmobile_ipmmu *ipmmu = platform_bus_ipmmu;
+ int ret = -EBUSY;
+
+ spin_lock(&lock);
+ if (attached != sh_domain) {
+ if (attached)
+ goto err;
+ atomic_set(&sh_domain->active, 1);
+ ipmmu_tlb_set(ipmmu, sh_domain->l1.handle, L1_SIZE, 0);
+ wmb();
+ ipmmu_tlb_flush(ipmmu);
+ attached = sh_domain;
+ num_attached_devices = 0;
+ sh_domain->ipmmu = ipmmu;
+ }
+ num_attached_devices++;
+ ret = 0;
+err:
+ spin_unlock(&lock);
+ return ret;
+}
+
+static void shmobile_iommu_detach_device(struct iommu_domain *domain,
+ struct device *dev)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ struct shmobile_ipmmu *ipmmu = platform_bus_ipmmu;
+
+ spin_lock(&lock);
+ atomic_set(&sh_domain->active, 0);
+ num_attached_devices--;
+ if (!num_attached_devices) {
+ ipmmu_tlb_set(ipmmu, 0, 0, 0);
+ ipmmu_tlb_flush(ipmmu);
+ attached = NULL;
+ sh_domain->ipmmu = NULL;
+ }
+ spin_unlock(&lock);
+}
+
+static int
+l2alloc(struct shmobile_iommu_domain *sh_domain, unsigned int l1index)
+{
+ if (!sh_domain->l2[l1index].pgtable) {
+ sh_domain->l2[l1index].pgtable = dma_pool_alloc(l2pool,
+ GFP_KERNEL,
+ &sh_domain->l2[l1index].handle);
+ if (!sh_domain->l2[l1index].pgtable)
+ return -ENOMEM;
+ memset(sh_domain->l2[l1index].pgtable, 0, L2_SIZE);
+ }
+ sh_domain->l1.pgtable[l1index] = sh_domain->l2[l1index].handle | 0x1;
+ return 0;
+}
+
+static void
+l2realfree(struct shmobile_iommu_domain_pgtable *l2)
+{
+ if (l2->pgtable)
+ dma_pool_free(l2pool, l2->pgtable, l2->handle);
+}
+
+static int
+l2free(struct shmobile_iommu_domain *sh_domain, unsigned int l1index,
+ struct shmobile_iommu_domain_pgtable *l2)
+{
+ sh_domain->l1.pgtable[l1index] = 0;
+ if (sh_domain->l2[l1index].pgtable) {
+ *l2 = sh_domain->l2[l1index];
+ sh_domain->l2[l1index].pgtable = NULL;
+ }
+ return 0;
+}
+
+static int shmobile_iommu_map(struct iommu_domain *domain, unsigned long iova,
+ phys_addr_t paddr, size_t size, int prot)
+{
+ struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL };
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ unsigned int l1index, l2index, i;
+ int ret;
+
+ l1index = iova >> 20;
+ switch (size) {
+ case 0x1000:
+ l2index = (iova >> 12) & 0xff;
+ spin_lock(&sh_domain->map_lock);
+ ret = l2alloc(sh_domain, l1index);
+ if (!ret)
+ sh_domain->l2[l1index].pgtable[l2index] = paddr | 0xff2;
+ spin_unlock(&sh_domain->map_lock);
+ break;
+ case 0x10000:
+ l2index = (iova >> 12) & 0xf0;
+ spin_lock(&sh_domain->map_lock);
+ ret = l2alloc(sh_domain, l1index);
+ if (!ret) {
+ for (i = 0; i < 0x10; i++)
+ sh_domain->l2[l1index].pgtable[l2index + i] =
+ paddr | 0xff1;
+ }
+ spin_unlock(&sh_domain->map_lock);
+ break;
+ case 0x100000:
+ spin_lock(&sh_domain->map_lock);
+ l2free(sh_domain, l1index, &l2);
+ sh_domain->l1.pgtable[l1index] = paddr | 0xc02;
+ spin_unlock(&sh_domain->map_lock);
+ ret = 0;
+ break;
+ default:
+ ret = -EINVAL;
+ }
+ if (!ret && atomic_read(&sh_domain->active)) {
+ wmb();
+ ipmmu_tlb_flush(sh_domain->ipmmu);
+ l2realfree(&l2);
+ }
+ return ret;
+}
+
+static size_t shmobile_iommu_unmap(struct iommu_domain *domain,
+ unsigned long iova, size_t size)
+{
+ struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL };
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ unsigned int l1index, l2index, i;
+ uint32_t l2entry = 0;
+ size_t ret = 0;
+
+ l1index = iova >> 20;
+ if (!(iova & 0xFFFFF) && size >= 0x100000) {
+ spin_lock(&sh_domain->map_lock);
+ l2free(sh_domain, l1index, &l2);
+ spin_unlock(&sh_domain->map_lock);
+ ret = 0x100000;
+ goto done;
+ }
+ l2index = (iova >> 12) & 0xff;
+ spin_lock(&sh_domain->map_lock);
+ if (sh_domain->l2[l1index].pgtable)
+ l2entry = sh_domain->l2[l1index].pgtable[l2index];
+ switch (l2entry & 3) {
+ case 1:
+ if (l2index & 0xf)
+ break;
+ for (i = 0; i < 0x10; i++)
+ sh_domain->l2[l1index].pgtable[l2index + i] = 0;
+ ret = 0x10000;
+ break;
+ case 2:
+ sh_domain->l2[l1index].pgtable[l2index] = 0;
+ ret = 0x1000;
+ break;
+ }
+ spin_unlock(&sh_domain->map_lock);
+done:
+ if (ret && atomic_read(&sh_domain->active)) {
+ wmb();
+ ipmmu_tlb_flush(sh_domain->ipmmu);
+ l2realfree(&l2);
+ }
+ return ret;
+}
+
+static phys_addr_t shmobile_iommu_iova_to_phys(struct iommu_domain *domain,
+ unsigned long iova)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ uint32_t l1entry = 0, l2entry = 0;
+ unsigned int l1index, l2index;
+
+ l1index = iova >> 20;
+ l2index = (iova >> 12) & 0xff;
+ spin_lock(&sh_domain->map_lock);
+ if (sh_domain->l2[l1index].pgtable)
+ l2entry = sh_domain->l2[l1index].pgtable[l2index];
+ else
+ l1entry = sh_domain->l1.pgtable[l1index];
+ spin_unlock(&sh_domain->map_lock);
+ switch (l2entry & 3) {
+ case 1:
+ return (l2entry & ~0xffff) | (iova & 0xffff);
+ case 2:
+ return (l2entry & ~0xfff) | (iova & 0xfff);
+ default:
+ if ((l1entry & 3) == 2)
+ return (l1entry & ~0xfffff) | (iova & 0xfffff);
+ return 0;
+ }
+}
+
+static int find_dev_name(struct shmobile_ipmmu *ipmmu, const char *dev_name)
+{
+ unsigned int i, n = ipmmu->num_dev_names;
+
+ for (i = 0; i < n; i++) {
+ if (strcmp(ipmmu->dev_names[i], dev_name) == 0)
+ return 1;
+ }
+ return 0;
+}
+
+static int shmobile_iommu_add_device(struct device *dev)
+{
+ struct shmobile_ipmmu *ipmmu = platform_bus_ipmmu;
+ struct dma_iommu_mapping *mapping;
+
+ if (!find_dev_name(ipmmu, dev_name(dev)))
+ return 0;
+ mapping = ipmmu->iommu_mapping;
+ if (!mapping) {
+ mapping = arm_iommu_create_mapping(&platform_bus_type, 0,
+ L1_LEN << 20, 0);
+ if (IS_ERR(mapping))
+ return PTR_ERR(mapping);
+ ipmmu->iommu_mapping = mapping;
+ }
+ if (arm_iommu_attach_device(dev, mapping))
+ pr_err("arm_iommu_attach_device failed\n");
+ return 0;
+}
+
+static struct iommu_ops shmobile_iommu_ops = {
+ .domain_init = shmobile_iommu_domain_init,
+ .domain_destroy = shmobile_iommu_domain_destroy,
+ .attach_dev = shmobile_iommu_attach_device,
+ .detach_dev = shmobile_iommu_detach_device,
+ .map = shmobile_iommu_map,
+ .unmap = shmobile_iommu_unmap,
+ .iova_to_phys = shmobile_iommu_iova_to_phys,
+ .add_device = shmobile_iommu_add_device,
+ .pgsize_bitmap = 0x111000,
+};
+
+int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu)
+{
+ dma_set_coherent_mask(ipmmu->dev, DMA_BIT_MASK(32));
+ l1pool = dma_pool_create("shmobile-iommu-pgtable1", ipmmu->dev,
+ L1_SIZE, L1_ALIGN, 0);
+ if (!l1pool)
+ goto nomem_pool1;
+ l2pool = dma_pool_create("shmobile-iommu-pgtable2", ipmmu->dev,
+ L2_SIZE, L2_ALIGN, 0);
+ if (!l2pool)
+ goto nomem_pool2;
+ spin_lock_init(&lock);
+ attached = NULL;
+ platform_bus_ipmmu = ipmmu;
+ bus_set_iommu(&platform_bus_type, &shmobile_iommu_ops);
+ return 0;
+nomem_pool2:
+ dma_pool_destroy(l1pool);
+nomem_pool1:
+ return -ENOMEM;
+}
diff --git a/drivers/iommu/shmobile-ipmmu.c b/drivers/iommu/shmobile-ipmmu.c
new file mode 100644
index 0000000..8321f89
--- /dev/null
+++ b/drivers/iommu/shmobile-ipmmu.c
@@ -0,0 +1,136 @@
+/*
+ * IPMMU/IPMMUI
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/platform_data/sh_ipmmu.h>
+#include "shmobile-ipmmu.h"
+
+#define IMCTR1 0x000
+#define IMCTR2 0x004
+#define IMASID 0x010
+#define IMTTBR 0x014
+#define IMTTBCR 0x018
+
+#define IMCTR1_TLBEN (1 << 0)
+#define IMCTR1_FLUSH (1 << 1)
+
+static void ipmmu_reg_write(struct shmobile_ipmmu *ipmmu, unsigned long reg_off,
+ unsigned long data)
+{
+ iowrite32(data, ipmmu->ipmmu_base + reg_off);
+}
+
+void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu)
+{
+ if (!ipmmu)
+ return;
+
+ mutex_lock(&ipmmu->flush_lock);
+ if (ipmmu->tlb_enabled)
+ ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH | IMCTR1_TLBEN);
+ else
+ ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH);
+ mutex_unlock(&ipmmu->flush_lock);
+}
+
+void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size,
+ int asid)
+{
+ if (!ipmmu)
+ return;
+
+ mutex_lock(&ipmmu->flush_lock);
+ switch (size) {
+ default:
+ ipmmu->tlb_enabled = 0;
+ break;
+ case 0x2000:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 1);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x1000:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 2);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x800:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 3);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x400:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 4);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x200:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 5);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x100:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 6);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x80:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 7);
+ ipmmu->tlb_enabled = 1;
+ break;
+ }
+ ipmmu_reg_write(ipmmu, IMTTBR, phys);
+ ipmmu_reg_write(ipmmu, IMASID, asid);
+ mutex_unlock(&ipmmu->flush_lock);
+}
+
+static int ipmmu_probe(struct platform_device *pdev)
+{
+ struct shmobile_ipmmu *ipmmu;
+ struct resource *res;
+ struct shmobile_ipmmu_platform_data *pdata = pdev->dev.platform_data;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(&pdev->dev, "cannot get platform resources\n");
+ return -ENOENT;
+ }
+ ipmmu = devm_kzalloc(&pdev->dev, sizeof(*ipmmu), GFP_KERNEL);
+ if (!ipmmu) {
+ dev_err(&pdev->dev, "cannot allocate device data\n");
+ return -ENOMEM;
+ }
+ mutex_init(&ipmmu->flush_lock);
+ ipmmu->dev = &pdev->dev;
+ ipmmu->ipmmu_base = devm_ioremap_nocache(&pdev->dev, res->start,
+ resource_size(res));
+ if (!ipmmu->ipmmu_base) {
+ dev_err(&pdev->dev, "ioremap_nocache failed\n");
+ return -ENOMEM;
+ }
+ ipmmu->dev_names = pdata->dev_names;
+ ipmmu->num_dev_names = pdata->num_dev_names;
+ platform_set_drvdata(pdev, ipmmu);
+ ipmmu_reg_write(ipmmu, IMCTR1, 0x0); /* disable TLB */
+ ipmmu_reg_write(ipmmu, IMCTR2, 0x0); /* disable PMB */
+ ipmmu_iommu_init(ipmmu);
+ return 0;
+}
+
+static struct platform_driver ipmmu_driver = {
+ .probe = ipmmu_probe,
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "ipmmu",
+ },
+};
+
+static int __init ipmmu_init(void)
+{
+ return platform_driver_register(&ipmmu_driver);
+}
+subsys_initcall(ipmmu_init);
diff --git a/drivers/iommu/shmobile-ipmmu.h b/drivers/iommu/shmobile-ipmmu.h
new file mode 100644
index 0000000..6270e7c
--- /dev/null
+++ b/drivers/iommu/shmobile-ipmmu.h
@@ -0,0 +1,37 @@
+/* shmobile-ipmmu.h
+ *
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#ifndef __SHMOBILE_IPMMU_H__
+#define __SHMOBILE_IPMMU_H__
+
+struct dma_iommu_mapping;
+
+struct shmobile_ipmmu {
+ struct device *dev;
+ void __iomem *ipmmu_base;
+ int tlb_enabled;
+ struct mutex flush_lock;
+ struct dma_iommu_mapping *iommu_mapping;
+ const char * const *dev_names;
+ unsigned int num_dev_names;
+};
+
+#ifdef CONFIG_SHMOBILE_IPMMU_TLB
+void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu);
+void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size,
+ int asid);
+int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu);
+#else
+static int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu)
+{
+ return -EINVAL;
+}
+#endif
+
+#endif /* __SHMOBILE_IPMMU_H__ */
diff --git a/include/linux/platform_data/sh_ipmmu.h b/include/linux/platform_data/sh_ipmmu.h
new file mode 100644
index 0000000..39f7405
--- /dev/null
+++ b/include/linux/platform_data/sh_ipmmu.h
@@ -0,0 +1,18 @@
+/* sh_ipmmu.h
+ *
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#ifndef __SH_IPMMU_H__
+#define __SH_IPMMU_H__
+
+struct shmobile_ipmmu_platform_data {
+ const char * const *dev_names;
+ unsigned int num_dev_names;
+};
+
+#endif /* __SH_IPMMU_H__ */
--
1.8.0
^ permalink raw reply related
* [PATCH v5 1/4] iommu/shmobile: Add iommu driver for Renesas IPMMU modules
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This is the Renesas IPMMU driver and IOMMU API implementation.
The IPMMU module supports the MMU function and the PMB function. The
MMU function provides address translation by pagetable compatible with
ARMv6. The PMB function provides address translation including
tile-linear translation. This patch implements the MMU function.
The iommu driver does not register a platform driver directly because:
- the register space of the MMU function and the PMB function
have a common register (used for settings flush), so they should ideally
have a way to appropriately share this register.
- the MMU function uses the IOMMU API while the PMB function does not.
- the two functions may be used independently.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
drivers/iommu/Kconfig | 74 +++++++
drivers/iommu/Makefile | 2 +
drivers/iommu/shmobile-iommu.c | 341 +++++++++++++++++++++++++++++++++
drivers/iommu/shmobile-ipmmu.c | 136 +++++++++++++
drivers/iommu/shmobile-ipmmu.h | 37 ++++
include/linux/platform_data/sh_ipmmu.h | 18 ++
6 files changed, 608 insertions(+)
create mode 100644 drivers/iommu/shmobile-iommu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.h
create mode 100644 include/linux/platform_data/sh_ipmmu.h
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index e39f9db..d364494 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -187,4 +187,78 @@ config EXYNOS_IOMMU_DEBUG
Say N unless you need kernel log message for IOMMU debugging
+config SHMOBILE_IPMMU
+ bool
+
+config SHMOBILE_IPMMU_TLB
+ bool
+
+config SHMOBILE_IOMMU
+ bool "IOMMU for Renesas IPMMU/IPMMUI"
+ default n
+ depends on (ARM && ARCH_SHMOBILE)
+ select IOMMU_API
+ select ARM_DMA_USE_IOMMU
+ select SHMOBILE_IPMMU
+ select SHMOBILE_IPMMU_TLB
+ help
+ Support for Renesas IPMMU/IPMMUI. This option enables
+ remapping of DMA memory accesses from all of the IP blocks
+ on the ICB.
+
+ Warning: Drivers (including userspace drivers of UIO
+ devices) of the IP blocks on the ICB *must* use addresses
+ allocated from the IPMMU (iova) for DMA with this option
+ enabled.
+
+ If unsure, say N.
+
+choice
+ prompt "IPMMU/IPMMUI address space size"
+ default SHMOBILE_IOMMU_ADDRSIZE_2048MB
+ depends on SHMOBILE_IOMMU
+ help
+ This option sets IPMMU/IPMMUI address space size by
+ adjusting the 1st level page table size. The page table size
+ is calculated as follows:
+
+ page table size = number of page table entries * 4 bytes
+ number of page table entries = address space size / 1 MiB
+
+ For example, when the address space size is 2048 MiB, the
+ 1st level page table size is 8192 bytes.
+
+ config SHMOBILE_IOMMU_ADDRSIZE_2048MB
+ bool "2 GiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_1024MB
+ bool "1 GiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_512MB
+ bool "512 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_256MB
+ bool "256 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_128MB
+ bool "128 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_64MB
+ bool "64 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_32MB
+ bool "32 MiB"
+
+endchoice
+
+config SHMOBILE_IOMMU_L1SIZE
+ int
+ default 8192 if SHMOBILE_IOMMU_ADDRSIZE_2048MB
+ default 4096 if SHMOBILE_IOMMU_ADDRSIZE_1024MB
+ default 2048 if SHMOBILE_IOMMU_ADDRSIZE_512MB
+ default 1024 if SHMOBILE_IOMMU_ADDRSIZE_256MB
+ default 512 if SHMOBILE_IOMMU_ADDRSIZE_128MB
+ default 256 if SHMOBILE_IOMMU_ADDRSIZE_64MB
+ default 128 if SHMOBILE_IOMMU_ADDRSIZE_32MB
+
endif # IOMMU_SUPPORT
diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
index f66b816..ef0e520 100644
--- a/drivers/iommu/Makefile
+++ b/drivers/iommu/Makefile
@@ -13,3 +13,5 @@ obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o
obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o
obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o
obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o
+obj-$(CONFIG_SHMOBILE_IOMMU) += shmobile-iommu.o
+obj-$(CONFIG_SHMOBILE_IPMMU) += shmobile-ipmmu.o
diff --git a/drivers/iommu/shmobile-iommu.c b/drivers/iommu/shmobile-iommu.c
new file mode 100644
index 0000000..360a06f
--- /dev/null
+++ b/drivers/iommu/shmobile-iommu.c
@@ -0,0 +1,341 @@
+/*
+ * IOMMU for IPMMU/IPMMUI
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/dma-mapping.h>
+#include <linux/dmapool.h>
+#include <linux/io.h>
+#include <linux/iommu.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <asm/dma-iommu.h>
+#include "shmobile-ipmmu.h"
+
+#define L1_SIZE CONFIG_SHMOBILE_IOMMU_L1SIZE
+#define L1_LEN (L1_SIZE / 4)
+#define L1_ALIGN L1_SIZE
+#define L2_SIZE 0x400
+#define L2_LEN (L2_SIZE / 4)
+#define L2_ALIGN L2_SIZE
+
+struct shmobile_iommu_domain_pgtable {
+ uint32_t *pgtable;
+ dma_addr_t handle;
+};
+
+struct shmobile_iommu_domain {
+ struct shmobile_ipmmu *ipmmu;
+ struct shmobile_iommu_domain_pgtable l1, l2[L1_LEN];
+ spinlock_t map_lock;
+ atomic_t active;
+};
+
+static struct shmobile_ipmmu *platform_bus_ipmmu;
+static struct dma_pool *l1pool, *l2pool;
+static spinlock_t lock;
+static struct shmobile_iommu_domain *attached;
+static int num_attached_devices;
+
+static int shmobile_iommu_domain_init(struct iommu_domain *domain)
+{
+ struct shmobile_iommu_domain *sh_domain;
+ int i;
+
+ sh_domain = kmalloc(sizeof(*sh_domain), GFP_KERNEL);
+ if (!sh_domain)
+ return -ENOMEM;
+ sh_domain->l1.pgtable = dma_pool_alloc(l1pool, GFP_KERNEL,
+ &sh_domain->l1.handle);
+ if (!sh_domain->l1.pgtable) {
+ kfree(sh_domain);
+ return -ENOMEM;
+ }
+ for (i = 0; i < L1_LEN; i++)
+ sh_domain->l2[i].pgtable = NULL;
+ memset(sh_domain->l1.pgtable, 0, L1_SIZE);
+ spin_lock_init(&sh_domain->map_lock);
+ atomic_set(&sh_domain->active, 0);
+ domain->priv = sh_domain;
+ return 0;
+}
+
+static void shmobile_iommu_domain_destroy(struct iommu_domain *domain)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ int i;
+
+ for (i = 0; i < L1_LEN; i++) {
+ if (sh_domain->l2[i].pgtable)
+ dma_pool_free(l2pool, sh_domain->l2[i].pgtable,
+ sh_domain->l2[i].handle);
+ }
+ dma_pool_free(l1pool, sh_domain->l1.pgtable, sh_domain->l1.handle);
+ kfree(sh_domain);
+ domain->priv = NULL;
+}
+
+static int shmobile_iommu_attach_device(struct iommu_domain *domain,
+ struct device *dev)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ struct shmobile_ipmmu *ipmmu = platform_bus_ipmmu;
+ int ret = -EBUSY;
+
+ spin_lock(&lock);
+ if (attached != sh_domain) {
+ if (attached)
+ goto err;
+ atomic_set(&sh_domain->active, 1);
+ ipmmu_tlb_set(ipmmu, sh_domain->l1.handle, L1_SIZE, 0);
+ wmb();
+ ipmmu_tlb_flush(ipmmu);
+ attached = sh_domain;
+ num_attached_devices = 0;
+ sh_domain->ipmmu = ipmmu;
+ }
+ num_attached_devices++;
+ ret = 0;
+err:
+ spin_unlock(&lock);
+ return ret;
+}
+
+static void shmobile_iommu_detach_device(struct iommu_domain *domain,
+ struct device *dev)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ struct shmobile_ipmmu *ipmmu = platform_bus_ipmmu;
+
+ spin_lock(&lock);
+ atomic_set(&sh_domain->active, 0);
+ num_attached_devices--;
+ if (!num_attached_devices) {
+ ipmmu_tlb_set(ipmmu, 0, 0, 0);
+ ipmmu_tlb_flush(ipmmu);
+ attached = NULL;
+ sh_domain->ipmmu = NULL;
+ }
+ spin_unlock(&lock);
+}
+
+static int
+l2alloc(struct shmobile_iommu_domain *sh_domain, unsigned int l1index)
+{
+ if (!sh_domain->l2[l1index].pgtable) {
+ sh_domain->l2[l1index].pgtable = dma_pool_alloc(l2pool,
+ GFP_KERNEL,
+ &sh_domain->l2[l1index].handle);
+ if (!sh_domain->l2[l1index].pgtable)
+ return -ENOMEM;
+ memset(sh_domain->l2[l1index].pgtable, 0, L2_SIZE);
+ }
+ sh_domain->l1.pgtable[l1index] = sh_domain->l2[l1index].handle | 0x1;
+ return 0;
+}
+
+static void
+l2realfree(struct shmobile_iommu_domain_pgtable *l2)
+{
+ if (l2->pgtable)
+ dma_pool_free(l2pool, l2->pgtable, l2->handle);
+}
+
+static int
+l2free(struct shmobile_iommu_domain *sh_domain, unsigned int l1index,
+ struct shmobile_iommu_domain_pgtable *l2)
+{
+ sh_domain->l1.pgtable[l1index] = 0;
+ if (sh_domain->l2[l1index].pgtable) {
+ *l2 = sh_domain->l2[l1index];
+ sh_domain->l2[l1index].pgtable = NULL;
+ }
+ return 0;
+}
+
+static int shmobile_iommu_map(struct iommu_domain *domain, unsigned long iova,
+ phys_addr_t paddr, size_t size, int prot)
+{
+ struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL };
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ unsigned int l1index, l2index, i;
+ int ret;
+
+ l1index = iova >> 20;
+ switch (size) {
+ case 0x1000:
+ l2index = (iova >> 12) & 0xff;
+ spin_lock(&sh_domain->map_lock);
+ ret = l2alloc(sh_domain, l1index);
+ if (!ret)
+ sh_domain->l2[l1index].pgtable[l2index] = paddr | 0xff2;
+ spin_unlock(&sh_domain->map_lock);
+ break;
+ case 0x10000:
+ l2index = (iova >> 12) & 0xf0;
+ spin_lock(&sh_domain->map_lock);
+ ret = l2alloc(sh_domain, l1index);
+ if (!ret) {
+ for (i = 0; i < 0x10; i++)
+ sh_domain->l2[l1index].pgtable[l2index + i] + paddr | 0xff1;
+ }
+ spin_unlock(&sh_domain->map_lock);
+ break;
+ case 0x100000:
+ spin_lock(&sh_domain->map_lock);
+ l2free(sh_domain, l1index, &l2);
+ sh_domain->l1.pgtable[l1index] = paddr | 0xc02;
+ spin_unlock(&sh_domain->map_lock);
+ ret = 0;
+ break;
+ default:
+ ret = -EINVAL;
+ }
+ if (!ret && atomic_read(&sh_domain->active)) {
+ wmb();
+ ipmmu_tlb_flush(sh_domain->ipmmu);
+ l2realfree(&l2);
+ }
+ return ret;
+}
+
+static size_t shmobile_iommu_unmap(struct iommu_domain *domain,
+ unsigned long iova, size_t size)
+{
+ struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL };
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ unsigned int l1index, l2index, i;
+ uint32_t l2entry = 0;
+ size_t ret = 0;
+
+ l1index = iova >> 20;
+ if (!(iova & 0xFFFFF) && size >= 0x100000) {
+ spin_lock(&sh_domain->map_lock);
+ l2free(sh_domain, l1index, &l2);
+ spin_unlock(&sh_domain->map_lock);
+ ret = 0x100000;
+ goto done;
+ }
+ l2index = (iova >> 12) & 0xff;
+ spin_lock(&sh_domain->map_lock);
+ if (sh_domain->l2[l1index].pgtable)
+ l2entry = sh_domain->l2[l1index].pgtable[l2index];
+ switch (l2entry & 3) {
+ case 1:
+ if (l2index & 0xf)
+ break;
+ for (i = 0; i < 0x10; i++)
+ sh_domain->l2[l1index].pgtable[l2index + i] = 0;
+ ret = 0x10000;
+ break;
+ case 2:
+ sh_domain->l2[l1index].pgtable[l2index] = 0;
+ ret = 0x1000;
+ break;
+ }
+ spin_unlock(&sh_domain->map_lock);
+done:
+ if (ret && atomic_read(&sh_domain->active)) {
+ wmb();
+ ipmmu_tlb_flush(sh_domain->ipmmu);
+ l2realfree(&l2);
+ }
+ return ret;
+}
+
+static phys_addr_t shmobile_iommu_iova_to_phys(struct iommu_domain *domain,
+ unsigned long iova)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ uint32_t l1entry = 0, l2entry = 0;
+ unsigned int l1index, l2index;
+
+ l1index = iova >> 20;
+ l2index = (iova >> 12) & 0xff;
+ spin_lock(&sh_domain->map_lock);
+ if (sh_domain->l2[l1index].pgtable)
+ l2entry = sh_domain->l2[l1index].pgtable[l2index];
+ else
+ l1entry = sh_domain->l1.pgtable[l1index];
+ spin_unlock(&sh_domain->map_lock);
+ switch (l2entry & 3) {
+ case 1:
+ return (l2entry & ~0xffff) | (iova & 0xffff);
+ case 2:
+ return (l2entry & ~0xfff) | (iova & 0xfff);
+ default:
+ if ((l1entry & 3) = 2)
+ return (l1entry & ~0xfffff) | (iova & 0xfffff);
+ return 0;
+ }
+}
+
+static int find_dev_name(struct shmobile_ipmmu *ipmmu, const char *dev_name)
+{
+ unsigned int i, n = ipmmu->num_dev_names;
+
+ for (i = 0; i < n; i++) {
+ if (strcmp(ipmmu->dev_names[i], dev_name) = 0)
+ return 1;
+ }
+ return 0;
+}
+
+static int shmobile_iommu_add_device(struct device *dev)
+{
+ struct shmobile_ipmmu *ipmmu = platform_bus_ipmmu;
+ struct dma_iommu_mapping *mapping;
+
+ if (!find_dev_name(ipmmu, dev_name(dev)))
+ return 0;
+ mapping = ipmmu->iommu_mapping;
+ if (!mapping) {
+ mapping = arm_iommu_create_mapping(&platform_bus_type, 0,
+ L1_LEN << 20, 0);
+ if (IS_ERR(mapping))
+ return PTR_ERR(mapping);
+ ipmmu->iommu_mapping = mapping;
+ }
+ if (arm_iommu_attach_device(dev, mapping))
+ pr_err("arm_iommu_attach_device failed\n");
+ return 0;
+}
+
+static struct iommu_ops shmobile_iommu_ops = {
+ .domain_init = shmobile_iommu_domain_init,
+ .domain_destroy = shmobile_iommu_domain_destroy,
+ .attach_dev = shmobile_iommu_attach_device,
+ .detach_dev = shmobile_iommu_detach_device,
+ .map = shmobile_iommu_map,
+ .unmap = shmobile_iommu_unmap,
+ .iova_to_phys = shmobile_iommu_iova_to_phys,
+ .add_device = shmobile_iommu_add_device,
+ .pgsize_bitmap = 0x111000,
+};
+
+int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu)
+{
+ dma_set_coherent_mask(ipmmu->dev, DMA_BIT_MASK(32));
+ l1pool = dma_pool_create("shmobile-iommu-pgtable1", ipmmu->dev,
+ L1_SIZE, L1_ALIGN, 0);
+ if (!l1pool)
+ goto nomem_pool1;
+ l2pool = dma_pool_create("shmobile-iommu-pgtable2", ipmmu->dev,
+ L2_SIZE, L2_ALIGN, 0);
+ if (!l2pool)
+ goto nomem_pool2;
+ spin_lock_init(&lock);
+ attached = NULL;
+ platform_bus_ipmmu = ipmmu;
+ bus_set_iommu(&platform_bus_type, &shmobile_iommu_ops);
+ return 0;
+nomem_pool2:
+ dma_pool_destroy(l1pool);
+nomem_pool1:
+ return -ENOMEM;
+}
diff --git a/drivers/iommu/shmobile-ipmmu.c b/drivers/iommu/shmobile-ipmmu.c
new file mode 100644
index 0000000..8321f89
--- /dev/null
+++ b/drivers/iommu/shmobile-ipmmu.c
@@ -0,0 +1,136 @@
+/*
+ * IPMMU/IPMMUI
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/platform_data/sh_ipmmu.h>
+#include "shmobile-ipmmu.h"
+
+#define IMCTR1 0x000
+#define IMCTR2 0x004
+#define IMASID 0x010
+#define IMTTBR 0x014
+#define IMTTBCR 0x018
+
+#define IMCTR1_TLBEN (1 << 0)
+#define IMCTR1_FLUSH (1 << 1)
+
+static void ipmmu_reg_write(struct shmobile_ipmmu *ipmmu, unsigned long reg_off,
+ unsigned long data)
+{
+ iowrite32(data, ipmmu->ipmmu_base + reg_off);
+}
+
+void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu)
+{
+ if (!ipmmu)
+ return;
+
+ mutex_lock(&ipmmu->flush_lock);
+ if (ipmmu->tlb_enabled)
+ ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH | IMCTR1_TLBEN);
+ else
+ ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH);
+ mutex_unlock(&ipmmu->flush_lock);
+}
+
+void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size,
+ int asid)
+{
+ if (!ipmmu)
+ return;
+
+ mutex_lock(&ipmmu->flush_lock);
+ switch (size) {
+ default:
+ ipmmu->tlb_enabled = 0;
+ break;
+ case 0x2000:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 1);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x1000:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 2);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x800:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 3);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x400:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 4);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x200:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 5);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x100:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 6);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x80:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 7);
+ ipmmu->tlb_enabled = 1;
+ break;
+ }
+ ipmmu_reg_write(ipmmu, IMTTBR, phys);
+ ipmmu_reg_write(ipmmu, IMASID, asid);
+ mutex_unlock(&ipmmu->flush_lock);
+}
+
+static int ipmmu_probe(struct platform_device *pdev)
+{
+ struct shmobile_ipmmu *ipmmu;
+ struct resource *res;
+ struct shmobile_ipmmu_platform_data *pdata = pdev->dev.platform_data;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(&pdev->dev, "cannot get platform resources\n");
+ return -ENOENT;
+ }
+ ipmmu = devm_kzalloc(&pdev->dev, sizeof(*ipmmu), GFP_KERNEL);
+ if (!ipmmu) {
+ dev_err(&pdev->dev, "cannot allocate device data\n");
+ return -ENOMEM;
+ }
+ mutex_init(&ipmmu->flush_lock);
+ ipmmu->dev = &pdev->dev;
+ ipmmu->ipmmu_base = devm_ioremap_nocache(&pdev->dev, res->start,
+ resource_size(res));
+ if (!ipmmu->ipmmu_base) {
+ dev_err(&pdev->dev, "ioremap_nocache failed\n");
+ return -ENOMEM;
+ }
+ ipmmu->dev_names = pdata->dev_names;
+ ipmmu->num_dev_names = pdata->num_dev_names;
+ platform_set_drvdata(pdev, ipmmu);
+ ipmmu_reg_write(ipmmu, IMCTR1, 0x0); /* disable TLB */
+ ipmmu_reg_write(ipmmu, IMCTR2, 0x0); /* disable PMB */
+ ipmmu_iommu_init(ipmmu);
+ return 0;
+}
+
+static struct platform_driver ipmmu_driver = {
+ .probe = ipmmu_probe,
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "ipmmu",
+ },
+};
+
+static int __init ipmmu_init(void)
+{
+ return platform_driver_register(&ipmmu_driver);
+}
+subsys_initcall(ipmmu_init);
diff --git a/drivers/iommu/shmobile-ipmmu.h b/drivers/iommu/shmobile-ipmmu.h
new file mode 100644
index 0000000..6270e7c
--- /dev/null
+++ b/drivers/iommu/shmobile-ipmmu.h
@@ -0,0 +1,37 @@
+/* shmobile-ipmmu.h
+ *
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#ifndef __SHMOBILE_IPMMU_H__
+#define __SHMOBILE_IPMMU_H__
+
+struct dma_iommu_mapping;
+
+struct shmobile_ipmmu {
+ struct device *dev;
+ void __iomem *ipmmu_base;
+ int tlb_enabled;
+ struct mutex flush_lock;
+ struct dma_iommu_mapping *iommu_mapping;
+ const char * const *dev_names;
+ unsigned int num_dev_names;
+};
+
+#ifdef CONFIG_SHMOBILE_IPMMU_TLB
+void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu);
+void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size,
+ int asid);
+int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu);
+#else
+static int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu)
+{
+ return -EINVAL;
+}
+#endif
+
+#endif /* __SHMOBILE_IPMMU_H__ */
diff --git a/include/linux/platform_data/sh_ipmmu.h b/include/linux/platform_data/sh_ipmmu.h
new file mode 100644
index 0000000..39f7405
--- /dev/null
+++ b/include/linux/platform_data/sh_ipmmu.h
@@ -0,0 +1,18 @@
+/* sh_ipmmu.h
+ *
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#ifndef __SH_IPMMU_H__
+#define __SH_IPMMU_H__
+
+struct shmobile_ipmmu_platform_data {
+ const char * const *dev_names;
+ unsigned int num_dev_names;
+};
+
+#endif /* __SH_IPMMU_H__ */
--
1.8.0
^ permalink raw reply related
* [PATCH v5 1/4] iommu/shmobile: Add iommu driver for Renesas IPMMU modules
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: Paul Mundt, Magnus Damm, Russell King, Simon Horman,
Laurent Pinchart
Cc: linux-sh, iommu, linux-arm-kernel, linux-kernel, Marek Szyprowski,
Katsuya MATSUBARA, Damian Hobson-Garcia, Hideki EIRAKU
In-Reply-To: <1356434355-3279-1-git-send-email-hdk@igel.co.jp>
This is the Renesas IPMMU driver and IOMMU API implementation.
The IPMMU module supports the MMU function and the PMB function. The
MMU function provides address translation by pagetable compatible with
ARMv6. The PMB function provides address translation including
tile-linear translation. This patch implements the MMU function.
The iommu driver does not register a platform driver directly because:
- the register space of the MMU function and the PMB function
have a common register (used for settings flush), so they should ideally
have a way to appropriately share this register.
- the MMU function uses the IOMMU API while the PMB function does not.
- the two functions may be used independently.
Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp>
---
drivers/iommu/Kconfig | 74 +++++++
drivers/iommu/Makefile | 2 +
drivers/iommu/shmobile-iommu.c | 341 +++++++++++++++++++++++++++++++++
drivers/iommu/shmobile-ipmmu.c | 136 +++++++++++++
drivers/iommu/shmobile-ipmmu.h | 37 ++++
include/linux/platform_data/sh_ipmmu.h | 18 ++
6 files changed, 608 insertions(+)
create mode 100644 drivers/iommu/shmobile-iommu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.h
create mode 100644 include/linux/platform_data/sh_ipmmu.h
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index e39f9db..d364494 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -187,4 +187,78 @@ config EXYNOS_IOMMU_DEBUG
Say N unless you need kernel log message for IOMMU debugging
+config SHMOBILE_IPMMU
+ bool
+
+config SHMOBILE_IPMMU_TLB
+ bool
+
+config SHMOBILE_IOMMU
+ bool "IOMMU for Renesas IPMMU/IPMMUI"
+ default n
+ depends on (ARM && ARCH_SHMOBILE)
+ select IOMMU_API
+ select ARM_DMA_USE_IOMMU
+ select SHMOBILE_IPMMU
+ select SHMOBILE_IPMMU_TLB
+ help
+ Support for Renesas IPMMU/IPMMUI. This option enables
+ remapping of DMA memory accesses from all of the IP blocks
+ on the ICB.
+
+ Warning: Drivers (including userspace drivers of UIO
+ devices) of the IP blocks on the ICB *must* use addresses
+ allocated from the IPMMU (iova) for DMA with this option
+ enabled.
+
+ If unsure, say N.
+
+choice
+ prompt "IPMMU/IPMMUI address space size"
+ default SHMOBILE_IOMMU_ADDRSIZE_2048MB
+ depends on SHMOBILE_IOMMU
+ help
+ This option sets IPMMU/IPMMUI address space size by
+ adjusting the 1st level page table size. The page table size
+ is calculated as follows:
+
+ page table size = number of page table entries * 4 bytes
+ number of page table entries = address space size / 1 MiB
+
+ For example, when the address space size is 2048 MiB, the
+ 1st level page table size is 8192 bytes.
+
+ config SHMOBILE_IOMMU_ADDRSIZE_2048MB
+ bool "2 GiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_1024MB
+ bool "1 GiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_512MB
+ bool "512 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_256MB
+ bool "256 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_128MB
+ bool "128 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_64MB
+ bool "64 MiB"
+
+ config SHMOBILE_IOMMU_ADDRSIZE_32MB
+ bool "32 MiB"
+
+endchoice
+
+config SHMOBILE_IOMMU_L1SIZE
+ int
+ default 8192 if SHMOBILE_IOMMU_ADDRSIZE_2048MB
+ default 4096 if SHMOBILE_IOMMU_ADDRSIZE_1024MB
+ default 2048 if SHMOBILE_IOMMU_ADDRSIZE_512MB
+ default 1024 if SHMOBILE_IOMMU_ADDRSIZE_256MB
+ default 512 if SHMOBILE_IOMMU_ADDRSIZE_128MB
+ default 256 if SHMOBILE_IOMMU_ADDRSIZE_64MB
+ default 128 if SHMOBILE_IOMMU_ADDRSIZE_32MB
+
endif # IOMMU_SUPPORT
diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
index f66b816..ef0e520 100644
--- a/drivers/iommu/Makefile
+++ b/drivers/iommu/Makefile
@@ -13,3 +13,5 @@ obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o
obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o
obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o
obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o
+obj-$(CONFIG_SHMOBILE_IOMMU) += shmobile-iommu.o
+obj-$(CONFIG_SHMOBILE_IPMMU) += shmobile-ipmmu.o
diff --git a/drivers/iommu/shmobile-iommu.c b/drivers/iommu/shmobile-iommu.c
new file mode 100644
index 0000000..360a06f
--- /dev/null
+++ b/drivers/iommu/shmobile-iommu.c
@@ -0,0 +1,341 @@
+/*
+ * IOMMU for IPMMU/IPMMUI
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/dma-mapping.h>
+#include <linux/dmapool.h>
+#include <linux/io.h>
+#include <linux/iommu.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <asm/dma-iommu.h>
+#include "shmobile-ipmmu.h"
+
+#define L1_SIZE CONFIG_SHMOBILE_IOMMU_L1SIZE
+#define L1_LEN (L1_SIZE / 4)
+#define L1_ALIGN L1_SIZE
+#define L2_SIZE 0x400
+#define L2_LEN (L2_SIZE / 4)
+#define L2_ALIGN L2_SIZE
+
+struct shmobile_iommu_domain_pgtable {
+ uint32_t *pgtable;
+ dma_addr_t handle;
+};
+
+struct shmobile_iommu_domain {
+ struct shmobile_ipmmu *ipmmu;
+ struct shmobile_iommu_domain_pgtable l1, l2[L1_LEN];
+ spinlock_t map_lock;
+ atomic_t active;
+};
+
+static struct shmobile_ipmmu *platform_bus_ipmmu;
+static struct dma_pool *l1pool, *l2pool;
+static spinlock_t lock;
+static struct shmobile_iommu_domain *attached;
+static int num_attached_devices;
+
+static int shmobile_iommu_domain_init(struct iommu_domain *domain)
+{
+ struct shmobile_iommu_domain *sh_domain;
+ int i;
+
+ sh_domain = kmalloc(sizeof(*sh_domain), GFP_KERNEL);
+ if (!sh_domain)
+ return -ENOMEM;
+ sh_domain->l1.pgtable = dma_pool_alloc(l1pool, GFP_KERNEL,
+ &sh_domain->l1.handle);
+ if (!sh_domain->l1.pgtable) {
+ kfree(sh_domain);
+ return -ENOMEM;
+ }
+ for (i = 0; i < L1_LEN; i++)
+ sh_domain->l2[i].pgtable = NULL;
+ memset(sh_domain->l1.pgtable, 0, L1_SIZE);
+ spin_lock_init(&sh_domain->map_lock);
+ atomic_set(&sh_domain->active, 0);
+ domain->priv = sh_domain;
+ return 0;
+}
+
+static void shmobile_iommu_domain_destroy(struct iommu_domain *domain)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ int i;
+
+ for (i = 0; i < L1_LEN; i++) {
+ if (sh_domain->l2[i].pgtable)
+ dma_pool_free(l2pool, sh_domain->l2[i].pgtable,
+ sh_domain->l2[i].handle);
+ }
+ dma_pool_free(l1pool, sh_domain->l1.pgtable, sh_domain->l1.handle);
+ kfree(sh_domain);
+ domain->priv = NULL;
+}
+
+static int shmobile_iommu_attach_device(struct iommu_domain *domain,
+ struct device *dev)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ struct shmobile_ipmmu *ipmmu = platform_bus_ipmmu;
+ int ret = -EBUSY;
+
+ spin_lock(&lock);
+ if (attached != sh_domain) {
+ if (attached)
+ goto err;
+ atomic_set(&sh_domain->active, 1);
+ ipmmu_tlb_set(ipmmu, sh_domain->l1.handle, L1_SIZE, 0);
+ wmb();
+ ipmmu_tlb_flush(ipmmu);
+ attached = sh_domain;
+ num_attached_devices = 0;
+ sh_domain->ipmmu = ipmmu;
+ }
+ num_attached_devices++;
+ ret = 0;
+err:
+ spin_unlock(&lock);
+ return ret;
+}
+
+static void shmobile_iommu_detach_device(struct iommu_domain *domain,
+ struct device *dev)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ struct shmobile_ipmmu *ipmmu = platform_bus_ipmmu;
+
+ spin_lock(&lock);
+ atomic_set(&sh_domain->active, 0);
+ num_attached_devices--;
+ if (!num_attached_devices) {
+ ipmmu_tlb_set(ipmmu, 0, 0, 0);
+ ipmmu_tlb_flush(ipmmu);
+ attached = NULL;
+ sh_domain->ipmmu = NULL;
+ }
+ spin_unlock(&lock);
+}
+
+static int
+l2alloc(struct shmobile_iommu_domain *sh_domain, unsigned int l1index)
+{
+ if (!sh_domain->l2[l1index].pgtable) {
+ sh_domain->l2[l1index].pgtable = dma_pool_alloc(l2pool,
+ GFP_KERNEL,
+ &sh_domain->l2[l1index].handle);
+ if (!sh_domain->l2[l1index].pgtable)
+ return -ENOMEM;
+ memset(sh_domain->l2[l1index].pgtable, 0, L2_SIZE);
+ }
+ sh_domain->l1.pgtable[l1index] = sh_domain->l2[l1index].handle | 0x1;
+ return 0;
+}
+
+static void
+l2realfree(struct shmobile_iommu_domain_pgtable *l2)
+{
+ if (l2->pgtable)
+ dma_pool_free(l2pool, l2->pgtable, l2->handle);
+}
+
+static int
+l2free(struct shmobile_iommu_domain *sh_domain, unsigned int l1index,
+ struct shmobile_iommu_domain_pgtable *l2)
+{
+ sh_domain->l1.pgtable[l1index] = 0;
+ if (sh_domain->l2[l1index].pgtable) {
+ *l2 = sh_domain->l2[l1index];
+ sh_domain->l2[l1index].pgtable = NULL;
+ }
+ return 0;
+}
+
+static int shmobile_iommu_map(struct iommu_domain *domain, unsigned long iova,
+ phys_addr_t paddr, size_t size, int prot)
+{
+ struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL };
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ unsigned int l1index, l2index, i;
+ int ret;
+
+ l1index = iova >> 20;
+ switch (size) {
+ case 0x1000:
+ l2index = (iova >> 12) & 0xff;
+ spin_lock(&sh_domain->map_lock);
+ ret = l2alloc(sh_domain, l1index);
+ if (!ret)
+ sh_domain->l2[l1index].pgtable[l2index] = paddr | 0xff2;
+ spin_unlock(&sh_domain->map_lock);
+ break;
+ case 0x10000:
+ l2index = (iova >> 12) & 0xf0;
+ spin_lock(&sh_domain->map_lock);
+ ret = l2alloc(sh_domain, l1index);
+ if (!ret) {
+ for (i = 0; i < 0x10; i++)
+ sh_domain->l2[l1index].pgtable[l2index + i] =
+ paddr | 0xff1;
+ }
+ spin_unlock(&sh_domain->map_lock);
+ break;
+ case 0x100000:
+ spin_lock(&sh_domain->map_lock);
+ l2free(sh_domain, l1index, &l2);
+ sh_domain->l1.pgtable[l1index] = paddr | 0xc02;
+ spin_unlock(&sh_domain->map_lock);
+ ret = 0;
+ break;
+ default:
+ ret = -EINVAL;
+ }
+ if (!ret && atomic_read(&sh_domain->active)) {
+ wmb();
+ ipmmu_tlb_flush(sh_domain->ipmmu);
+ l2realfree(&l2);
+ }
+ return ret;
+}
+
+static size_t shmobile_iommu_unmap(struct iommu_domain *domain,
+ unsigned long iova, size_t size)
+{
+ struct shmobile_iommu_domain_pgtable l2 = { .pgtable = NULL };
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ unsigned int l1index, l2index, i;
+ uint32_t l2entry = 0;
+ size_t ret = 0;
+
+ l1index = iova >> 20;
+ if (!(iova & 0xFFFFF) && size >= 0x100000) {
+ spin_lock(&sh_domain->map_lock);
+ l2free(sh_domain, l1index, &l2);
+ spin_unlock(&sh_domain->map_lock);
+ ret = 0x100000;
+ goto done;
+ }
+ l2index = (iova >> 12) & 0xff;
+ spin_lock(&sh_domain->map_lock);
+ if (sh_domain->l2[l1index].pgtable)
+ l2entry = sh_domain->l2[l1index].pgtable[l2index];
+ switch (l2entry & 3) {
+ case 1:
+ if (l2index & 0xf)
+ break;
+ for (i = 0; i < 0x10; i++)
+ sh_domain->l2[l1index].pgtable[l2index + i] = 0;
+ ret = 0x10000;
+ break;
+ case 2:
+ sh_domain->l2[l1index].pgtable[l2index] = 0;
+ ret = 0x1000;
+ break;
+ }
+ spin_unlock(&sh_domain->map_lock);
+done:
+ if (ret && atomic_read(&sh_domain->active)) {
+ wmb();
+ ipmmu_tlb_flush(sh_domain->ipmmu);
+ l2realfree(&l2);
+ }
+ return ret;
+}
+
+static phys_addr_t shmobile_iommu_iova_to_phys(struct iommu_domain *domain,
+ unsigned long iova)
+{
+ struct shmobile_iommu_domain *sh_domain = domain->priv;
+ uint32_t l1entry = 0, l2entry = 0;
+ unsigned int l1index, l2index;
+
+ l1index = iova >> 20;
+ l2index = (iova >> 12) & 0xff;
+ spin_lock(&sh_domain->map_lock);
+ if (sh_domain->l2[l1index].pgtable)
+ l2entry = sh_domain->l2[l1index].pgtable[l2index];
+ else
+ l1entry = sh_domain->l1.pgtable[l1index];
+ spin_unlock(&sh_domain->map_lock);
+ switch (l2entry & 3) {
+ case 1:
+ return (l2entry & ~0xffff) | (iova & 0xffff);
+ case 2:
+ return (l2entry & ~0xfff) | (iova & 0xfff);
+ default:
+ if ((l1entry & 3) == 2)
+ return (l1entry & ~0xfffff) | (iova & 0xfffff);
+ return 0;
+ }
+}
+
+static int find_dev_name(struct shmobile_ipmmu *ipmmu, const char *dev_name)
+{
+ unsigned int i, n = ipmmu->num_dev_names;
+
+ for (i = 0; i < n; i++) {
+ if (strcmp(ipmmu->dev_names[i], dev_name) == 0)
+ return 1;
+ }
+ return 0;
+}
+
+static int shmobile_iommu_add_device(struct device *dev)
+{
+ struct shmobile_ipmmu *ipmmu = platform_bus_ipmmu;
+ struct dma_iommu_mapping *mapping;
+
+ if (!find_dev_name(ipmmu, dev_name(dev)))
+ return 0;
+ mapping = ipmmu->iommu_mapping;
+ if (!mapping) {
+ mapping = arm_iommu_create_mapping(&platform_bus_type, 0,
+ L1_LEN << 20, 0);
+ if (IS_ERR(mapping))
+ return PTR_ERR(mapping);
+ ipmmu->iommu_mapping = mapping;
+ }
+ if (arm_iommu_attach_device(dev, mapping))
+ pr_err("arm_iommu_attach_device failed\n");
+ return 0;
+}
+
+static struct iommu_ops shmobile_iommu_ops = {
+ .domain_init = shmobile_iommu_domain_init,
+ .domain_destroy = shmobile_iommu_domain_destroy,
+ .attach_dev = shmobile_iommu_attach_device,
+ .detach_dev = shmobile_iommu_detach_device,
+ .map = shmobile_iommu_map,
+ .unmap = shmobile_iommu_unmap,
+ .iova_to_phys = shmobile_iommu_iova_to_phys,
+ .add_device = shmobile_iommu_add_device,
+ .pgsize_bitmap = 0x111000,
+};
+
+int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu)
+{
+ dma_set_coherent_mask(ipmmu->dev, DMA_BIT_MASK(32));
+ l1pool = dma_pool_create("shmobile-iommu-pgtable1", ipmmu->dev,
+ L1_SIZE, L1_ALIGN, 0);
+ if (!l1pool)
+ goto nomem_pool1;
+ l2pool = dma_pool_create("shmobile-iommu-pgtable2", ipmmu->dev,
+ L2_SIZE, L2_ALIGN, 0);
+ if (!l2pool)
+ goto nomem_pool2;
+ spin_lock_init(&lock);
+ attached = NULL;
+ platform_bus_ipmmu = ipmmu;
+ bus_set_iommu(&platform_bus_type, &shmobile_iommu_ops);
+ return 0;
+nomem_pool2:
+ dma_pool_destroy(l1pool);
+nomem_pool1:
+ return -ENOMEM;
+}
diff --git a/drivers/iommu/shmobile-ipmmu.c b/drivers/iommu/shmobile-ipmmu.c
new file mode 100644
index 0000000..8321f89
--- /dev/null
+++ b/drivers/iommu/shmobile-ipmmu.c
@@ -0,0 +1,136 @@
+/*
+ * IPMMU/IPMMUI
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/platform_data/sh_ipmmu.h>
+#include "shmobile-ipmmu.h"
+
+#define IMCTR1 0x000
+#define IMCTR2 0x004
+#define IMASID 0x010
+#define IMTTBR 0x014
+#define IMTTBCR 0x018
+
+#define IMCTR1_TLBEN (1 << 0)
+#define IMCTR1_FLUSH (1 << 1)
+
+static void ipmmu_reg_write(struct shmobile_ipmmu *ipmmu, unsigned long reg_off,
+ unsigned long data)
+{
+ iowrite32(data, ipmmu->ipmmu_base + reg_off);
+}
+
+void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu)
+{
+ if (!ipmmu)
+ return;
+
+ mutex_lock(&ipmmu->flush_lock);
+ if (ipmmu->tlb_enabled)
+ ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH | IMCTR1_TLBEN);
+ else
+ ipmmu_reg_write(ipmmu, IMCTR1, IMCTR1_FLUSH);
+ mutex_unlock(&ipmmu->flush_lock);
+}
+
+void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size,
+ int asid)
+{
+ if (!ipmmu)
+ return;
+
+ mutex_lock(&ipmmu->flush_lock);
+ switch (size) {
+ default:
+ ipmmu->tlb_enabled = 0;
+ break;
+ case 0x2000:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 1);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x1000:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 2);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x800:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 3);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x400:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 4);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x200:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 5);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x100:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 6);
+ ipmmu->tlb_enabled = 1;
+ break;
+ case 0x80:
+ ipmmu_reg_write(ipmmu, IMTTBCR, 7);
+ ipmmu->tlb_enabled = 1;
+ break;
+ }
+ ipmmu_reg_write(ipmmu, IMTTBR, phys);
+ ipmmu_reg_write(ipmmu, IMASID, asid);
+ mutex_unlock(&ipmmu->flush_lock);
+}
+
+static int ipmmu_probe(struct platform_device *pdev)
+{
+ struct shmobile_ipmmu *ipmmu;
+ struct resource *res;
+ struct shmobile_ipmmu_platform_data *pdata = pdev->dev.platform_data;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(&pdev->dev, "cannot get platform resources\n");
+ return -ENOENT;
+ }
+ ipmmu = devm_kzalloc(&pdev->dev, sizeof(*ipmmu), GFP_KERNEL);
+ if (!ipmmu) {
+ dev_err(&pdev->dev, "cannot allocate device data\n");
+ return -ENOMEM;
+ }
+ mutex_init(&ipmmu->flush_lock);
+ ipmmu->dev = &pdev->dev;
+ ipmmu->ipmmu_base = devm_ioremap_nocache(&pdev->dev, res->start,
+ resource_size(res));
+ if (!ipmmu->ipmmu_base) {
+ dev_err(&pdev->dev, "ioremap_nocache failed\n");
+ return -ENOMEM;
+ }
+ ipmmu->dev_names = pdata->dev_names;
+ ipmmu->num_dev_names = pdata->num_dev_names;
+ platform_set_drvdata(pdev, ipmmu);
+ ipmmu_reg_write(ipmmu, IMCTR1, 0x0); /* disable TLB */
+ ipmmu_reg_write(ipmmu, IMCTR2, 0x0); /* disable PMB */
+ ipmmu_iommu_init(ipmmu);
+ return 0;
+}
+
+static struct platform_driver ipmmu_driver = {
+ .probe = ipmmu_probe,
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "ipmmu",
+ },
+};
+
+static int __init ipmmu_init(void)
+{
+ return platform_driver_register(&ipmmu_driver);
+}
+subsys_initcall(ipmmu_init);
diff --git a/drivers/iommu/shmobile-ipmmu.h b/drivers/iommu/shmobile-ipmmu.h
new file mode 100644
index 0000000..6270e7c
--- /dev/null
+++ b/drivers/iommu/shmobile-ipmmu.h
@@ -0,0 +1,37 @@
+/* shmobile-ipmmu.h
+ *
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#ifndef __SHMOBILE_IPMMU_H__
+#define __SHMOBILE_IPMMU_H__
+
+struct dma_iommu_mapping;
+
+struct shmobile_ipmmu {
+ struct device *dev;
+ void __iomem *ipmmu_base;
+ int tlb_enabled;
+ struct mutex flush_lock;
+ struct dma_iommu_mapping *iommu_mapping;
+ const char * const *dev_names;
+ unsigned int num_dev_names;
+};
+
+#ifdef CONFIG_SHMOBILE_IPMMU_TLB
+void ipmmu_tlb_flush(struct shmobile_ipmmu *ipmmu);
+void ipmmu_tlb_set(struct shmobile_ipmmu *ipmmu, unsigned long phys, int size,
+ int asid);
+int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu);
+#else
+static int ipmmu_iommu_init(struct shmobile_ipmmu *ipmmu)
+{
+ return -EINVAL;
+}
+#endif
+
+#endif /* __SHMOBILE_IPMMU_H__ */
diff --git a/include/linux/platform_data/sh_ipmmu.h b/include/linux/platform_data/sh_ipmmu.h
new file mode 100644
index 0000000..39f7405
--- /dev/null
+++ b/include/linux/platform_data/sh_ipmmu.h
@@ -0,0 +1,18 @@
+/* sh_ipmmu.h
+ *
+ * Copyright (C) 2012 Hideki EIRAKU
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#ifndef __SH_IPMMU_H__
+#define __SH_IPMMU_H__
+
+struct shmobile_ipmmu_platform_data {
+ const char * const *dev_names;
+ unsigned int num_dev_names;
+};
+
+#endif /* __SH_IPMMU_H__ */
--
1.8.0
^ permalink raw reply related
* [PATCH v5 0/4] Renesas IPMMU driver for sh7372, sh73a0 and r8a7740
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
This is the Renesas IPMMU driver, IOMMU API implementation and IPMMU
device support for sh7372 (AP4EVB and Mackerel), sh73a0 and r8a7740.
The IPMMU module supports the MMU function and the PMB function. The
MMU function provides address translation by pagetable compatible with
ARMv6. The PMB function provides address translation including
tile-linear translation. This is implementation of the MMU function.
Note: The IPMMU module translates DMA memory address from all of the
IP blocks on the ICB. The IOMMU API has iommu_attach_device() which
attaches one device to one domain, but the IPMMU module cannot attach
only one device. The IPMMU module only can attach all devices to one
domain.
Tested on:
- armadillo800eva
- kzma9
- mackerel (I could not make it boot the v3.8-rc1 with Device Tree, so
I tested a kernel without Device Tree support, reverting
3b7b70552afe351a8bd8fff1eb2d60aab2206576 and
0ce53cdc5c7e28f378e480363a0b0c2ed7e7eaf9)
How to test:
1. Boot a kernel built with CONFIG_SHMOBILE_IOMMU=y.
2. Check whether a display on the board shows console normally.
3. Check whether the IMCTR1 register is 1 which means the MMU function enabled.
To read the IMCTR1 register:
# peekpoke 0xfe951000
4. Change the IMCTR1 to 0 to disable the MMU function.
To change the IMCTR1 register to 0:
# peekpoke 0xfe951000 0
5. Check whether the display shows broken data.
6. Change the IMCTR1 to 1 to enable the MMU function.
To change the IMCTR1 register to 1:
# peekpoke 0xfe951000 1
7. Check whether a display on the board shows console normally.
8. Capture and check the framebuffer contents via memory mapped by mmap().
To capture the framebuffer contents and save the image to a file "filename":
# fbcat /dev/fb0 > filename
To look at the contents saved by fbcat on a PC:
$ display filename
- fbcat can be downloaded from https://code.google.com/p/fbcat/.
- display is one of the ImageMagick tools.
- peekpoke is:
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <err.h>
int main(int argc,char**argv){
uint32_t*p,addr;
int fd=open("/dev/mem",O_RDWR);
if(fd<0)err(1,"open");
addr=strtoul(argv[1],NULL,0);
p=mmap(NULL,0x1000,PROT_READ|PROT_WRITE,MAP_SHARED,fd,addr&~0xfff);
if(p==MAP_FAILED)err(1,"mmap");
if(argc<=2)printf("0x%08x\n",p[addr/4&0x3ff]);
else printf("wrote 0x%08x\n",p[addr/4&0x3ff]=strtoul(argv[2],NULL,0));
}
Changelog:
v5:
- Rebased on 3.8-rc1.
- Add sh73a0 and r8a7740 support.
- CONFIG_SHMOBILE_IOMMU is now selectable only for arm shmobile
architecture.
- Fix "defined but not used" warnings when CONFIG_SHMOBILE_IOMMU is
not set.
- Add help text of CONFIG_SHMOBILE_IOMMU.
- Apply some of Laurent Pinchart's rework patches: Move the driver to
drivers/iommu/.
- Use platform_data to specify attaching devices instead of
ipmmu_add_device() API.
v4:
- Rebased on 3.7-rc1.
- Use address space size instead of page table size in config.
- Use Kconfig default value instead of #ifdef-#define-#endif.
v3:
- Rebased on 3.6-rc5.
- Simplify configs. SHMOBILE_IPMMU is now selected by setting
SHMOBILE_IOMMU.
- Remove weak symbols.
- Use drvdata to store private driver data.
- Make a function for writing to a register of IPMMU.
- Add a lock to accessing the tlb_enabled member.
- Make unmap work correctly with size larger than map size.
- Free L2 page table when 1MiB page is mapped or unmapped.
- Add VEU devices as IP blocks on the ICB.
v2:
- Rebased on v3.6-rc1.
- Make variable names clear.
- Page table size can now be selected by config.
Hideki EIRAKU (4):
iommu/shmobile: Add iommu driver for Renesas IPMMU modules
ARM: mach-shmobile: sh7372: Add IPMMU device
ARM: mach-shmobile: sh73a0: Add IPMMU device
ARM: mach-shmobile: r8a7740: Add IPMMU device
arch/arm/mach-shmobile/setup-r8a7740.c | 33 ++++
arch/arm/mach-shmobile/setup-sh7372.c | 39 ++++
arch/arm/mach-shmobile/setup-sh73a0.c | 31 +++
drivers/iommu/Kconfig | 74 +++++++
drivers/iommu/Makefile | 2 +
drivers/iommu/shmobile-iommu.c | 341 +++++++++++++++++++++++++++++++++
drivers/iommu/shmobile-ipmmu.c | 136 +++++++++++++
drivers/iommu/shmobile-ipmmu.h | 37 ++++
include/linux/platform_data/sh_ipmmu.h | 18 ++
9 files changed, 711 insertions(+)
create mode 100644 drivers/iommu/shmobile-iommu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.h
create mode 100644 include/linux/platform_data/sh_ipmmu.h
--
1.8.0
^ permalink raw reply
* [PATCH v5 0/4] Renesas IPMMU driver for sh7372, sh73a0 and r8a7740
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: linux-arm-kernel
This is the Renesas IPMMU driver, IOMMU API implementation and IPMMU
device support for sh7372 (AP4EVB and Mackerel), sh73a0 and r8a7740.
The IPMMU module supports the MMU function and the PMB function. The
MMU function provides address translation by pagetable compatible with
ARMv6. The PMB function provides address translation including
tile-linear translation. This is implementation of the MMU function.
Note: The IPMMU module translates DMA memory address from all of the
IP blocks on the ICB. The IOMMU API has iommu_attach_device() which
attaches one device to one domain, but the IPMMU module cannot attach
only one device. The IPMMU module only can attach all devices to one
domain.
Tested on:
- armadillo800eva
- kzma9
- mackerel (I could not make it boot the v3.8-rc1 with Device Tree, so
I tested a kernel without Device Tree support, reverting
3b7b70552afe351a8bd8fff1eb2d60aab2206576 and
0ce53cdc5c7e28f378e480363a0b0c2ed7e7eaf9)
How to test:
1. Boot a kernel built with CONFIG_SHMOBILE_IOMMU=y.
2. Check whether a display on the board shows console normally.
3. Check whether the IMCTR1 register is 1 which means the MMU function enabled.
To read the IMCTR1 register:
# peekpoke 0xfe951000
4. Change the IMCTR1 to 0 to disable the MMU function.
To change the IMCTR1 register to 0:
# peekpoke 0xfe951000 0
5. Check whether the display shows broken data.
6. Change the IMCTR1 to 1 to enable the MMU function.
To change the IMCTR1 register to 1:
# peekpoke 0xfe951000 1
7. Check whether a display on the board shows console normally.
8. Capture and check the framebuffer contents via memory mapped by mmap().
To capture the framebuffer contents and save the image to a file "filename":
# fbcat /dev/fb0 > filename
To look at the contents saved by fbcat on a PC:
$ display filename
- fbcat can be downloaded from https://code.google.com/p/fbcat/.
- display is one of the ImageMagick tools.
- peekpoke is:
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <err.h>
int main(int argc,char**argv){
uint32_t*p,addr;
int fd=open("/dev/mem",O_RDWR);
if(fd<0)err(1,"open");
addr=strtoul(argv[1],NULL,0);
p=mmap(NULL,0x1000,PROT_READ|PROT_WRITE,MAP_SHARED,fd,addr&~0xfff);
if(p=MAP_FAILED)err(1,"mmap");
if(argc<=2)printf("0x%08x\n",p[addr/4&0x3ff]);
else printf("wrote 0x%08x\n",p[addr/4&0x3ff]=strtoul(argv[2],NULL,0));
}
Changelog:
v5:
- Rebased on 3.8-rc1.
- Add sh73a0 and r8a7740 support.
- CONFIG_SHMOBILE_IOMMU is now selectable only for arm shmobile
architecture.
- Fix "defined but not used" warnings when CONFIG_SHMOBILE_IOMMU is
not set.
- Add help text of CONFIG_SHMOBILE_IOMMU.
- Apply some of Laurent Pinchart's rework patches: Move the driver to
drivers/iommu/.
- Use platform_data to specify attaching devices instead of
ipmmu_add_device() API.
v4:
- Rebased on 3.7-rc1.
- Use address space size instead of page table size in config.
- Use Kconfig default value instead of #ifdef-#define-#endif.
v3:
- Rebased on 3.6-rc5.
- Simplify configs. SHMOBILE_IPMMU is now selected by setting
SHMOBILE_IOMMU.
- Remove weak symbols.
- Use drvdata to store private driver data.
- Make a function for writing to a register of IPMMU.
- Add a lock to accessing the tlb_enabled member.
- Make unmap work correctly with size larger than map size.
- Free L2 page table when 1MiB page is mapped or unmapped.
- Add VEU devices as IP blocks on the ICB.
v2:
- Rebased on v3.6-rc1.
- Make variable names clear.
- Page table size can now be selected by config.
Hideki EIRAKU (4):
iommu/shmobile: Add iommu driver for Renesas IPMMU modules
ARM: mach-shmobile: sh7372: Add IPMMU device
ARM: mach-shmobile: sh73a0: Add IPMMU device
ARM: mach-shmobile: r8a7740: Add IPMMU device
arch/arm/mach-shmobile/setup-r8a7740.c | 33 ++++
arch/arm/mach-shmobile/setup-sh7372.c | 39 ++++
arch/arm/mach-shmobile/setup-sh73a0.c | 31 +++
drivers/iommu/Kconfig | 74 +++++++
drivers/iommu/Makefile | 2 +
drivers/iommu/shmobile-iommu.c | 341 +++++++++++++++++++++++++++++++++
drivers/iommu/shmobile-ipmmu.c | 136 +++++++++++++
drivers/iommu/shmobile-ipmmu.h | 37 ++++
include/linux/platform_data/sh_ipmmu.h | 18 ++
9 files changed, 711 insertions(+)
create mode 100644 drivers/iommu/shmobile-iommu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.h
create mode 100644 include/linux/platform_data/sh_ipmmu.h
--
1.8.0
^ permalink raw reply
* [PATCH v5 0/4] Renesas IPMMU driver for sh7372, sh73a0 and r8a7740
From: Hideki EIRAKU @ 2012-12-25 11:19 UTC (permalink / raw)
To: Paul Mundt, Magnus Damm, Russell King, Simon Horman,
Laurent Pinchart
Cc: linux-sh, iommu, linux-arm-kernel, linux-kernel, Marek Szyprowski,
Katsuya MATSUBARA, Damian Hobson-Garcia, Hideki EIRAKU
This is the Renesas IPMMU driver, IOMMU API implementation and IPMMU
device support for sh7372 (AP4EVB and Mackerel), sh73a0 and r8a7740.
The IPMMU module supports the MMU function and the PMB function. The
MMU function provides address translation by pagetable compatible with
ARMv6. The PMB function provides address translation including
tile-linear translation. This is implementation of the MMU function.
Note: The IPMMU module translates DMA memory address from all of the
IP blocks on the ICB. The IOMMU API has iommu_attach_device() which
attaches one device to one domain, but the IPMMU module cannot attach
only one device. The IPMMU module only can attach all devices to one
domain.
Tested on:
- armadillo800eva
- kzma9
- mackerel (I could not make it boot the v3.8-rc1 with Device Tree, so
I tested a kernel without Device Tree support, reverting
3b7b70552afe351a8bd8fff1eb2d60aab2206576 and
0ce53cdc5c7e28f378e480363a0b0c2ed7e7eaf9)
How to test:
1. Boot a kernel built with CONFIG_SHMOBILE_IOMMU=y.
2. Check whether a display on the board shows console normally.
3. Check whether the IMCTR1 register is 1 which means the MMU function enabled.
To read the IMCTR1 register:
# peekpoke 0xfe951000
4. Change the IMCTR1 to 0 to disable the MMU function.
To change the IMCTR1 register to 0:
# peekpoke 0xfe951000 0
5. Check whether the display shows broken data.
6. Change the IMCTR1 to 1 to enable the MMU function.
To change the IMCTR1 register to 1:
# peekpoke 0xfe951000 1
7. Check whether a display on the board shows console normally.
8. Capture and check the framebuffer contents via memory mapped by mmap().
To capture the framebuffer contents and save the image to a file "filename":
# fbcat /dev/fb0 > filename
To look at the contents saved by fbcat on a PC:
$ display filename
- fbcat can be downloaded from https://code.google.com/p/fbcat/.
- display is one of the ImageMagick tools.
- peekpoke is:
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <err.h>
int main(int argc,char**argv){
uint32_t*p,addr;
int fd=open("/dev/mem",O_RDWR);
if(fd<0)err(1,"open");
addr=strtoul(argv[1],NULL,0);
p=mmap(NULL,0x1000,PROT_READ|PROT_WRITE,MAP_SHARED,fd,addr&~0xfff);
if(p==MAP_FAILED)err(1,"mmap");
if(argc<=2)printf("0x%08x\n",p[addr/4&0x3ff]);
else printf("wrote 0x%08x\n",p[addr/4&0x3ff]=strtoul(argv[2],NULL,0));
}
Changelog:
v5:
- Rebased on 3.8-rc1.
- Add sh73a0 and r8a7740 support.
- CONFIG_SHMOBILE_IOMMU is now selectable only for arm shmobile
architecture.
- Fix "defined but not used" warnings when CONFIG_SHMOBILE_IOMMU is
not set.
- Add help text of CONFIG_SHMOBILE_IOMMU.
- Apply some of Laurent Pinchart's rework patches: Move the driver to
drivers/iommu/.
- Use platform_data to specify attaching devices instead of
ipmmu_add_device() API.
v4:
- Rebased on 3.7-rc1.
- Use address space size instead of page table size in config.
- Use Kconfig default value instead of #ifdef-#define-#endif.
v3:
- Rebased on 3.6-rc5.
- Simplify configs. SHMOBILE_IPMMU is now selected by setting
SHMOBILE_IOMMU.
- Remove weak symbols.
- Use drvdata to store private driver data.
- Make a function for writing to a register of IPMMU.
- Add a lock to accessing the tlb_enabled member.
- Make unmap work correctly with size larger than map size.
- Free L2 page table when 1MiB page is mapped or unmapped.
- Add VEU devices as IP blocks on the ICB.
v2:
- Rebased on v3.6-rc1.
- Make variable names clear.
- Page table size can now be selected by config.
Hideki EIRAKU (4):
iommu/shmobile: Add iommu driver for Renesas IPMMU modules
ARM: mach-shmobile: sh7372: Add IPMMU device
ARM: mach-shmobile: sh73a0: Add IPMMU device
ARM: mach-shmobile: r8a7740: Add IPMMU device
arch/arm/mach-shmobile/setup-r8a7740.c | 33 ++++
arch/arm/mach-shmobile/setup-sh7372.c | 39 ++++
arch/arm/mach-shmobile/setup-sh73a0.c | 31 +++
drivers/iommu/Kconfig | 74 +++++++
drivers/iommu/Makefile | 2 +
drivers/iommu/shmobile-iommu.c | 341 +++++++++++++++++++++++++++++++++
drivers/iommu/shmobile-ipmmu.c | 136 +++++++++++++
drivers/iommu/shmobile-ipmmu.h | 37 ++++
include/linux/platform_data/sh_ipmmu.h | 18 ++
9 files changed, 711 insertions(+)
create mode 100644 drivers/iommu/shmobile-iommu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.c
create mode 100644 drivers/iommu/shmobile-ipmmu.h
create mode 100644 include/linux/platform_data/sh_ipmmu.h
--
1.8.0
^ permalink raw reply
* Re: Does init start with any open files?
From: Borislav Petkov @ 2012-12-25 11:17 UTC (permalink / raw)
To: bbi5291; +Cc: linux-kernel
In-Reply-To: <CAMmfjbPKGD28070A0JvMyL02juYW5tuwNmVwrJ-1gFzkNhCuDQ@mail.gmail.com>
On Tue, Dec 25, 2012 at 02:38:09AM -0500, bbi5291 wrote:
> When the init process is created on system startup, does it have any
> open file descriptors? If so, where do they point?
$ tree /proc/1/fd
/proc/1/fd
└── 10 -> /run/initctl
0 directories, 1 file
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
^ permalink raw reply
* [Bug 50121] [Regression] Since kernel v3.5 several cards fail to resume, introduced by: 'convert to exec engine, and improve channel sync'
From: bugzilla-daemon-CC+yJ3UmIYqDUpFQwHEjaQ @ 2012-12-25 11:17 UTC (permalink / raw)
To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
In-Reply-To: <bug-50121-8800-V0hAGp6uBxMKqLRl/0Ahz6D7qz1kEfGD2LY78lusg7I@public.gmane.org/>
[-- Attachment #1.1: Type: text/plain, Size: 936 bytes --]
https://bugs.freedesktop.org/show_bug.cgi?id=50121
--- Comment #33 from Ronald <ronald645-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> ---
The FX5200 still functions and survived another cycle.
I went ahead and tested your patch on a 'G73 (NV4B)' as well. Since modeset
became mandatory suspend/resume never worked (anymore). It suspended, but
resumed with a garbled console where some colors are off. Eventually, the card
looks up.
Recent rework made the screen completely black. So the regression regressed
even further. Current head with your patch restores the second regression back
to where the display is garbled after resume (after which it looks up again).
So I'm fairly confident that your patch restores pre rework (v3.5) behaviour on
these cards with respect to suspend and resume cycles.
I'm going to test an NV4E laptop later, when I have time.
--
You are receiving this mail because:
You are the assignee for the bug.
[-- Attachment #1.2: Type: text/html, Size: 1828 bytes --]
[-- Attachment #2: Type: text/plain, Size: 181 bytes --]
_______________________________________________
Nouveau mailing list
Nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
http://lists.freedesktop.org/mailman/listinfo/nouveau
^ permalink raw reply
* Re: [PATCH 1/6] uvcvideo: Set error_idx properly for extended controls API failures
From: Hans Verkuil @ 2012-12-25 11:15 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: linux-media, Hans Verkuil
In-Reply-To: <1542143.Te5j8EM75x@avalon>
On Mon December 24 2012 13:27:08 Laurent Pinchart wrote:
> Hi Hans,
>
> On Thursday 27 September 2012 17:16:15 Laurent Pinchart wrote:
> > When one of the requested controls doesn't exist the error_idx field
> > must reflect that situation. For G_EXT_CTRLS and S_EXT_CTRLS, error_idx
> > must be set to the control count. For TRY_EXT_CTRLS, it must be set to
> > the index of the unexisting control.
> >
> > This issue was found by the v4l2-compliance tool.
>
> I'm revisiting this patch as it has been reverted in v3.8-rc1.
>
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> > drivers/media/usb/uvc/uvc_ctrl.c | 17 ++++++++++-------
> > drivers/media/usb/uvc/uvc_v4l2.c | 19 ++++++++++++-------
> > 2 files changed, 22 insertions(+), 14 deletions(-)
>
> [snip]
>
> > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c
> > b/drivers/media/usb/uvc/uvc_v4l2.c index f00db30..e5817b9 100644
> > --- a/drivers/media/usb/uvc/uvc_v4l2.c
> > +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> > @@ -591,8 +591,10 @@ static long uvc_v4l2_do_ioctl(struct file *file,
>
> [snip]
>
> > @@ -637,8 +639,9 @@ static long uvc_v4l2_do_ioctl(struct file *file,
> > unsigned int cmd, void *arg) ret = uvc_ctrl_get(chain, ctrl);
> > if (ret < 0) {
> > uvc_ctrl_rollback(handle);
> > - ctrls->error_idx = i;
> > - return ret;
> > + ctrls->error_idx = ret == -ENOENT
> > + ? ctrls->count : i;
> > + return ret == -ENOENT ? -EINVAL : ret;
> > }
> > }
> > ctrls->error_idx = 0;
> > @@ -661,8 +664,10 @@ static long uvc_v4l2_do_ioctl(struct file *file,
> > unsigned int cmd, void *arg) ret = uvc_ctrl_set(chain, ctrl);
> > if (ret < 0) {
> > uvc_ctrl_rollback(handle);
> > - ctrls->error_idx = i;
> > - return ret;
> > + ctrls->error_idx = (ret == -ENOENT &&
> > + cmd == VIDIOC_S_EXT_CTRLS)
> > + ? ctrls->count : i;
> > + return ret == -ENOENT ? -EINVAL : ret;
> > }
> > }
>
> I've reread the V4L2 specification, and the least I can say is that the text
> is pretty ambiguous. Let's clarify it.
>
> Is there a reason to differentiate between invalid control IDs and other
> errors as far as error_idx is concerned ? It would be simpler if error_idx was
> set to the index of the first error for get and try operations, regardless of
> the error type. What do you think ?
There is a good reason for doing this: the G/S_EXT_CTRLS ioctls have to be as atomic
as possible, i.e. it should try hard to prevent leaving the hardware in an
inconsistent state because not all controls could be set. It can never be fully
atomic since writing multiple registers over usb or i2c can always return errors
for one of those writes, but it should certainly check for all the obvious
errors first that do not require actually writing to the hardware, such as
whether all the controls in the control list actually exist.
And for such errors error_idx should be set to the number of controls to
indicate that none of the controls were actually set but that there was a
problem with the list of controls itself.
Since TRY_EXT_CTRLS doesn't touch the hardware at all the error_idx can be set
to the index of the control that caused the problem.
The documentation can definitely be improved as the difference between G/S and
TRY with regards to error_idx is not made explicit.
Regards,
Hans
^ permalink raw reply
* Re: [PATCH v2 8/8] MFD:rtsx: Use macro defines to replace some variables
From: Borislav Petkov @ 2012-12-25 11:14 UTC (permalink / raw)
To: wei_wang; +Cc: cjb, sameo, devel, linux-kernel, linux-mmc, gregkh, arnd, oakad
In-Reply-To: <9df15689e28b011b5401b09d0a9282d95171dab5.1356403281.git.wei_wang@realsil.com.cn>
On Tue, Dec 25, 2012 at 10:43:40AM +0800, wei_wang@realsil.com.cn wrote:
> From: Wei WANG <wei_wang@realsil.com.cn>
>
> In function rtsx_pci_switch_clock, some variables, such as min_n, max_n,
> and max_div, are not necessary. And those assigned values look very
> obscure for others. It's more proper to use macro definitions here to
> replace these variables.
>
> Signed-off-by: Wei WANG <wei_wang@realsil.com.cn>
Acked-by: Borislav Petkov <bp@alien8.de>
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
^ permalink raw reply
* Re: [PATCH v2 3/8] MFD:rtsx: Declare that the DMA address limitation is 32bit explicitly
From: Borislav Petkov @ 2012-12-25 11:13 UTC (permalink / raw)
To: wei_wang; +Cc: cjb, sameo, devel, linux-kernel, linux-mmc, gregkh, arnd, oakad
In-Reply-To: <7ba22b7e0e0be5a353cdfcfefbeff03a5be973c0.1356403281.git.wei_wang@realsil.com.cn>
On Tue, Dec 25, 2012 at 10:43:09AM +0800, wei_wang@realsil.com.cn wrote:
> From: Wei WANG <wei_wang@realsil.com.cn>
>
> Signed-off-by: Wei WANG <wei_wang@realsil.com.cn>
This one is still missing a commit message. You might want to write some
blubber about the hardware supporting only 32-bit DMA or whatever the
real reason is.
Also, with the whole patchset, please don't send it the very next day
but do wait a couple of days to collect all feedback from people -
especially now I'd wait even longer since everyone except you and me are
away :) - and then resend it after incorporating all feedback.
Thanks.
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
^ permalink raw reply
* Re: [PATCH v2 2/8] MFD:rtsx: Remove redundant code
From: Borislav Petkov @ 2012-12-25 11:11 UTC (permalink / raw)
To: wei_wang; +Cc: cjb, sameo, devel, linux-kernel, linux-mmc, gregkh, arnd, oakad
In-Reply-To: <29a6ff4a0fa5f8f307ed98de97b2ef9643352782.1356403281.git.wei_wang@realsil.com.cn>
On Tue, Dec 25, 2012 at 10:43:03AM +0800, wei_wang@realsil.com.cn wrote:
> From: Wei WANG <wei_wang@realsil.com.cn>
>
> In function rtsx_pci_add_sg_tbl, the statement "ptr++" is useless.
>
> Signed-off-by: Wei WANG <wei_wang@realsil.com.cn>
Acked-by: Borislav Petkov <bp@alien8.de>
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
^ permalink raw reply
* [PATCH v2 2/2] ARM: boot: dts: Add an entry for imx27-pdk.dtb
From: Fabio Estevam @ 2012-12-25 11:10 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1356433852-3028-1-git-send-email-festevam@gmail.com>
From: Fabio Estevam <fabio.estevam@freescale.com>
Add an entry for imx27-pdk.dtb, so that it can be generated by default.
Also, add an entry into Documentation/devicetree/bindings/arm/fsl.txt.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Changes since v2:
- No changes
Documentation/devicetree/bindings/arm/fsl.txt | 4 ++++
arch/arm/boot/dts/Makefile | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/arm/fsl.txt b/Documentation/devicetree/bindings/arm/fsl.txt
index f798187..4c25c98 100644
--- a/Documentation/devicetree/bindings/arm/fsl.txt
+++ b/Documentation/devicetree/bindings/arm/fsl.txt
@@ -5,6 +5,10 @@ i.MX23 Evaluation Kit
Required root node properties:
- compatible = "fsl,imx23-evk", "fsl,imx23";
+i.MX27 Product Development Kit
+Required root node properties:
+ - compatible = "fsl,imx27-pdk", "fsl,imx27";
+
i.MX28 Evaluation Kit
Required root node properties:
- compatible = "fsl,imx28-evk", "fsl,imx28";
diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index d077ef8..a48b511 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -80,7 +80,8 @@ dtb-$(CONFIG_ARCH_MVEBU) += armada-370-db.dtb \
armada-370-mirabox.dtb \
armada-xp-db.dtb \
armada-xp-openblocks-ax3-4.dtb
-dtb-$(CONFIG_ARCH_MXC) += imx51-babbage.dtb \
+dtb-$(CONFIG_ARCH_MXC) += imx27-pdk.dtb \
+ imx51-babbage.dtb \
imx53-ard.dtb \
imx53-evk.dtb \
imx53-qsb.dtb \
--
1.7.9.5
^ permalink raw reply related
* [PATCH v2 1/2] ARM: dts: imx27-3ds: Rename it to imx27-pdk
From: Fabio Estevam @ 2012-12-25 11:10 UTC (permalink / raw)
To: linux-arm-kernel
From: Fabio Estevam <fabio.estevam@freescale.com>
imx27-pdk is the name found on Freescale website, so use it instead of 3ds.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Changes since v1:
- Use 'fsl' instead of 'freescale' in the compatible field.
arch/arm/boot/dts/{imx27-3ds.dts => imx27-pdk.dts} | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
rename arch/arm/boot/dts/{imx27-3ds.dts => imx27-pdk.dts} (85%)
diff --git a/arch/arm/boot/dts/imx27-3ds.dts b/arch/arm/boot/dts/imx27-pdk.dts
similarity index 85%
rename from arch/arm/boot/dts/imx27-3ds.dts
rename to arch/arm/boot/dts/imx27-pdk.dts
index fa04c7b..860b6f2 100644
--- a/arch/arm/boot/dts/imx27-3ds.dts
+++ b/arch/arm/boot/dts/imx27-pdk.dts
@@ -13,8 +13,8 @@
/include/ "imx27.dtsi"
/ {
- model = "mx27_3ds";
- compatible = "freescale,imx27-3ds", "fsl,imx27";
+ model = "Freescale i.MX27 Product Development Kit";
+ compatible = "fsl,imx27-pdk", "fsl,imx27";
memory {
reg = <0x0 0x0>;
--
1.7.9.5
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.