timer iomem hwrng driver
Subsystems (5)
Alexander Clouter
maintainerRFC PATCH 1/1 timer iomem hwrng driver
Hi,
I've noticed that the HW RNG core is orphaned so I'm posted this here...
I have been putting together some patches[1] for mainline support for the Technologic Systems TS-7800 which also includes a HW RNG generator; 32 bits of entropy a second is not great but hell if it's there, why not use it?
So I started slapping a driver together and realised it might be handy to generalise the driver a bit as in the case of the TS-7800 you just yank data once a second from a memory address and that's it; I imagine there are other boards out there that provision this kind of thing too. Nosing around in drivers/char/hw_random I noticed that ixp4xx-rng.c could trivially be replaced with my driver too.
So what's the consensus? The only possibly 'offencive' bit I can think of is that the ioremap'ing is done in the platform code. After a lot of head scratched I managed to get it to use a timer queue so hopefully it's rather lightweight; saving me the stack of 64bit calculations on an ARM chip I had before I got it using the timer queue.
Comments, flames, suggestions for improvement all welcomed.
Cheers
Alex
P.S. I'm not subscribed to LKML so please CC me in on your replies, the FAQ
said this was not a 'faux par'...
[1] http://marc.info/?l=linux-arm-kernel&m=121280018602505&w=2
Signature · 10 lines
________________________________________
/ You may be marching to the beat of a \
| different drummer, but you're still in |
\ the parade. /
----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||arch/arm/mach-orion5x/ts78xx-setup.c +27 -0
@@ -15,6 +15,7 @@#include <linux/mv643xx_eth.h> #include <linux/ata_platform.h> #include <linux/m48t86.h> +#include <linux/timeriomem-rng.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> #include <asm/mach/map.h>
@@ -37,6 +38,8 @@#define TS78XX_FPGA_REGS_SYSCON_LCDI (TS78XX_FPGA_REGS_VIRT_BASE | 0x004)#define TS78XX_FPGA_REGS_SYSCON_LCDO (TS78XX_FPGA_REGS_VIRT_BASE | 0x008) +#define TS78XX_FPGA_REGS_SYSCON_RNG (TS78XX_FPGA_REGS_VIRT_BASE | 0x044) +#define TS78XX_FPGA_REGS_RTC_CTRL (TS78XX_FPGA_REGS_VIRT_BASE | 0x808)#define TS78XX_FPGA_REGS_RTC_DATA (TS78XX_FPGA_REGS_VIRT_BASE | 0x80c)
@@ -108,6 +111,27 @@ static struct mv643xx_eth_platform_data ts78xx_eth_data = { };/***************************************************************************** +* RNG +****************************************************************************/ +#ifdef CONFIG_HW_RANDOM_TIMERIOMEM +static struct timeriomem_rng_data ts78xx_rng_data = { + .address = (u32 *__iomem )TS78XX_FPGA_REGS_SYSCON_RNG , + .width =32 , + .mask =0 , + .period =1000000 , +}; + +static struct platform_device ts78xx_rng_device = { + .name ="timeriomem_rng" , + .id =-1 , + .dev = { + .platform_data = &ts78xx_rng_data, + }, + .num_resources =0 , +}; +#endif + +/***************************************************************************** * RTC M48T86 - nicked^Wborrowed from arch/arm/mach-ep93xx/ts72xx.c ****************************************************************************/ #ifdef CONFIG_RTC_DRV_M48T86
@@ -258,6 +282,9 @@ static void __init ts78xx_init(void)if (!ts78xx_rtc_init ())printk (KERN_INFO "TS-78xx RTC not detected or enabled\n" ); +#ifdef CONFIG_HW_RANDOM_TIMERIOMEM +platform_device_register (&ts78xx_rng_device); +#endif }MACHINE_START (TS78XX ,"Technologic Systems TS-78xx SBC" )
drivers/char/hw_random/Kconfig +13 -0
@@ -20,6 +20,19 @@ config HW_RANDOM If unsure, say Y. +config HW_RANDOM_TIMERIOMEM + tristate "Timer IOMEM HW Random Number Generator support" + depends on HW_RANDOM + ---help--- + This driver provides kernel-side support for a generic Random + Number Generator provisioned by hardware through a dumb iomem + address; for example the TS-7800 is such a device. + + To compile this driver as a module, choose M here: the + module will be called timeriomem-rng. + + If unsure, say Y. + config HW_RANDOM_INTEL tristate "Intel HW Random Number Generator support" depends on HW_RANDOM && (X86 || IA64) && PCI
drivers/char/hw_random/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_HW_RANDOM) += rng-core.o rng-core-y := core.o +obj-$(CONFIG_HW_RANDOM_TIMERIOMEM) += timeriomem-rng.o obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o
drivers/char/hw_random/timeriomem-rng.c new file +152 -0
152 lines not on this page · raw message
include/linux/timeriomem-rng.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* linux/include/linux/timeriomem-rng.h +* +* Copyright (c) 2008 Alexander Clouter <[email protected]> +* +* 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. +*/ + +struct timeriomem_rng_data { +u32 __iomem *address; + +/* width in bits */ +unsigned int width; +/* if non-zero the mask to apply to get the bits we want */ +unsigned int mask; + +/* measures in usecs */ +unsigned int period; +};