* [PATCH] OMAP3 ROM Random Number Generator support
@ 2013-02-28 18:05 Pali Rohár
2013-03-24 14:15 ` Pali Rohár
2013-03-27 21:09 ` Tony Lindgren
0 siblings, 2 replies; 17+ messages in thread
From: Pali Rohár @ 2013-02-28 18:05 UTC (permalink / raw)
To: Tony Lindgren
Cc: Juha Yrjola, Russell King, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel
[-- Attachment #1: Type: Text/Plain, Size: 7871 bytes --]
This driver provides kernel-side support for the Random Number
Generator hardware found on OMAP34xx processors.
This driver is included in Maemo 2.6.28 kernel used on Nokia N900.
I fixed driver to work with 3.8 kernel and added platform_driver
code to autoload it on omap3 devices.
diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 626f3ea..48e40f3 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -446,6 +446,18 @@ static void omap_init_mcspi(void)
static inline void omap_init_mcspi(void) {}
#endif
+static struct platform_device omap3_rom_rng_device = {
+ .name = "omap3-rom-rng",
+ .id = -1,
+};
+
+static void omap_init_rom_rng(void)
+{
+ if (!cpu_is_omap34xx() || omap_type() == OMAP2_DEVICE_TYPE_GP)
+ return;
+ platform_device_register(&omap3_rom_rng_device);
+}
+
/**
* omap_init_rng - bind the RNG hwmod to the RNG omap_device
*
@@ -727,6 +739,7 @@ static int __init omap2_init_devices(void)
}
omap_init_sti();
omap_init_rng();
+ omap_init_rom_rng();
omap_init_sham();
omap_init_aes();
omap_init_vout();
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index c5a0262..2d51db6 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -153,6 +153,19 @@ config HW_RANDOM_OMAP
If unsure, say Y.
+config HW_RANDOM_OMAP3_ROM
+ tristate "OMAP3 ROM Random Number Generator support"
+ depends on HW_RANDOM && ARCH_OMAP3
+ default HW_RANDOM
+ ---help---
+ This driver provides kernel-side support for the Random Number
+ Generator hardware found on OMAP34xx processors.
+
+ To compile this driver as a module, choose M here: the
+ module will be called omap3-rom-rng.
+
+ If unsure, say Y.
+
config HW_RANDOM_OCTEON
tristate "Octeon Random Number Generator support"
depends on HW_RANDOM && CPU_CAVIUM_OCTEON
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index 1fd7eec..d227cd6 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -15,6 +15,8 @@ n2-rng-y := n2-drv.o n2-asm.o
obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
+obj-$(CONFIG_HW_RANDOM_OMAP3_ROM) += omap3-rom-rng.o
+omap3-rom-rng-y := omap3-rom-drv.o omap3-rom-asm.o
obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
diff --git a/drivers/char/hw_random/omap3-rom-asm.S b/drivers/char/hw_random/omap3-rom-asm.S
new file mode 100644
index 0000000..ce82e16
--- /dev/null
+++ b/drivers/char/hw_random/omap3-rom-asm.S
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+ENTRY(omap3_rng_call_rom_asm)
+ .arch_extension sec
+ stmfd sp!, {r4-r12, lr}
+ stmfd sp!, {r0-r3}
+ bl v7_flush_dcache_all
+ ldmfd sp!, {r0-r3}
+ mov r6, #0xff
+ mov r12, r0
+ smc #1
+ mov r12, r0
+ bl v7_flush_dcache_all
+ mov r0, #0
+ mcr p15, 0, r0, c7, c5, 0
+ mov r0, r12
+ ldmfd sp!, {r4-r12, pc}
diff --git a/drivers/char/hw_random/omap3-rom-drv.c b/drivers/char/hw_random/omap3-rom-drv.c
new file mode 100644
index 0000000..4e2c0ff
--- /dev/null
+++ b/drivers/char/hw_random/omap3-rom-drv.c
@@ -0,0 +1,167 @@
+/*
+ * omap3-rom-drv.c - RNG driver for TI OMAP3 CPU family
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ * Author: Juha Yrjola <juha.yrjola@solidboot.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/random.h>
+#include <linux/hw_random.h>
+#include <linux/timer.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+
+#include "../../../arch/arm/mach-omap2/soc.h"
+
+#define SEC_HAL_RNG_GENERATE 29
+#define RNG_RESET 0x01
+#define RNG_GEN_PRNG_HW_INIT 0x02
+#define RNG_GEN_HW 0x08
+
+static const char *omap3_rom_rng_name = "OMAP3 ROM RNG";
+
+extern u32 omap3_rng_call_rom_asm(u32 id, u32 proc, u32 flags, u32 va_ptr);
+
+static int call_sec_rom(u32 appl_id, u32 proc_id, u32 flag, ...)
+{
+ va_list ap;
+ u32 ret;
+ u32 val;
+
+ va_start(ap, flag);
+ val = *(u32 *) ≈
+ local_irq_disable();
+ local_fiq_disable();
+ ret = omap3_rng_call_rom_asm(appl_id, proc_id, flag,
+ (u32) virt_to_phys((void *) val));
+ local_fiq_enable();
+ local_irq_enable();
+ va_end(ap);
+
+ return ret;
+}
+
+static struct timer_list idle_timer;
+static int rng_idle;
+static struct clk *rng_clk;
+
+static void omap3_rom_idle_rng(unsigned long data)
+{
+ int r;
+
+ r = call_sec_rom(SEC_HAL_RNG_GENERATE, 0, 0, 3, NULL, 0,
+ RNG_RESET);
+ if (r != 0) {
+ printk(KERN_ERR "%s: reset failed: %d\n",
+ omap3_rom_rng_name, r);
+ return;
+ }
+ clk_disable_unprepare(rng_clk);
+ rng_idle = 1;
+}
+
+static int omap3_rom_get_random(void *buf, unsigned int count)
+{
+ u32 r;
+ u32 ptr;
+
+ del_timer_sync(&idle_timer);
+ if (rng_idle) {
+ clk_prepare_enable(rng_clk);
+ r = call_sec_rom(SEC_HAL_RNG_GENERATE, 0, 0, 3, NULL, 0,
+ RNG_GEN_PRNG_HW_INIT);
+ if (r != 0) {
+ clk_disable_unprepare(rng_clk);
+ printk(KERN_ERR "%s: HW init failed: %d\n",
+ omap3_rom_rng_name, r);
+ return -EIO;
+ }
+ rng_idle = 0;
+ }
+
+ ptr = virt_to_phys(buf);
+ r = call_sec_rom(SEC_HAL_RNG_GENERATE, 0, 0, 3, ptr,
+ count, RNG_GEN_HW);
+ mod_timer(&idle_timer, jiffies + msecs_to_jiffies(500));
+ if (r != 0)
+ return -EINVAL;
+ return 0;
+}
+
+static int omap3_rom_rng_data_present(struct hwrng *rng, int wait)
+{
+ return 1;
+}
+
+static int omap3_rom_rng_data_read(struct hwrng *rng, u32 *data)
+{
+ int r;
+
+ r = omap3_rom_get_random(data, 4);
+ if (r < 0)
+ return r;
+ return 4;
+}
+
+static struct hwrng omap3_rom_rng_ops = {
+ .name = "omap3-rom",
+ .data_present = omap3_rom_rng_data_present,
+ .data_read = omap3_rom_rng_data_read,
+};
+
+static int omap3_rom_rng_probe(struct platform_device *pdev)
+{
+ printk(KERN_INFO "%s: initializing\n", omap3_rom_rng_name);
+ if (!cpu_is_omap34xx()) {
+ printk(KERN_ERR "%s: currently supports only OMAP34xx CPUs\n",
+ omap3_rom_rng_name);
+ return -ENODEV;
+ }
+ if (omap_type() == OMAP2_DEVICE_TYPE_GP) {
+ printk(KERN_ERR "%s: GP OMAPs not supported\n",
+ omap3_rom_rng_name);
+ return -ENODEV;
+ }
+
+ setup_timer(&idle_timer, omap3_rom_idle_rng, 0);
+ rng_clk = clk_get_sys("omap_rng", "ick");
+ if (IS_ERR(rng_clk)) {
+ printk(KERN_ERR "%s: unable to get RNG clock\n",
+ omap3_rom_rng_name);
+ return IS_ERR(rng_clk);
+ }
+
+ /* Leave the RNG in reset state. */
+ clk_prepare_enable(rng_clk);
+ omap3_rom_idle_rng(0);
+
+ return hwrng_register(&omap3_rom_rng_ops);
+}
+
+static int omap3_rom_rng_remove(struct platform_device *pdev)
+{
+ hwrng_unregister(&omap3_rom_rng_ops);
+ return 0;
+}
+
+static struct platform_driver omap3_rom_rng_driver = {
+ .driver = {
+ .name = "omap3-rom-rng",
+ .owner = THIS_MODULE,
+ },
+ .probe = omap3_rom_rng_probe,
+ .remove = omap3_rom_rng_remove,
+};
+
+module_platform_driver(omap3_rom_rng_driver);
+
+MODULE_ALIAS("platform:omap3-rom-rng");
+MODULE_AUTHOR("Juha Yrjola");
+MODULE_LICENSE("GPL");
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-02-28 18:05 Pali Rohár
@ 2013-03-24 14:15 ` Pali Rohár
2013-03-27 21:09 ` Tony Lindgren
1 sibling, 0 replies; 17+ messages in thread
From: Pali Rohár @ 2013-03-24 14:15 UTC (permalink / raw)
To: Tony Lindgren
Cc: Juha Yrjola, Russell King, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel
[-- Attachment #1: Type: Text/Plain, Size: 456 bytes --]
On Thursday 28 February 2013 19:05:47 Pali Rohár wrote:
> This driver provides kernel-side support for the Random Number
> Generator hardware found on OMAP34xx processors.
>
> This driver is included in Maemo 2.6.28 kernel used on Nokia
> N900.
>
> I fixed driver to work with 3.8 kernel and added
> platform_driver code to autoload it on omap3 devices.
>
Hello, can somebody look at this driver?
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-02-28 18:05 Pali Rohár
2013-03-24 14:15 ` Pali Rohár
@ 2013-03-27 21:09 ` Tony Lindgren
2013-03-27 22:03 ` Pali Rohár
2013-03-28 9:52 ` Russell King - ARM Linux
1 sibling, 2 replies; 17+ messages in thread
From: Tony Lindgren @ 2013-03-27 21:09 UTC (permalink / raw)
To: Pali Rohár
Cc: Juha Yrjola, Russell King, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel
* Pali Rohár <pali.rohar@gmail.com> [130228 10:09]:
> --- /dev/null
> +++ b/drivers/char/hw_random/omap3-rom-asm.S
> @@ -0,0 +1,27 @@
> +/*
> + * Copyright (C) 2009 Nokia Corporation
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + */
> +
> +#include <linux/linkage.h>
> +#include <asm/assembler.h>
> +
> +ENTRY(omap3_rng_call_rom_asm)
> + .arch_extension sec
> + stmfd sp!, {r4-r12, lr}
> + stmfd sp!, {r0-r3}
> + bl v7_flush_dcache_all
> + ldmfd sp!, {r0-r3}
> + mov r6, #0xff
> + mov r12, r0
> + smc #1
> + mov r12, r0
> + bl v7_flush_dcache_all
> + mov r0, #0
> + mcr p15, 0, r0, c7, c5, 0
> + mov r0, r12
> + ldmfd sp!, {r4-r12, pc}
This part should be in arch/arm/mach-omap2 because of the
direct calls to v7_flush_dcache_all. Then you can pass a pointer
to this function in platform_data for now, and set it up based
on the compatible flag with device tree from driver later on.
> --- /dev/null
> +++ b/drivers/char/hw_random/omap3-rom-drv.c
> @@ -0,0 +1,167 @@
> +/*
> + * omap3-rom-drv.c - RNG driver for TI OMAP3 CPU family
> + *
> + * Copyright (C) 2009 Nokia Corporation
> + * Author: Juha Yrjola <juha.yrjola@solidboot.com>
> + *
> + * This file is licensed under the terms of the GNU General Public
> + * License version 2. This program is licensed "as is" without any
> + * warranty of any kind, whether express or implied.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/random.h>
> +#include <linux/hw_random.h>
> +#include <linux/timer.h>
> +#include <linux/clk.h>
> +#include <linux/err.h>
> +#include <linux/platform_device.h>
> +
> +#include "../../../arch/arm/mach-omap2/soc.h"
NAK for this, this must be private to arch/arm/mach-omap2.
Instead, just create a minimal include/linux/platform_data/omap3-rom.h,
and pass the function pointer in the pdata if passed.
> +static int omap3_rom_rng_probe(struct platform_device *pdev)
> +{
> + printk(KERN_INFO "%s: initializing\n", omap3_rom_rng_name);
> + if (!cpu_is_omap34xx()) {
> + printk(KERN_ERR "%s: currently supports only OMAP34xx CPUs\n",
> + omap3_rom_rng_name);
> + return -ENODEV;
> + }
> + if (omap_type() == OMAP2_DEVICE_TYPE_GP) {
> + printk(KERN_ERR "%s: GP OMAPs not supported\n",
> + omap3_rom_rng_name);
> + return -ENODEV;
> + }
> +
> + setup_timer(&idle_timer, omap3_rom_idle_rng, 0);
> + rng_clk = clk_get_sys("omap_rng", "ick");
> + if (IS_ERR(rng_clk)) {
> + printk(KERN_ERR "%s: unable to get RNG clock\n",
> + omap3_rom_rng_name);
> + return IS_ERR(rng_clk);
> + }
> +
> + /* Leave the RNG in reset state. */
> + clk_prepare_enable(rng_clk);
> + omap3_rom_idle_rng(0);
> +
> + return hwrng_register(&omap3_rom_rng_ops);
> +}
You should replace the cpu_is_omap34xx() and omap_type() with
some flags that you pass in the pdata. These too can be then
deciphered based on the DT compatible flag later on. And then
you don't need to include soc.h.
Regards,
Tony
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-27 21:09 ` Tony Lindgren
@ 2013-03-27 22:03 ` Pali Rohár
2013-03-27 22:25 ` Tony Lindgren
2013-03-28 9:52 ` Russell King - ARM Linux
1 sibling, 1 reply; 17+ messages in thread
From: Pali Rohár @ 2013-03-27 22:03 UTC (permalink / raw)
To: Tony Lindgren
Cc: Juha Yrjola, Russell King, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel
[-- Attachment #1: Type: Text/Plain, Size: 3815 bytes --]
On Wednesday 27 March 2013 22:09:18 Tony Lindgren wrote:
> * Pali Rohár <pali.rohar@gmail.com> [130228 10:09]:
> > --- /dev/null
> > +++ b/drivers/char/hw_random/omap3-rom-asm.S
> > @@ -0,0 +1,27 @@
> > +/*
> > + * Copyright (C) 2009 Nokia Corporation
> > + *
> > + * This program is free software; you can redistribute it
> > and/or modify + * it under the terms of the GNU General
> > Public License version 2 as + * published by the Free
> > Software Foundation.
> > + *
> > + */
> > +
> > +#include <linux/linkage.h>
> > +#include <asm/assembler.h>
> > +
> > +ENTRY(omap3_rng_call_rom_asm)
> > + .arch_extension sec
> > + stmfd sp!, {r4-r12, lr}
> > + stmfd sp!, {r0-r3}
> > + bl v7_flush_dcache_all
> > + ldmfd sp!, {r0-r3}
> > + mov r6, #0xff
> > + mov r12, r0
> > + smc #1
> > + mov r12, r0
> > + bl v7_flush_dcache_all
> > + mov r0, #0
> > + mcr p15, 0, r0, c7, c5, 0
> > + mov r0, r12
> > + ldmfd sp!, {r4-r12, pc}
>
> This part should be in arch/arm/mach-omap2 because of the
> direct calls to v7_flush_dcache_all. Then you can pass a
> pointer to this function in platform_data for now, and set it
> up based on the compatible flag with device tree from driver
> later on.
>
Ok, I will move this file to arch/arm/mach-omap2/omap3-rom-rng.S
and pass function via platform_data to driver.
> > --- /dev/null
> > +++ b/drivers/char/hw_random/omap3-rom-drv.c
> > @@ -0,0 +1,167 @@
> > +/*
> > + * omap3-rom-drv.c - RNG driver for TI OMAP3 CPU family
> > + *
> > + * Copyright (C) 2009 Nokia Corporation
> > + * Author: Juha Yrjola <juha.yrjola@solidboot.com>
> > + *
> > + * This file is licensed under the terms of the GNU
> > General Public + * License version 2. This program is
> > licensed "as is" without any + * warranty of any kind,
> > whether express or implied. + */
> > +
> > +#include <linux/module.h>
> > +#include <linux/init.h>
> > +#include <linux/random.h>
> > +#include <linux/hw_random.h>
> > +#include <linux/timer.h>
> > +#include <linux/clk.h>
> > +#include <linux/err.h>
> > +#include <linux/platform_device.h>
> > +
> > +#include "../../../arch/arm/mach-omap2/soc.h"
>
> NAK for this, this must be private to arch/arm/mach-omap2.
>
> Instead, just create a minimal
> include/linux/platform_data/omap3-rom.h, and pass the
> function pointer in the pdata if passed.
>
> > +static int omap3_rom_rng_probe(struct platform_device
> > *pdev) +{
> > + printk(KERN_INFO "%s: initializing\n",
> > omap3_rom_rng_name); + if (!cpu_is_omap34xx()) {
> > + printk(KERN_ERR "%s: currently supports only OMAP34xx
> > CPUs\n", + omap3_rom_rng_name);
> > + return -ENODEV;
> > + }
> > + if (omap_type() == OMAP2_DEVICE_TYPE_GP) {
> > + printk(KERN_ERR "%s: GP OMAPs not supported\n",
> > + omap3_rom_rng_name);
> > + return -ENODEV;
> > + }
> > +
> > + setup_timer(&idle_timer, omap3_rom_idle_rng, 0);
> > + rng_clk = clk_get_sys("omap_rng", "ick");
> > + if (IS_ERR(rng_clk)) {
> > + printk(KERN_ERR "%s: unable to get RNG clock\n",
> > + omap3_rom_rng_name);
> > + return IS_ERR(rng_clk);
> > + }
> > +
> > + /* Leave the RNG in reset state. */
> > + clk_prepare_enable(rng_clk);
> > + omap3_rom_idle_rng(0);
> > +
> > + return hwrng_register(&omap3_rom_rng_ops);
> > +}
>
> You should replace the cpu_is_omap34xx() and omap_type() with
> some flags that you pass in the pdata. These too can be then
> deciphered based on the DT compatible flag later on. And then
> you don't need to include soc.h.
>
> Regards,
>
> Tony
I will remove above code for checking omap type from hw rand
driver, because same code is in omap part which creating
platform_device for this driver. So soc.h is not needed.
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-27 22:03 ` Pali Rohár
@ 2013-03-27 22:25 ` Tony Lindgren
2013-03-28 17:54 ` Pali Rohár
0 siblings, 1 reply; 17+ messages in thread
From: Tony Lindgren @ 2013-03-27 22:25 UTC (permalink / raw)
To: Pali Rohár
Cc: Juha Yrjola, Russell King, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel
* Pali Rohár <pali.rohar@gmail.com> [130327 15:08]:
>
> I will remove above code for checking omap type from hw rand
> driver, because same code is in omap part which creating
> platform_device for this driver. So soc.h is not needed.
OK thanks,
Tony
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-27 21:09 ` Tony Lindgren
2013-03-27 22:03 ` Pali Rohár
@ 2013-03-28 9:52 ` Russell King - ARM Linux
2013-03-28 17:24 ` Pali Rohár
1 sibling, 1 reply; 17+ messages in thread
From: Russell King - ARM Linux @ 2013-03-28 9:52 UTC (permalink / raw)
To: Tony Lindgren
Cc: Pali Rohár, Juha Yrjola, Matt Mackall, Herbert Xu,
linux-omap, linux-kernel
On Wed, Mar 27, 2013 at 02:09:18PM -0700, Tony Lindgren wrote:
> > + setup_timer(&idle_timer, omap3_rom_idle_rng, 0);
> > + rng_clk = clk_get_sys("omap_rng", "ick");
Why is this using clk_get_sys when it should be using clk_get() with the
platform device?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-28 9:52 ` Russell King - ARM Linux
@ 2013-03-28 17:24 ` Pali Rohár
0 siblings, 0 replies; 17+ messages in thread
From: Pali Rohár @ 2013-03-28 17:24 UTC (permalink / raw)
To: Russell King - ARM Linux
Cc: Tony Lindgren, Juha Yrjola, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel
[-- Attachment #1: Type: Text/Plain, Size: 544 bytes --]
On Thursday 28 March 2013 10:52:28 Russell King - ARM Linux
wrote:
> On Wed, Mar 27, 2013 at 02:09:18PM -0700, Tony Lindgren wrote:
> > > + setup_timer(&idle_timer, omap3_rom_idle_rng, 0);
> > > + rng_clk = clk_get_sys("omap_rng", "ick");
>
> Why is this using clk_get_sys when it should be using
> clk_get() with the platform device?
Funcion clk_get() needs struct device* instead clk device name.
And I do not know how to get that pointer to device. With
clk_get_sys driver working.
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-27 22:25 ` Tony Lindgren
@ 2013-03-28 17:54 ` Pali Rohár
2013-03-28 21:44 ` Tony Lindgren
0 siblings, 1 reply; 17+ messages in thread
From: Pali Rohár @ 2013-03-28 17:54 UTC (permalink / raw)
To: Tony Lindgren
Cc: Juha Yrjola, Russell King, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel
[-- Attachment #1: Type: Text/Plain, Size: 8628 bytes --]
On Wednesday 27 March 2013 23:25:24 Tony Lindgren wrote:
> * Pali Rohár <pali.rohar@gmail.com> [130327 15:08]:
> > I will remove above code for checking omap type from hw rand
> > driver, because same code is in omap part which creating
> > platform_device for this driver. So soc.h is not needed.
>
> OK thanks,
>
> Tony
Here is new version of patch:
diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index 5423456..37c4e09 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -82,7 +82,7 @@ obj-$(CONFIG_OMAP_PM_NOOP) += omap-pm-noop.o
ifeq ($(CONFIG_PM),y)
obj-$(CONFIG_ARCH_OMAP2) += pm24xx.o
obj-$(CONFIG_ARCH_OMAP2) += sleep24xx.o
-obj-$(CONFIG_ARCH_OMAP3) += pm34xx.o sleep34xx.o
+obj-$(CONFIG_ARCH_OMAP3) += pm34xx.o sleep34xx.o omap3-rom-rng.o
obj-$(CONFIG_ARCH_OMAP4) += pm44xx.o omap-mpuss-lowpower.o
obj-$(CONFIG_SOC_OMAP5) += omap-mpuss-lowpower.o
obj-$(CONFIG_PM_DEBUG) += pm-debug.o
diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 1ec7f05..0b6260a1 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -486,6 +486,23 @@ static void omap_init_mcspi(void)
static inline void omap_init_mcspi(void) {}
#endif
+extern u32 *omap3_rom_rng_call(u32 id, u32 proc, u32 flags, u32 va_ptr);
+
+static struct platform_device omap3_rom_rng_device = {
+ .name = "omap3-rom-rng",
+ .id = -1,
+ .dev = {
+ .platform_data = omap3_rom_rng_call,
+ },
+};
+
+static void omap_init_rom_rng(void)
+{
+ if (!cpu_is_omap34xx() || omap_type() == OMAP2_DEVICE_TYPE_GP)
+ return;
+ platform_device_register(&omap3_rom_rng_device);
+}
+
/**
* omap_init_rng - bind the RNG hwmod to the RNG omap_device
*
@@ -767,6 +784,7 @@ static int __init omap2_init_devices(void)
}
omap_init_sti();
omap_init_rng();
+ omap_init_rom_rng();
omap_init_sham();
omap_init_aes();
omap_init_vout();
diff --git a/arch/arm/mach-omap2/omap3-rom-rng.S b/arch/arm/mach-omap2/omap3-rom-rng.S
new file mode 100644
index 0000000..5d7d886
--- /dev/null
+++ b/arch/arm/mach-omap2/omap3-rom-rng.S
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation
+ * Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+ENTRY(omap3_rom_rng_call)
+ .arch_extension sec
+ stmfd sp!, {r4-r12, lr}
+ stmfd sp!, {r0-r3}
+ bl v7_flush_dcache_all
+ ldmfd sp!, {r0-r3}
+ mov r6, #0xff
+ mov r12, r0
+ smc #1
+ mov r12, r0
+ bl v7_flush_dcache_all
+ mov r0, #0
+ mcr p15, 0, r0, c7, c5, 0
+ mov r0, r12
+ ldmfd sp!, {r4-r12, pc}
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index c5a0262..2d51db6 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -153,6 +153,19 @@ config HW_RANDOM_OMAP
If unsure, say Y.
+config HW_RANDOM_OMAP3_ROM
+ tristate "OMAP3 ROM Random Number Generator support"
+ depends on HW_RANDOM && ARCH_OMAP3
+ default HW_RANDOM
+ ---help---
+ This driver provides kernel-side support for the Random Number
+ Generator hardware found on OMAP34xx processors.
+
+ To compile this driver as a module, choose M here: the
+ module will be called omap3-rom-rng.
+
+ If unsure, say Y.
+
config HW_RANDOM_OCTEON
tristate "Octeon Random Number Generator support"
depends on HW_RANDOM && CPU_CAVIUM_OCTEON
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index 1fd7eec..c53e018 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -15,6 +15,7 @@ n2-rng-y := n2-drv.o n2-asm.o
obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
+obj-$(CONFIG_HW_RANDOM_OMAP3_ROM) += omap3-rom-rng.o
obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
new file mode 100644
index 0000000..5343415
--- /dev/null
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -0,0 +1,165 @@
+/*
+ * omap3-rom-drv.c - RNG driver for TI OMAP3 CPU family
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ * Author: Juha Yrjola <juha.yrjola@solidboot.com>
+ *
+ * Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/random.h>
+#include <linux/hw_random.h>
+#include <linux/timer.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+
+#define SEC_HAL_RNG_GENERATE 29
+#define RNG_RESET 0x01
+#define RNG_GEN_PRNG_HW_INIT 0x02
+#define RNG_GEN_HW 0x08
+
+static const char *omap3_rom_rng_name = "OMAP3 ROM RNG";
+
+static u32 (*omap3_rom_rng_call)(u32, u32, u32, u32);
+
+static int call_sec_rom(u32 appl_id, u32 proc_id, u32 flag, ...)
+{
+ va_list ap;
+ u32 ret;
+ u32 val;
+
+ va_start(ap, flag);
+ val = *(u32 *) ≈
+ local_irq_disable();
+ local_fiq_disable();
+ ret = omap3_rom_rng_call(appl_id, proc_id, flag,
+ (u32) virt_to_phys((void *) val));
+ local_fiq_enable();
+ local_irq_enable();
+ va_end(ap);
+
+ return ret;
+}
+
+static struct timer_list idle_timer;
+static int rng_idle;
+static struct clk *rng_clk;
+
+static void omap3_rom_idle_rng(unsigned long data)
+{
+ int r;
+
+ r = call_sec_rom(SEC_HAL_RNG_GENERATE, 0, 0, 3, NULL, 0,
+ RNG_RESET);
+ if (r != 0) {
+ printk(KERN_ERR "%s: reset failed: %d\n",
+ omap3_rom_rng_name, r);
+ return;
+ }
+ clk_disable_unprepare(rng_clk);
+ rng_idle = 1;
+}
+
+static int omap3_rom_get_random(void *buf, unsigned int count)
+{
+ u32 r;
+ u32 ptr;
+
+ del_timer_sync(&idle_timer);
+ if (rng_idle) {
+ clk_prepare_enable(rng_clk);
+ r = call_sec_rom(SEC_HAL_RNG_GENERATE, 0, 0, 3, NULL, 0,
+ RNG_GEN_PRNG_HW_INIT);
+ if (r != 0) {
+ clk_disable_unprepare(rng_clk);
+ printk(KERN_ERR "%s: HW init failed: %d\n",
+ omap3_rom_rng_name, r);
+ return -EIO;
+ }
+ rng_idle = 0;
+ }
+
+ ptr = virt_to_phys(buf);
+ r = call_sec_rom(SEC_HAL_RNG_GENERATE, 0, 0, 3, ptr,
+ count, RNG_GEN_HW);
+ mod_timer(&idle_timer, jiffies + msecs_to_jiffies(500));
+ if (r != 0)
+ return -EINVAL;
+ return 0;
+}
+
+static int omap3_rom_rng_data_present(struct hwrng *rng, int wait)
+{
+ return 1;
+}
+
+static int omap3_rom_rng_data_read(struct hwrng *rng, u32 *data)
+{
+ int r;
+
+ r = omap3_rom_get_random(data, 4);
+ if (r < 0)
+ return r;
+ return 4;
+}
+
+static struct hwrng omap3_rom_rng_ops = {
+ .name = "omap3-rom",
+ .data_present = omap3_rom_rng_data_present,
+ .data_read = omap3_rom_rng_data_read,
+};
+
+static int omap3_rom_rng_probe(struct platform_device *pdev)
+{
+ printk(KERN_INFO "%s: initializing\n", omap3_rom_rng_name);
+
+ omap3_rom_rng_call = pdev->dev.platform_data;
+ if (!omap3_rom_rng_call) {
+ printk(KERN_ERR "%s: omap3_rom_rng_call is NULL\n",
+ omap3_rom_rng_name);
+ return -EINVAL;
+ }
+
+ setup_timer(&idle_timer, omap3_rom_idle_rng, 0);
+ rng_clk = clk_get_sys("omap_rng", "ick");
+ if (IS_ERR(rng_clk)) {
+ printk(KERN_ERR "%s: unable to get RNG clock\n",
+ omap3_rom_rng_name);
+ return IS_ERR(rng_clk);
+ }
+
+ /* Leave the RNG in reset state. */
+ clk_prepare_enable(rng_clk);
+ omap3_rom_idle_rng(0);
+
+ return hwrng_register(&omap3_rom_rng_ops);
+}
+
+static int omap3_rom_rng_remove(struct platform_device *pdev)
+{
+ hwrng_unregister(&omap3_rom_rng_ops);
+ return 0;
+}
+
+static struct platform_driver omap3_rom_rng_driver = {
+ .driver = {
+ .name = "omap3-rom-rng",
+ .owner = THIS_MODULE,
+ },
+ .probe = omap3_rom_rng_probe,
+ .remove = omap3_rom_rng_remove,
+};
+
+module_platform_driver(omap3_rom_rng_driver);
+
+MODULE_ALIAS("platform:omap3-rom-rng");
+MODULE_AUTHOR("Juha Yrjola");
+MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
+MODULE_LICENSE("GPL");
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-28 17:54 ` Pali Rohár
@ 2013-03-28 21:44 ` Tony Lindgren
2013-03-31 9:28 ` Pali Rohár
0 siblings, 1 reply; 17+ messages in thread
From: Tony Lindgren @ 2013-03-28 21:44 UTC (permalink / raw)
To: Pali Rohár
Cc: Juha Yrjola, Russell King, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel
* Pali Rohár <pali.rohar@gmail.com> [130328 10:58]:
>
> Here is new version of patch:
>
> --- a/arch/arm/mach-omap2/devices.c
> +++ b/arch/arm/mach-omap2/devices.c
> @@ -486,6 +486,23 @@ static void omap_init_mcspi(void)
> static inline void omap_init_mcspi(void) {}
> #endif
>
> +extern u32 *omap3_rom_rng_call(u32 id, u32 proc, u32 flags, u32 va_ptr);
> +
> +static struct platform_device omap3_rom_rng_device = {
> + .name = "omap3-rom-rng",
> + .id = -1,
> + .dev = {
> + .platform_data = omap3_rom_rng_call,
> + },
> +};
> +
> +static void omap_init_rom_rng(void)
> +{
> + if (!cpu_is_omap34xx() || omap_type() == OMAP2_DEVICE_TYPE_GP)
> + return;
> + platform_device_register(&omap3_rom_rng_device);
> +}
> +
> /**
> * omap_init_rng - bind the RNG hwmod to the RNG omap_device
> *
This driver probably only works on Nokia boards because of the
different SMC call numbering. Until it's been verified on some
other HS omap34xx, I'd probably register this only from the
Nokia board-*.c file.
> --- /dev/null
> +++ b/drivers/char/hw_random/omap3-rom-rng.c
> +static int omap3_rom_rng_probe(struct platform_device *pdev)
> +{
> + printk(KERN_INFO "%s: initializing\n", omap3_rom_rng_name);
> +
> + omap3_rom_rng_call = pdev->dev.platform_data;
> + if (!omap3_rom_rng_call) {
> + printk(KERN_ERR "%s: omap3_rom_rng_call is NULL\n",
> + omap3_rom_rng_name);
> + return -EINVAL;
> + }
> +
> + setup_timer(&idle_timer, omap3_rom_idle_rng, 0);
> + rng_clk = clk_get_sys("omap_rng", "ick");
> + if (IS_ERR(rng_clk)) {
> + printk(KERN_ERR "%s: unable to get RNG clock\n",
> + omap3_rom_rng_name);
> + return IS_ERR(rng_clk);
> + }
You can use regular clk_get if you add the alias to
struct omap_clk omap3xxx_clks table.
Regards,
Tony
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-28 21:44 ` Tony Lindgren
@ 2013-03-31 9:28 ` Pali Rohár
2013-04-01 16:25 ` Tony Lindgren
0 siblings, 1 reply; 17+ messages in thread
From: Pali Rohár @ 2013-03-31 9:28 UTC (permalink / raw)
To: Tony Lindgren
Cc: Juha Yrjola, Russell King, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel,
Ивайло Димитров
[-- Attachment #1: Type: Text/Plain, Size: 2302 bytes --]
On Thursday 28 March 2013 22:44:11 Tony Lindgren wrote:
> * Pali Rohár <pali.rohar@gmail.com> [130328 10:58]:
> > Here is new version of patch:
> >
> > --- a/arch/arm/mach-omap2/devices.c
> > +++ b/arch/arm/mach-omap2/devices.c
> > @@ -486,6 +486,23 @@ static void omap_init_mcspi(void)
> >
> > static inline void omap_init_mcspi(void) {}
> > #endif
> >
> > +extern u32 *omap3_rom_rng_call(u32 id, u32 proc, u32 flags,
> > u32 va_ptr); +
> > +static struct platform_device omap3_rom_rng_device = {
> > + .name = "omap3-rom-rng",
> > + .id = -1,
> > + .dev = {
> > + .platform_data = omap3_rom_rng_call,
> > + },
> > +};
> > +
> > +static void omap_init_rom_rng(void)
> > +{
> > + if (!cpu_is_omap34xx() || omap_type() ==
> > OMAP2_DEVICE_TYPE_GP) + return;
> > + platform_device_register(&omap3_rom_rng_device);
> > +}
> > +
> >
> > /**
> >
> > * omap_init_rng - bind the RNG hwmod to the RNG
> > omap_device *
>
> This driver probably only works on Nokia boards because of the
> different SMC call numbering. Until it's been verified on some
> other HS omap34xx, I'd probably register this only from the
> Nokia board-*.c file.
>
Freemangordon, can you look at this smc and errara 430973 code if
they could be merged? Really omap3_rom_rng_call function looks
like n900 specific.
Link: https://lkml.org/lkml/2013/3/28/398
> > --- /dev/null
> > +++ b/drivers/char/hw_random/omap3-rom-rng.c
> > +static int omap3_rom_rng_probe(struct platform_device
> > *pdev) +{
> > + printk(KERN_INFO "%s: initializing\n",
> > omap3_rom_rng_name); +
> > + omap3_rom_rng_call = pdev->dev.platform_data;
> > + if (!omap3_rom_rng_call) {
> > + printk(KERN_ERR "%s: omap3_rom_rng_call is NULL\n",
> > + omap3_rom_rng_name);
> > + return -EINVAL;
> > + }
> > +
> > + setup_timer(&idle_timer, omap3_rom_idle_rng, 0);
> > + rng_clk = clk_get_sys("omap_rng", "ick");
> > + if (IS_ERR(rng_clk)) {
> > + printk(KERN_ERR "%s: unable to get RNG clock\n",
> > + omap3_rom_rng_name);
> > + return IS_ERR(rng_clk);
> > + }
>
> You can use regular clk_get if you add the alias to
> struct omap_clk omap3xxx_clks table.
>
> Regards,
>
> Tony
Tony, can you show me how?
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
@ 2013-03-31 12:05 Ивайло Димитров
2013-03-31 12:43 ` Pali Rohár
` (2 more replies)
0 siblings, 3 replies; 17+ messages in thread
From: Ивайло Димитров @ 2013-03-31 12:05 UTC (permalink / raw)
To: Pali Rohár
Cc: tony, juha.yrjola, linux, mpm, herbert, linux-omap, linux-kernel
Hi Pali,
Yep, the code looks almost identical, I guess with some tweaks all SMC code from that patch could be removed and instead used the one from SMC PPA API.
What I don't get, is why one needs to disable/enable fiqs/irqs:
+static int call_sec_rom(u32 appl_id, u32 proc_id, u32 flag, ...)
+{
+ va_list ap;
+ u32 ret;
+ u32 val;
+
+ va_start(ap, flag);
+ val = *(u32 *) ≈
+ local_irq_disable();
+ local_fiq_disable();
+ ret = omap3_rom_rng_call(appl_id, proc_id, flag,
+ (u32) virt_to_phys((void *) val));
+ local_fiq_enable();
+ local_irq_enable();
+ va_end(ap);
+
+ return ret;
+}
Do you have any idea why is that needed? Any other code I've ever seen to call SM, does not disable fiqs/irqs, is RNG SMC somehow special? I know this is Nokia's code, but still, if we can get some understanding...
Regards,
Ivo
>-------- Оригинално писмо --------
>От: Pali Rohár
>Относно: Re: [PATCH] OMAP3 ROM Random Number Generator support
>До: Tony Lindgren
>Изпратено на: Неделя, 2013, Март 31 12:28:12 EEST
>
>
>On Thursday 28 March 2013 22:44:11 Tony Lindgren wrote:
>> * Pali Rohár [130328 10:58]:
>> > Here is new version of patch:
>> >
>> > --- a/arch/arm/mach-omap2/devices.c
>> > +++ b/arch/arm/mach-omap2/devices.c
>> > @@ -486,6 +486,23 @@ static void omap_init_mcspi(void)
>> >
>> > static inline void omap_init_mcspi(void) {}
>> > #endif
>> >
>> > +extern u32 *omap3_rom_rng_call(u32 id, u32 proc, u32 flags,
>> > u32 va_ptr); +
>> > +static struct platform_device omap3_rom_rng_device = {
>> > + .name = "omap3-rom-rng",
>> > + .id = -1,
>> > + .dev = {
>> > + .platform_data = omap3_rom_rng_call,
>> > + },
>> > +};
>> > +
>> > +static void omap_init_rom_rng(void)
>> > +{
>> > + if (!cpu_is_omap34xx() || omap_type() ==
>> > OMAP2_DEVICE_TYPE_GP) + return;
>> > + platform_device_register(&omap3_rom_rng_device);
>> > +}
>> > +
>> >
>> > /**
>> >
>> > * omap_init_rng - bind the RNG hwmod to the RNG
>> > omap_device *
>>
>> This driver probably only works on Nokia boards because of the
>> different SMC call numbering. Until it's been verified on some
>> other HS omap34xx, I'd probably register this only from the
>> Nokia board-*.c file.
>>
>
>Freemangordon, can you look at this smc and errara 430973 code if
>they could be merged? Really omap3_rom_rng_call function looks
>like n900 specific.
>
>Link: https://lkml.org/lkml/2013/3/28/398
>
>> > --- /dev/null
>> > +++ b/drivers/char/hw_random/omap3-rom-rng.c
>> > +static int omap3_rom_rng_probe(struct platform_device
>> > *pdev) +{
>> > + printk(KERN_INFO "%s: initializing\n",
>> > omap3_rom_rng_name); +
>> > + omap3_rom_rng_call = pdev->dev.platform_data;
>> > + if (!omap3_rom_rng_call) {
>> > + printk(KERN_ERR "%s: omap3_rom_rng_call is NULL\n",
>> > + omap3_rom_rng_name);
>> > + return -EINVAL;
>> > + }
>> > +
>> > + setup_timer(&idle_timer, omap3_rom_idle_rng, 0);
>> > + rng_clk = clk_get_sys("omap_rng", "ick");
>> > + if (IS_ERR(rng_clk)) {
>> > + printk(KERN_ERR "%s: unable to get RNG clock\n",
>> > + omap3_rom_rng_name);
>> > + return IS_ERR(rng_clk);
>> > + }
>>
>> You can use regular clk_get if you add the alias to
>> struct omap_clk omap3xxx_clks table.
>>
>> Regards,
>>
>> Tony
>
>Tony, can you show me how?
>
>--
>Pali Rohár
>pali.rohar@gmail.com
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-31 12:05 [PATCH] OMAP3 ROM Random Number Generator support Ивайло Димитров
@ 2013-03-31 12:43 ` Pali Rohár
2013-04-01 16:59 ` Tony Lindgren
2013-04-01 22:09 ` Aaro Koskinen
2 siblings, 0 replies; 17+ messages in thread
From: Pali Rohár @ 2013-03-31 12:43 UTC (permalink / raw)
To: Ивайло Димитров
Cc: tony, juha.yrjola, linux, mpm, herbert, linux-omap, linux-kernel
[-- Attachment #1: Type: Text/Plain, Size: 1157 bytes --]
On Sunday 31 March 2013 14:05:42 Ивайло Димитров wrote:
> Hi Pali,
>
> Yep, the code looks almost identical, I guess with some tweaks
> all SMC code from that patch could be removed and instead
> used the one from SMC PPA API.
>
> What I don't get, is why one needs to disable/enable
> fiqs/irqs:
>
> +static int call_sec_rom(u32 appl_id, u32 proc_id, u32 flag,
> ...) +{
> + va_list ap;
> + u32 ret;
> + u32 val;
> +
> + va_start(ap, flag);
> + val = *(u32 *) ≈
> + local_irq_disable();
> + local_fiq_disable();
> + ret = omap3_rom_rng_call(appl_id, proc_id, flag,
> + (u32) virt_to_phys((void *) val));
> + local_fiq_enable();
> + local_irq_enable();
> + va_end(ap);
> +
> + return ret;
> +}
>
> Do you have any idea why is that needed? Any other code I've
> ever seen to call SM, does not disable fiqs/irqs, is RNG SMC
> somehow special? I know this is Nokia's code, but still, if
> we can get some understanding...
>
> Regards,
> Ivo
This driver is written by Juha Yrjola and is part of maemo 2.6.28 kernel.
Juha Yrjola, are you still around?
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-31 9:28 ` Pali Rohár
@ 2013-04-01 16:25 ` Tony Lindgren
0 siblings, 0 replies; 17+ messages in thread
From: Tony Lindgren @ 2013-04-01 16:25 UTC (permalink / raw)
To: Pali Rohár
Cc: Juha Yrjola, Russell King, Matt Mackall, Herbert Xu, linux-omap,
linux-kernel,
Ивайло Димитров
* Pali Rohár <pali.rohar@gmail.com> [130331 02:32]:
> On Thursday 28 March 2013 22:44:11 Tony Lindgren wrote:
> >
> > You can use regular clk_get if you add the alias to
> > struct omap_clk omap3xxx_clks table.
>
> Tony, can you show me how?
Take a look at the omap3xxx_clks in cclock3xxx_data.c.
Note how some entries have things like "omap_hsmmc.0" and
"ick". By adding those your driver can request the clock
with clk_get(&pdev->dev, "ick").
Regards,
Tony
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-31 12:05 [PATCH] OMAP3 ROM Random Number Generator support Ивайло Димитров
2013-03-31 12:43 ` Pali Rohár
@ 2013-04-01 16:59 ` Tony Lindgren
2013-04-01 22:09 ` Aaro Koskinen
2 siblings, 0 replies; 17+ messages in thread
From: Tony Lindgren @ 2013-04-01 16:59 UTC (permalink / raw)
To: Ивайло Димитров
Cc: Pali Rohár, juha.yrjola, linux, mpm, herbert, linux-omap,
linux-kernel
* Ивайло Димитров <freemangordon@abv.bg> [130331 05:10]:
>
> Hi Pali,
>
> Yep, the code looks almost identical, I guess with some tweaks all SMC code from that patch could be removed and instead used the one from SMC PPA API.
>
> What I don't get, is why one needs to disable/enable fiqs/irqs:
>
> +static int call_sec_rom(u32 appl_id, u32 proc_id, u32 flag, ...)
> +{
> + va_list ap;
> + u32 ret;
> + u32 val;
> +
> + va_start(ap, flag);
> + val = *(u32 *) ≈
> + local_irq_disable();
> + local_fiq_disable();
> + ret = omap3_rom_rng_call(appl_id, proc_id, flag,
> + (u32) virt_to_phys((void *) val));
> + local_fiq_enable();
> + local_irq_enable();
> + va_end(ap);
> +
> + return ret;
> +}
>
> Do you have any idea why is that needed? Any other code I've ever seen to call SM, does not disable fiqs/irqs, is RNG SMC somehow special? I know this is Nokia's code, but still, if we can get some understanding...
Sounds like the fiq handling can be dropped based on what
the TI guys posted recently about FIQs only be available in
the secure mode starting with omap2.
Regards,
Tony
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
@ 2013-04-01 20:37 Ивайло Димитров
2013-04-02 16:17 ` Tony Lindgren
0 siblings, 1 reply; 17+ messages in thread
From: Ивайло Димитров @ 2013-04-01 20:37 UTC (permalink / raw)
To: Tony Lindgren
Cc: pali.rohar, juha.yrjola, linux, mpm, herbert, linux-omap,
linux-kernel
It could be that I am misreading something, but RX51 is OMAP3.
Regards,
Ivo
>-------- Оригинално писмо --------
>От: Tony Lindgren
>Относно: Re: [PATCH] OMAP3 ROM Random Number Generator support
>До: Ивайло Димитров
>Изпратено на: Понеделник, 2013, Април 1 19:59:50 EEST
>
>
>* Ивайло Димитров [130331 05:10]:
>>
>> Hi Pali,
>>
>> Yep, the code looks almost identical, I guess with some tweaks all SMC code from that patch could be removed and instead used the one from SMC PPA API.
>>
>> What I don't get, is why one needs to disable/enable fiqs/irqs:
>>
>> +static int call_sec_rom(u32 appl_id, u32 proc_id, u32 flag, ...)
>> +{
>> + va_list ap;
>> + u32 ret;
>> + u32 val;
>> +
>> + va_start(ap, flag);
>> + val = *(u32 *) &ap;
>> + local_irq_disable();
>> + local_fiq_disable();
>> + ret = omap3_rom_rng_call(appl_id, proc_id, flag,
>> + (u32) virt_to_phys((void *) val));
>> + local_fiq_enable();
>> + local_irq_enable();
>> + va_end(ap);
>> +
>> + return ret;
>> +}
>>
>> Do you have any idea why is that needed? Any other code I've ever seen to call SM, does not disable fiqs/irqs, is RNG SMC somehow special? I know this is Nokia's code, but still, if we can get some understanding...
>
>Sounds like the fiq handling can be dropped based on what
>the TI guys posted recently about FIQs only be available in
>the secure mode starting with omap2.
>
>Regards,
>
>Tony
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-03-31 12:05 [PATCH] OMAP3 ROM Random Number Generator support Ивайло Димитров
2013-03-31 12:43 ` Pali Rohár
2013-04-01 16:59 ` Tony Lindgren
@ 2013-04-01 22:09 ` Aaro Koskinen
2 siblings, 0 replies; 17+ messages in thread
From: Aaro Koskinen @ 2013-04-01 22:09 UTC (permalink / raw)
To: Ивайло Димитров
Cc: Pali Rohár, tony, juha.yrjola, linux, mpm, herbert,
linux-omap, linux-kernel
Hi,
On Sun, Mar 31, 2013 at 03:05:42PM +0300, Ивайло Димитров wrote:
> Yep, the code looks almost identical, I guess with some tweaks all SMC
> code from that patch could be removed and instead used the one from SMC
> PPA API.
>
> What I don't get, is why one needs to disable/enable fiqs/irqs:
[..]
> Do you have any idea why is that needed? Any other code I've ever seen
> to call SM, does not disable fiqs/irqs, is RNG SMC somehow special? I
> know this is Nokia's code, but still, if we can get some understanding...
I think without disabling irqs you may suffer some strange crashes when
heavily stressing the RNG... that's why you also have cache flushes before
and after the SMC. With proper test suite you could probably verify this.
How are you testing this driver?
A.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] OMAP3 ROM Random Number Generator support
2013-04-01 20:37 Ивайло Димитров
@ 2013-04-02 16:17 ` Tony Lindgren
0 siblings, 0 replies; 17+ messages in thread
From: Tony Lindgren @ 2013-04-02 16:17 UTC (permalink / raw)
To: Ивайло Димитров
Cc: pali.rohar, juha.yrjola, linux, mpm, herbert, linux-omap,
linux-kernel
* Ивайло Димитров <freemangordon@abv.bg> [130401 13:41]:
> It could be that I am misreading something, but RX51 is OMAP3.
Yes the FIQs are only accessible in the secure mode starting with
omap2. So that also means omap3, 4, 5.
Regards,
Tony
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2013-04-02 16:17 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-31 12:05 [PATCH] OMAP3 ROM Random Number Generator support Ивайло Димитров
2013-03-31 12:43 ` Pali Rohár
2013-04-01 16:59 ` Tony Lindgren
2013-04-01 22:09 ` Aaro Koskinen
-- strict thread matches above, loose matches on Subject: below --
2013-04-01 20:37 Ивайло Димитров
2013-04-02 16:17 ` Tony Lindgren
2013-02-28 18:05 Pali Rohár
2013-03-24 14:15 ` Pali Rohár
2013-03-27 21:09 ` Tony Lindgren
2013-03-27 22:03 ` Pali Rohár
2013-03-27 22:25 ` Tony Lindgren
2013-03-28 17:54 ` Pali Rohár
2013-03-28 21:44 ` Tony Lindgren
2013-03-31 9:28 ` Pali Rohár
2013-04-01 16:25 ` Tony Lindgren
2013-03-28 9:52 ` Russell King - ARM Linux
2013-03-28 17:24 ` Pali Rohár
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).