diff mbox

[01/02] ARM: shmobile: Add shared R-Car Gen2 CMA reservation code

Message ID 20140609123845.31532.36468.sendpatchset@w520 (mailing list archive)
State Accepted
Commit f8e819352d12f1b7d109d846e9bf1c07e006469a
Headers show

Commit Message

Magnus Damm June 9, 2014, 12:38 p.m. UTC
From: Magnus Damm <damm+renesas@opensource.se>

Add R-Car Gen2 CMA memory reservation code that can be
shared between multiple SoCs and boards. At this point
r8a7790 and r8a7791 are supported.

The top 256MiB of the legacy 32-bit physical memory space
is assigned to a separate CMA area that may be assigned
to various devices later on.

Signed-off-by: Magnus Damm <damm+renesas@opensource.se>
---

 arch/arm/mach-shmobile/include/mach/rcar-gen2.h |    1 
 arch/arm/mach-shmobile/setup-r8a7790.c          |    1 
 arch/arm/mach-shmobile/setup-r8a7791.c          |    1 
 arch/arm/mach-shmobile/setup-rcar-gen2.c        |   79 +++++++++++++++++++++++
 4 files changed, 82 insertions(+)

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Geert Uytterhoeven June 10, 2014, 7:19 a.m. UTC | #1
Hi Magnus,

On Mon, Jun 9, 2014 at 2:38 PM, Magnus Damm <magnus.damm@gmail.com> wrote:
> --- 0001/arch/arm/mach-shmobile/setup-rcar-gen2.c
> +++ work/arch/arm/mach-shmobile/setup-rcar-gen2.c       2014-06-09 21:01:33.000000000 +0900

> +static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname,
> +                                    int depth, void *data)
> +{

> +       u64 lpae_start = (u64)1 << 32;

Casts are evil:

1ULL << 32

(I hope one day gcc will gain a "-Wcast" option, so we can easily find and
 inspect all casts, as C-style casts are much more difficult to grep for than
 C++-style casts).

> +       /* We are scanning "memory" nodes only */
> +       if (type == NULL) {
> +               /*
> +                * The longtrail doesn't have a device_type on the
> +                * /memory node, so look for the node called /memory@0.
> +                */
> +               if (depth != 1 || strcmp(uname, "memory@0") != 0)
> +                       return 0;

AFAIK Open Firmware in the LongTrail does not support plugging in ARM CPUs
in its PPC 603e/604e-compatible CPU socket ;-)

> +struct cma *rcar_gen2_dma_contiguous;
> +
> +void __init rcar_gen2_reserve(void)
> +{

> +#ifdef CONFIG_DMA_CMA
> +       if (mrc.size)
> +               dma_contiguous_reserve_area(mrc.size, mrc.base, 0,
> +                                           &rcar_gen2_dma_contiguous);
> +#endif

I assume one day rcar_gen2_dma_contiguous will become used?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Magnus Damm June 10, 2014, 10:51 a.m. UTC | #2
Hi Geert,

Thanks for your feedback!

On Tue, Jun 10, 2014 at 4:19 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> Hi Magnus,
>
> On Mon, Jun 9, 2014 at 2:38 PM, Magnus Damm <magnus.damm@gmail.com> wrote:
>> --- 0001/arch/arm/mach-shmobile/setup-rcar-gen2.c
>> +++ work/arch/arm/mach-shmobile/setup-rcar-gen2.c       2014-06-09 21:01:33.000000000 +0900
>
>> +static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname,
>> +                                    int depth, void *data)
>> +{
>
>> +       u64 lpae_start = (u64)1 << 32;
>
> Casts are evil:
>
> 1ULL << 32
>
> (I hope one day gcc will gain a "-Wcast" option, so we can easily find and
>  inspect all casts, as C-style casts are much more difficult to grep for than
>  C++-style casts).

Oh, right, I totally forgot I added that one. =)

>> +       /* We are scanning "memory" nodes only */
>> +       if (type == NULL) {
>> +               /*
>> +                * The longtrail doesn't have a device_type on the
>> +                * /memory node, so look for the node called /memory@0.
>> +                */
>> +               if (depth != 1 || strcmp(uname, "memory@0") != 0)
>> +                       return 0;
>
> AFAIK Open Firmware in the LongTrail does not support plugging in ARM CPUs
> in its PPC 603e/604e-compatible CPU socket ;-)

You never know - anything is possible with DT. =)

