diff options
Diffstat (limited to 'drivers/char/hw_random')
-rw-r--r-- | drivers/char/hw_random/Kconfig | 14 | ||||
-rw-r--r-- | drivers/char/hw_random/Makefile | 1 | ||||
-rw-r--r-- | drivers/char/hw_random/amd-rng.c | 9 | ||||
-rw-r--r-- | drivers/char/hw_random/core.c | 2 | ||||
-rw-r--r-- | drivers/char/hw_random/n2-drv.c | 19 | ||||
-rw-r--r-- | drivers/char/hw_random/nomadik-rng.c | 2 | ||||
-rw-r--r-- | drivers/char/hw_random/omap-rng.c | 14 | ||||
-rw-r--r-- | drivers/char/hw_random/pasemi-rng.c | 9 | ||||
-rw-r--r-- | drivers/char/hw_random/picoxcell-rng.c | 208 | ||||
-rw-r--r-- | drivers/char/hw_random/via-rng.c | 10 |
10 files changed, 261 insertions, 27 deletions
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index d31483c54883..a60043b3e409 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig | |||
@@ -49,7 +49,7 @@ config HW_RANDOM_INTEL | |||
49 | 49 | ||
50 | config HW_RANDOM_AMD | 50 | config HW_RANDOM_AMD |
51 | tristate "AMD HW Random Number Generator support" | 51 | tristate "AMD HW Random Number Generator support" |
52 | depends on HW_RANDOM && X86 && PCI | 52 | depends on HW_RANDOM && (X86 || PPC_MAPLE) && PCI |
53 | default HW_RANDOM | 53 | default HW_RANDOM |
54 | ---help--- | 54 | ---help--- |
55 | This driver provides kernel-side support for the Random Number | 55 | This driver provides kernel-side support for the Random Number |
@@ -198,3 +198,15 @@ config HW_RANDOM_NOMADIK | |||
198 | module will be called nomadik-rng. | 198 | module will be called nomadik-rng. |
199 | 199 | ||
200 | If unsure, say Y. | 200 | If unsure, say Y. |
201 | |||
202 | config HW_RANDOM_PICOXCELL | ||
203 | tristate "Picochip picoXcell true random number generator support" | ||
204 | depends on HW_RANDOM && ARCH_PICOXCELL && PICOXCELL_PC3X3 | ||
205 | ---help--- | ||
206 | This driver provides kernel-side support for the Random Number | ||
207 | Generator hardware found on Picochip PC3x3 and later devices. | ||
208 | |||
209 | To compile this driver as a module, choose M here: the | ||
210 | module will be called picoxcell-rng. | ||
211 | |||
212 | If unsure, say Y. | ||
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile index 4273308aa1e3..3db4eb8b19c0 100644 --- a/drivers/char/hw_random/Makefile +++ b/drivers/char/hw_random/Makefile | |||
@@ -19,3 +19,4 @@ obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o | |||
19 | obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o | 19 | obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o |
20 | obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o | 20 | obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o |
21 | obj-$(CONFIG_HW_RANDOM_NOMADIK) += nomadik-rng.o | 21 | obj-$(CONFIG_HW_RANDOM_NOMADIK) += nomadik-rng.o |
22 | obj-$(CONFIG_HW_RANDOM_PICOXCELL) += picoxcell-rng.o | ||
diff --git a/drivers/char/hw_random/amd-rng.c b/drivers/char/hw_random/amd-rng.c index 0d8c5788b8e4..c6af038682f1 100644 --- a/drivers/char/hw_random/amd-rng.c +++ b/drivers/char/hw_random/amd-rng.c | |||
@@ -133,6 +133,12 @@ found: | |||
133 | pmbase &= 0x0000FF00; | 133 | pmbase &= 0x0000FF00; |
134 | if (pmbase == 0) | 134 | if (pmbase == 0) |
135 | goto out; | 135 | goto out; |
136 | if (!request_region(pmbase + 0xF0, 8, "AMD HWRNG")) { | ||
137 | dev_err(&pdev->dev, "AMD HWRNG region 0x%x already in use!\n", | ||
138 | pmbase + 0xF0); | ||
139 | err = -EBUSY; | ||
140 | goto out; | ||
141 | } | ||
136 | amd_rng.priv = (unsigned long)pmbase; | 142 | amd_rng.priv = (unsigned long)pmbase; |
137 | amd_pdev = pdev; | 143 | amd_pdev = pdev; |
138 | 144 | ||
@@ -141,6 +147,7 @@ found: | |||
141 | if (err) { | 147 | if (err) { |
142 | printk(KERN_ERR PFX "RNG registering failed (%d)\n", | 148 | printk(KERN_ERR PFX "RNG registering failed (%d)\n", |
143 | err); | 149 | err); |
150 | release_region(pmbase + 0xF0, 8); | ||
144 | goto out; | 151 | goto out; |
145 | } | 152 | } |
146 | out: | 153 | out: |
@@ -149,6 +156,8 @@ out: | |||
149 | 156 | ||
150 | static void __exit mod_exit(void) | 157 | static void __exit mod_exit(void) |
151 | { | 158 | { |
159 | u32 pmbase = (unsigned long)amd_rng.priv; | ||
160 | release_region(pmbase + 0xF0, 8); | ||
152 | hwrng_unregister(&amd_rng); | 161 | hwrng_unregister(&amd_rng); |
153 | } | 162 | } |
154 | 163 | ||
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index 3d9c61e5acbf..2016aad85203 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c | |||
@@ -37,7 +37,6 @@ | |||
37 | #include <linux/kernel.h> | 37 | #include <linux/kernel.h> |
38 | #include <linux/fs.h> | 38 | #include <linux/fs.h> |
39 | #include <linux/sched.h> | 39 | #include <linux/sched.h> |
40 | #include <linux/smp_lock.h> | ||
41 | #include <linux/init.h> | 40 | #include <linux/init.h> |
42 | #include <linux/miscdevice.h> | 41 | #include <linux/miscdevice.h> |
43 | #include <linux/delay.h> | 42 | #include <linux/delay.h> |
@@ -170,6 +169,7 @@ static const struct file_operations rng_chrdev_ops = { | |||
170 | .owner = THIS_MODULE, | 169 | .owner = THIS_MODULE, |
171 | .open = rng_dev_open, | 170 | .open = rng_dev_open, |
172 | .read = rng_dev_read, | 171 | .read = rng_dev_read, |
172 | .llseek = noop_llseek, | ||
173 | }; | 173 | }; |
174 | 174 | ||
175 | static struct miscdevice rng_miscdev = { | 175 | static struct miscdevice rng_miscdev = { |
diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index a3f5e381e746..ac6739e085e3 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c | |||
@@ -619,15 +619,20 @@ static void __devinit n2rng_driver_version(void) | |||
619 | pr_info("%s", version); | 619 | pr_info("%s", version); |
620 | } | 620 | } |
621 | 621 | ||
622 | static int __devinit n2rng_probe(struct platform_device *op, | 622 | static const struct of_device_id n2rng_match[]; |
623 | const struct of_device_id *match) | 623 | static int __devinit n2rng_probe(struct platform_device *op) |
624 | { | 624 | { |
625 | int victoria_falls = (match->data != NULL); | 625 | const struct of_device_id *match; |
626 | int victoria_falls; | ||
626 | int err = -ENOMEM; | 627 | int err = -ENOMEM; |
627 | struct n2rng *np; | 628 | struct n2rng *np; |
628 | 629 | ||
629 | n2rng_driver_version(); | 630 | match = of_match_device(n2rng_match, &op->dev); |
631 | if (!match) | ||
632 | return -EINVAL; | ||
633 | victoria_falls = (match->data != NULL); | ||
630 | 634 | ||
635 | n2rng_driver_version(); | ||
631 | np = kzalloc(sizeof(*np), GFP_KERNEL); | 636 | np = kzalloc(sizeof(*np), GFP_KERNEL); |
632 | if (!np) | 637 | if (!np) |
633 | goto out; | 638 | goto out; |
@@ -750,7 +755,7 @@ static const struct of_device_id n2rng_match[] = { | |||
750 | }; | 755 | }; |
751 | MODULE_DEVICE_TABLE(of, n2rng_match); | 756 | MODULE_DEVICE_TABLE(of, n2rng_match); |
752 | 757 | ||
753 | static struct of_platform_driver n2rng_driver = { | 758 | static struct platform_driver n2rng_driver = { |
754 | .driver = { | 759 | .driver = { |
755 | .name = "n2rng", | 760 | .name = "n2rng", |
756 | .owner = THIS_MODULE, | 761 | .owner = THIS_MODULE, |
@@ -762,12 +767,12 @@ static struct of_platform_driver n2rng_driver = { | |||
762 | 767 | ||
763 | static int __init n2rng_init(void) | 768 | static int __init n2rng_init(void) |
764 | { | 769 | { |
765 | return of_register_platform_driver(&n2rng_driver); | 770 | return platform_driver_register(&n2rng_driver); |
766 | } | 771 | } |
767 | 772 | ||
768 | static void __exit n2rng_exit(void) | 773 | static void __exit n2rng_exit(void) |
769 | { | 774 | { |
770 | of_unregister_platform_driver(&n2rng_driver); | 775 | platform_driver_unregister(&n2rng_driver); |
771 | } | 776 | } |
772 | 777 | ||
773 | module_init(n2rng_init); | 778 | module_init(n2rng_init); |
diff --git a/drivers/char/hw_random/nomadik-rng.c b/drivers/char/hw_random/nomadik-rng.c index a348c7e9aa0b..dd1d143eb8ea 100644 --- a/drivers/char/hw_random/nomadik-rng.c +++ b/drivers/char/hw_random/nomadik-rng.c | |||
@@ -39,7 +39,7 @@ static struct hwrng nmk_rng = { | |||
39 | .read = nmk_rng_read, | 39 | .read = nmk_rng_read, |
40 | }; | 40 | }; |
41 | 41 | ||
42 | static int nmk_rng_probe(struct amba_device *dev, struct amba_id *id) | 42 | static int nmk_rng_probe(struct amba_device *dev, const struct amba_id *id) |
43 | { | 43 | { |
44 | void __iomem *base; | 44 | void __iomem *base; |
45 | int ret; | 45 | int ret; |
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c index 06aad0831c73..2cc755a64302 100644 --- a/drivers/char/hw_random/omap-rng.c +++ b/drivers/char/hw_random/omap-rng.c | |||
@@ -91,7 +91,7 @@ static struct hwrng omap_rng_ops = { | |||
91 | 91 | ||
92 | static int __devinit omap_rng_probe(struct platform_device *pdev) | 92 | static int __devinit omap_rng_probe(struct platform_device *pdev) |
93 | { | 93 | { |
94 | struct resource *res, *mem; | 94 | struct resource *res; |
95 | int ret; | 95 | int ret; |
96 | 96 | ||
97 | /* | 97 | /* |
@@ -116,14 +116,12 @@ static int __devinit omap_rng_probe(struct platform_device *pdev) | |||
116 | if (!res) | 116 | if (!res) |
117 | return -ENOENT; | 117 | return -ENOENT; |
118 | 118 | ||
119 | mem = request_mem_region(res->start, resource_size(res), | 119 | if (!request_mem_region(res->start, resource_size(res), pdev->name)) { |
120 | pdev->name); | ||
121 | if (mem == NULL) { | ||
122 | ret = -EBUSY; | 120 | ret = -EBUSY; |
123 | goto err_region; | 121 | goto err_region; |
124 | } | 122 | } |
125 | 123 | ||
126 | dev_set_drvdata(&pdev->dev, mem); | 124 | dev_set_drvdata(&pdev->dev, res); |
127 | rng_base = ioremap(res->start, resource_size(res)); | 125 | rng_base = ioremap(res->start, resource_size(res)); |
128 | if (!rng_base) { | 126 | if (!rng_base) { |
129 | ret = -ENOMEM; | 127 | ret = -ENOMEM; |
@@ -146,7 +144,7 @@ err_register: | |||
146 | iounmap(rng_base); | 144 | iounmap(rng_base); |
147 | rng_base = NULL; | 145 | rng_base = NULL; |
148 | err_ioremap: | 146 | err_ioremap: |
149 | release_resource(mem); | 147 | release_mem_region(res->start, resource_size(res)); |
150 | err_region: | 148 | err_region: |
151 | if (cpu_is_omap24xx()) { | 149 | if (cpu_is_omap24xx()) { |
152 | clk_disable(rng_ick); | 150 | clk_disable(rng_ick); |
@@ -157,7 +155,7 @@ err_region: | |||
157 | 155 | ||
158 | static int __exit omap_rng_remove(struct platform_device *pdev) | 156 | static int __exit omap_rng_remove(struct platform_device *pdev) |
159 | { | 157 | { |
160 | struct resource *mem = dev_get_drvdata(&pdev->dev); | 158 | struct resource *res = dev_get_drvdata(&pdev->dev); |
161 | 159 | ||
162 | hwrng_unregister(&omap_rng_ops); | 160 | hwrng_unregister(&omap_rng_ops); |
163 | 161 | ||
@@ -170,7 +168,7 @@ static int __exit omap_rng_remove(struct platform_device *pdev) | |||
170 | clk_put(rng_ick); | 168 | clk_put(rng_ick); |
171 | } | 169 | } |
172 | 170 | ||
173 | release_resource(mem); | 171 | release_mem_region(res->start, resource_size(res)); |
174 | rng_base = NULL; | 172 | rng_base = NULL; |
175 | 173 | ||
176 | return 0; | 174 | return 0; |
diff --git a/drivers/char/hw_random/pasemi-rng.c b/drivers/char/hw_random/pasemi-rng.c index a31c830ca8cd..1d504815e6db 100644 --- a/drivers/char/hw_random/pasemi-rng.c +++ b/drivers/char/hw_random/pasemi-rng.c | |||
@@ -94,8 +94,7 @@ static struct hwrng pasemi_rng = { | |||
94 | .data_read = pasemi_rng_data_read, | 94 | .data_read = pasemi_rng_data_read, |
95 | }; | 95 | }; |
96 | 96 | ||
97 | static int __devinit rng_probe(struct platform_device *ofdev, | 97 | static int __devinit rng_probe(struct platform_device *ofdev) |
98 | const struct of_device_id *match) | ||
99 | { | 98 | { |
100 | void __iomem *rng_regs; | 99 | void __iomem *rng_regs; |
101 | struct device_node *rng_np = ofdev->dev.of_node; | 100 | struct device_node *rng_np = ofdev->dev.of_node; |
@@ -139,7 +138,7 @@ static struct of_device_id rng_match[] = { | |||
139 | { }, | 138 | { }, |
140 | }; | 139 | }; |
141 | 140 | ||
142 | static struct of_platform_driver rng_driver = { | 141 | static struct platform_driver rng_driver = { |
143 | .driver = { | 142 | .driver = { |
144 | .name = "pasemi-rng", | 143 | .name = "pasemi-rng", |
145 | .owner = THIS_MODULE, | 144 | .owner = THIS_MODULE, |
@@ -151,13 +150,13 @@ static struct of_platform_driver rng_driver = { | |||
151 | 150 | ||
152 | static int __init rng_init(void) | 151 | static int __init rng_init(void) |
153 | { | 152 | { |
154 | return of_register_platform_driver(&rng_driver); | 153 | return platform_driver_register(&rng_driver); |
155 | } | 154 | } |
156 | module_init(rng_init); | 155 | module_init(rng_init); |
157 | 156 | ||
158 | static void __exit rng_exit(void) | 157 | static void __exit rng_exit(void) |
159 | { | 158 | { |
160 | of_unregister_platform_driver(&rng_driver); | 159 | platform_driver_unregister(&rng_driver); |
161 | } | 160 | } |
162 | module_exit(rng_exit); | 161 | module_exit(rng_exit); |
163 | 162 | ||
diff --git a/drivers/char/hw_random/picoxcell-rng.c b/drivers/char/hw_random/picoxcell-rng.c new file mode 100644 index 000000000000..990d55a5e3e8 --- /dev/null +++ b/drivers/char/hw_random/picoxcell-rng.c | |||
@@ -0,0 +1,208 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010-2011 Picochip Ltd., Jamie Iles | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | * | ||
8 | * All enquiries to support@picochip.com | ||
9 | */ | ||
10 | #include <linux/clk.h> | ||
11 | #include <linux/delay.h> | ||
12 | #include <linux/err.h> | ||
13 | #include <linux/hw_random.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | |||
19 | #define DATA_REG_OFFSET 0x0200 | ||
20 | #define CSR_REG_OFFSET 0x0278 | ||
21 | #define CSR_OUT_EMPTY_MASK (1 << 24) | ||
22 | #define CSR_FAULT_MASK (1 << 1) | ||
23 | #define TRNG_BLOCK_RESET_MASK (1 << 0) | ||
24 | #define TAI_REG_OFFSET 0x0380 | ||
25 | |||
26 | /* | ||
27 | * The maximum amount of time in microseconds to spend waiting for data if the | ||
28 | * core wants us to wait. The TRNG should generate 32 bits every 320ns so a | ||
29 | * timeout of 20us seems reasonable. The TRNG does builtin tests of the data | ||
30 | * for randomness so we can't always assume there is data present. | ||
31 | */ | ||
32 | #define PICO_TRNG_TIMEOUT 20 | ||
33 | |||
34 | static void __iomem *rng_base; | ||
35 | static struct clk *rng_clk; | ||
36 | struct device *rng_dev; | ||
37 | |||
38 | static inline u32 picoxcell_trng_read_csr(void) | ||
39 | { | ||
40 | return __raw_readl(rng_base + CSR_REG_OFFSET); | ||
41 | } | ||
42 | |||
43 | static inline bool picoxcell_trng_is_empty(void) | ||
44 | { | ||
45 | return picoxcell_trng_read_csr() & CSR_OUT_EMPTY_MASK; | ||
46 | } | ||
47 | |||
48 | /* | ||
49 | * Take the random number generator out of reset and make sure the interrupts | ||
50 | * are masked. We shouldn't need to get large amounts of random bytes so just | ||
51 | * poll the status register. The hardware generates 32 bits every 320ns so we | ||
52 | * shouldn't have to wait long enough to warrant waiting for an IRQ. | ||
53 | */ | ||
54 | static void picoxcell_trng_start(void) | ||
55 | { | ||
56 | __raw_writel(0, rng_base + TAI_REG_OFFSET); | ||
57 | __raw_writel(0, rng_base + CSR_REG_OFFSET); | ||
58 | } | ||
59 | |||
60 | static void picoxcell_trng_reset(void) | ||
61 | { | ||
62 | __raw_writel(TRNG_BLOCK_RESET_MASK, rng_base + CSR_REG_OFFSET); | ||
63 | __raw_writel(TRNG_BLOCK_RESET_MASK, rng_base + TAI_REG_OFFSET); | ||
64 | picoxcell_trng_start(); | ||
65 | } | ||
66 | |||
67 | /* | ||
68 | * Get some random data from the random number generator. The hw_random core | ||
69 | * layer provides us with locking. | ||
70 | */ | ||
71 | static int picoxcell_trng_read(struct hwrng *rng, void *buf, size_t max, | ||
72 | bool wait) | ||
73 | { | ||
74 | int i; | ||
75 | |||
76 | /* Wait for some data to become available. */ | ||
77 | for (i = 0; i < PICO_TRNG_TIMEOUT && picoxcell_trng_is_empty(); ++i) { | ||
78 | if (!wait) | ||
79 | return 0; | ||
80 | |||
81 | udelay(1); | ||
82 | } | ||
83 | |||
84 | if (picoxcell_trng_read_csr() & CSR_FAULT_MASK) { | ||
85 | dev_err(rng_dev, "fault detected, resetting TRNG\n"); | ||
86 | picoxcell_trng_reset(); | ||
87 | return -EIO; | ||
88 | } | ||
89 | |||
90 | if (i == PICO_TRNG_TIMEOUT) | ||
91 | return 0; | ||
92 | |||
93 | *(u32 *)buf = __raw_readl(rng_base + DATA_REG_OFFSET); | ||
94 | return sizeof(u32); | ||
95 | } | ||
96 | |||
97 | static struct hwrng picoxcell_trng = { | ||
98 | .name = "picoxcell", | ||
99 | .read = picoxcell_trng_read, | ||
100 | }; | ||
101 | |||
102 | static int picoxcell_trng_probe(struct platform_device *pdev) | ||
103 | { | ||
104 | int ret; | ||
105 | struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
106 | |||
107 | if (!mem) { | ||
108 | dev_warn(&pdev->dev, "no memory resource\n"); | ||
109 | return -ENOMEM; | ||
110 | } | ||
111 | |||
112 | if (!devm_request_mem_region(&pdev->dev, mem->start, resource_size(mem), | ||
113 | "picoxcell_trng")) { | ||
114 | dev_warn(&pdev->dev, "unable to request io mem\n"); | ||
115 | return -EBUSY; | ||
116 | } | ||
117 | |||
118 | rng_base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); | ||
119 | if (!rng_base) { | ||
120 | dev_warn(&pdev->dev, "unable to remap io mem\n"); | ||
121 | return -ENOMEM; | ||
122 | } | ||
123 | |||
124 | rng_clk = clk_get(&pdev->dev, NULL); | ||
125 | if (IS_ERR(rng_clk)) { | ||
126 | dev_warn(&pdev->dev, "no clk\n"); | ||
127 | return PTR_ERR(rng_clk); | ||
128 | } | ||
129 | |||
130 | ret = clk_enable(rng_clk); | ||
131 | if (ret) { | ||
132 | dev_warn(&pdev->dev, "unable to enable clk\n"); | ||
133 | goto err_enable; | ||
134 | } | ||
135 | |||
136 | picoxcell_trng_start(); | ||
137 | ret = hwrng_register(&picoxcell_trng); | ||
138 | if (ret) | ||
139 | goto err_register; | ||
140 | |||
141 | rng_dev = &pdev->dev; | ||
142 | dev_info(&pdev->dev, "pixoxcell random number generator active\n"); | ||
143 | |||
144 | return 0; | ||
145 | |||
146 | err_register: | ||
147 | clk_disable(rng_clk); | ||
148 | err_enable: | ||
149 | clk_put(rng_clk); | ||
150 | |||
151 | return ret; | ||
152 | } | ||
153 | |||
154 | static int __devexit picoxcell_trng_remove(struct platform_device *pdev) | ||
155 | { | ||
156 | hwrng_unregister(&picoxcell_trng); | ||
157 | clk_disable(rng_clk); | ||
158 | clk_put(rng_clk); | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | #ifdef CONFIG_PM | ||
164 | static int picoxcell_trng_suspend(struct device *dev) | ||
165 | { | ||
166 | clk_disable(rng_clk); | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | static int picoxcell_trng_resume(struct device *dev) | ||
172 | { | ||
173 | return clk_enable(rng_clk); | ||
174 | } | ||
175 | |||
176 | static const struct dev_pm_ops picoxcell_trng_pm_ops = { | ||
177 | .suspend = picoxcell_trng_suspend, | ||
178 | .resume = picoxcell_trng_resume, | ||
179 | }; | ||
180 | #endif /* CONFIG_PM */ | ||
181 | |||
182 | static struct platform_driver picoxcell_trng_driver = { | ||
183 | .probe = picoxcell_trng_probe, | ||
184 | .remove = __devexit_p(picoxcell_trng_remove), | ||
185 | .driver = { | ||
186 | .name = "picoxcell-trng", | ||
187 | .owner = THIS_MODULE, | ||
188 | #ifdef CONFIG_PM | ||
189 | .pm = &picoxcell_trng_pm_ops, | ||
190 | #endif /* CONFIG_PM */ | ||
191 | }, | ||
192 | }; | ||
193 | |||
194 | static int __init picoxcell_trng_init(void) | ||
195 | { | ||
196 | return platform_driver_register(&picoxcell_trng_driver); | ||
197 | } | ||
198 | module_init(picoxcell_trng_init); | ||
199 | |||
200 | static void __exit picoxcell_trng_exit(void) | ||
201 | { | ||
202 | platform_driver_unregister(&picoxcell_trng_driver); | ||
203 | } | ||
204 | module_exit(picoxcell_trng_exit); | ||
205 | |||
206 | MODULE_LICENSE("GPL"); | ||
207 | MODULE_AUTHOR("Jamie Iles"); | ||
208 | MODULE_DESCRIPTION("Picochip picoXcell TRNG driver"); | ||
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c index 794aacb715c1..d0387a84eec1 100644 --- a/drivers/char/hw_random/via-rng.c +++ b/drivers/char/hw_random/via-rng.c | |||
@@ -24,6 +24,7 @@ | |||
24 | * warranty of any kind, whether express or implied. | 24 | * warranty of any kind, whether express or implied. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include <crypto/padlock.h> | ||
27 | #include <linux/module.h> | 28 | #include <linux/module.h> |
28 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
29 | #include <linux/hw_random.h> | 30 | #include <linux/hw_random.h> |
@@ -34,7 +35,6 @@ | |||
34 | #include <asm/i387.h> | 35 | #include <asm/i387.h> |
35 | 36 | ||
36 | 37 | ||
37 | #define PFX KBUILD_MODNAME ": " | ||
38 | 38 | ||
39 | 39 | ||
40 | enum { | 40 | enum { |
@@ -81,8 +81,7 @@ static inline u32 xstore(u32 *addr, u32 edx_in) | |||
81 | ts_state = irq_ts_save(); | 81 | ts_state = irq_ts_save(); |
82 | 82 | ||
83 | asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */" | 83 | asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */" |
84 | :"=m"(*addr), "=a"(eax_out) | 84 | : "=m" (*addr), "=a" (eax_out), "+d" (edx_in), "+D" (addr)); |
85 | :"D"(addr), "d"(edx_in)); | ||
86 | 85 | ||
87 | irq_ts_restore(ts_state); | 86 | irq_ts_restore(ts_state); |
88 | return eax_out; | 87 | return eax_out; |
@@ -90,8 +89,10 @@ static inline u32 xstore(u32 *addr, u32 edx_in) | |||
90 | 89 | ||
91 | static int via_rng_data_present(struct hwrng *rng, int wait) | 90 | static int via_rng_data_present(struct hwrng *rng, int wait) |
92 | { | 91 | { |
92 | char buf[16 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__ | ||
93 | ((aligned(STACK_ALIGN))); | ||
94 | u32 *via_rng_datum = (u32 *)PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT); | ||
93 | u32 bytes_out; | 95 | u32 bytes_out; |
94 | u32 *via_rng_datum = (u32 *)(&rng->priv); | ||
95 | int i; | 96 | int i; |
96 | 97 | ||
97 | /* We choose the recommended 1-byte-per-instruction RNG rate, | 98 | /* We choose the recommended 1-byte-per-instruction RNG rate, |
@@ -115,6 +116,7 @@ static int via_rng_data_present(struct hwrng *rng, int wait) | |||
115 | break; | 116 | break; |
116 | udelay(10); | 117 | udelay(10); |
117 | } | 118 | } |
119 | rng->priv = *via_rng_datum; | ||
118 | return bytes_out ? 1 : 0; | 120 | return bytes_out ? 1 : 0; |
119 | } | 121 | } |
120 | 122 | ||