But yes, I get your point - will clean up.

>> +struct cma *rcar_gen2_dma_contiguous;
>> +
>> +void __init rcar_gen2_reserve(void)
>> +{
>
>> +#ifdef CONFIG_DMA_CMA
>> +       if (mrc.size)
>> +               dma_contiguous_reserve_area(mrc.size, mrc.base, 0,
>> +                                           &rcar_gen2_dma_contiguous);
>> +#endif
>
> I assume one day rcar_gen2_dma_contiguous will become used?

That's the idea, yes!

Since Simon kindly queued this up already I will submit an incremental
fix to deal with the issues that you pointed out.

Cheers,

/ magnus
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Simon Horman June 10, 2014, 11:40 p.m. UTC | #3
On Tue, Jun 10, 2014 at 07:51:38PM +0900, Magnus Damm wrote:
> Hi Geert,
> 
> Thanks for your feedback!
> 
> On Tue, Jun 10, 2014 at 4:19 PM, Geert Uytterhoeven
> <geert@linux-m68k.org> wrote:
> > Hi Magnus,
> >
> > On Mon, Jun 9, 2014 at 2:38 PM, Magnus Damm <magnus.damm@gmail.com> wrote:
> >> --- 0001/arch/arm/mach-shmobile/setup-rcar-gen2.c
> >> +++ work/arch/arm/mach-shmobile/setup-rcar-gen2.c       2014-06-09 21:01:33.000000000 +0900
> >
> >> +static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname,
> >> +                                    int depth, void *data)
> >> +{
> >
> >> +       u64 lpae_start = (u64)1 << 32;
> >
> > Casts are evil:
> >
> > 1ULL << 32
> >
> > (I hope one day gcc will gain a "-Wcast" option, so we can easily find and
> >  inspect all casts, as C-style casts are much more difficult to grep for than
> >  C++-style casts).
> 
> Oh, right, I totally forgot I added that one. =)
> 
> >> +       /* We are scanning "memory" nodes only */
> >> +       if (type == NULL) {
> >> +               /*
> >> +                * The longtrail doesn't have a device_type on the
> >> +                * /memory node, so look for the node called /memory@0.
> >> +                */
> >> +               if (depth != 1 || strcmp(uname, "memory@0") != 0)
> >> +                       return 0;
> >
> > AFAIK Open Firmware in the LongTrail does not support plugging in ARM CPUs
> > in its PPC 603e/604e-compatible CPU socket ;-)
> 
> You never know - anything is possible with DT. =)
> 
> But yes, I get your point - will clean up.
> 
> >> +struct cma *rcar_gen2_dma_contiguous;
> >> +
> >> +void __init rcar_gen2_reserve(void)
> >> +{
> >
> >> +#ifdef CONFIG_DMA_CMA
> >> +       if (mrc.size)
> >> +               dma_contiguous_reserve_area(mrc.size, mrc.base, 0,
> >> +                                           &rcar_gen2_dma_contiguous);
> >> +#endif
> >
> > I assume one day rcar_gen2_dma_contiguous will become used?
> 
> That's the idea, yes!
> 
> Since Simon kindly queued this up already I will submit an incremental
> fix to deal with the issues that you pointed out.

Thanks. FWIW I quite dislike casts.
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

--- 0001/arch/arm/mach-shmobile/include/mach/rcar-gen2.h
+++ work/arch/arm/mach-shmobile/include/mach/rcar-gen2.h	2014-06-09 20:51:34.000000000 +0900
@@ -4,5 +4,6 @@ 
 void rcar_gen2_timer_init(void);
 #define MD(nr) BIT(nr)
 u32 rcar_gen2_read_mode_pins(void);
+void rcar_gen2_reserve(void);
 
 #endif /* __ASM_RCAR_GEN2_H__ */
--- 0001/arch/arm/mach-shmobile/setup-r8a7790.c
+++ work/arch/arm/mach-shmobile/setup-r8a7790.c	2014-06-09 21:02:30.000000000 +0900
@@ -319,6 +319,7 @@  DT_MACHINE_START(R8A7790_DT, "Generic R8
 	.init_early	= shmobile_init_delay,
 	.init_time	= rcar_gen2_timer_init,
 	.init_late	= shmobile_init_late,
+	.reserve	= rcar_gen2_reserve,
 	.dt_compat	= r8a7790_boards_compat_dt,
 MACHINE_END
 #endif /* CONFIG_USE_OF */
--- 0001/arch/arm/mach-shmobile/setup-r8a7791.c
+++ work/arch/arm/mach-shmobile/setup-r8a7791.c	2014-06-09 21:02:37.000000000 +0900
@@ -218,6 +218,7 @@  DT_MACHINE_START(R8A7791_DT, "Generic R8
 	.init_early	= shmobile_init_delay,
 	.init_time	= rcar_gen2_timer_init,
 	.init_late	= shmobile_init_late,
+	.reserve	= rcar_gen2_reserve,
 	.dt_compat	= r8a7791_boards_compat_dt,
 MACHINE_END
 #endif /* CONFIG_USE_OF */
--- 0001/arch/arm/mach-shmobile/setup-rcar-gen2.c
+++ work/arch/arm/mach-shmobile/setup-rcar-gen2.c	2014-06-09 21:01:33.000000000 +0900
@@ -20,8 +20,11 @@ 
 
 #include <linux/clk/shmobile.h>
 #include <linux/clocksource.h>
+#include <linux/device.h>
+#include <linux/dma-contiguous.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
+#include <linux/of_fdt.h>
 #include <mach/common.h>
 #include <mach/rcar-gen2.h>
 #include <asm/mach/arch.h>
@@ -110,3 +113,79 @@  void __init rcar_gen2_timer_init(void)
 #endif
 	clocksource_of_init();
 }
+
+struct memory_reserve_config {
+	u64 reserved;
+	u64 base, size;
+};
+
+static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname,
+				     int depth, void *data)
+{
+	char *type = of_get_flat_dt_prop(node, "device_type", NULL);
+	__be32 *reg, *endp;
+	unsigned long l;
+	struct memory_reserve_config *mrc = data;
+	u64 lpae_start = (u64)1 << 32;
+
+	/* We are scanning "memory" nodes only */
+	if (type == NULL) {
+		/*
+		 * The longtrail doesn't have a device_type on the
+		 * /memory node, so look for the node called /memory@0.
+		 */
+		if (depth != 1 || strcmp(uname, "memory@0") != 0)
+			return 0;
+	} else if (strcmp(type, "memory") != 0)
+		return 0;
+
+	reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
+	if (reg == NULL)
+		reg = of_get_flat_dt_prop(node, "reg", &l);
+	if (reg == NULL)
+		return 0;
+
+	endp = reg + (l / sizeof(__be32));
+	while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
+		u64 base, size;
+
+		base = dt_mem_next_cell(dt_root_addr_cells, &reg);
+		size = dt_mem_next_cell(dt_root_size_cells, &reg);
+
+		if (base >= lpae_start)
+			continue;
+
+		if ((base + size) >= lpae_start)
+			size = lpae_start - base;
+
+		if (size < mrc->reserved)
+			continue;
+
+		if (base < mrc->base)
+			continue;
+
+		/* keep the area at top near the 32-bit legacy limit */
+		mrc->base = base + size - mrc->reserved;
+		mrc->size = mrc->reserved;
+	}
+
+	return 0;
+}
+
+struct cma *rcar_gen2_dma_contiguous;
+
+void __init rcar_gen2_reserve(void)
+{
+	struct memory_reserve_config mrc;
+
+	/* reserve 256 MiB at the top of the physical legacy 32-bit space */
+	memset(&mrc, 0, sizeof(mrc));
+	mrc.reserved = SZ_256M;
+
+	of_scan_flat_dt(rcar_gen2_scan_mem, &mrc);
+#ifdef CONFIG_DMA_CMA
+	if (mrc.size)
+		dma_contiguous_reserve_area(mrc.size, mrc.base, 0,
+					    &rcar_gen2_dma_contiguous);
+#endif
+}