Deleted Added
sdiff udiff text old ( 253845 ) new ( 254147 )
full compact
1/*-
2 * Copyright (c) 2013 David E. O'Brien <obrien@NUXI.org>
3 * Copyright (c) 2004 Mark R V Murray
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer

--- 11 unchanged lines hidden (view full) ---

22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/dev/random/nehemiah.c 254147 2013-08-09 15:31:50Z obrien $");
31
32#include <sys/param.h>
33#include <sys/time.h>
34#include <sys/lock.h>
35#include <sys/mutex.h>
36#include <sys/module.h>
37#include <sys/selinfo.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40
41#include <machine/pcb.h>
42#include <machine/md_var.h>
43#include <machine/specialreg.h>
44
45#include <dev/random/random_adaptors.h>
46#include <dev/random/randomdev.h>
47
48#define RANDOM_BLOCK_SIZE 256
49#define CIPHER_BLOCK_SIZE 16
50
51static void random_nehemiah_init(void);
52static void random_nehemiah_deinit(void);
53static int random_nehemiah_read(void *, int);
54
55struct random_adaptor random_nehemiah = {
56 .ident = "Hardware, VIA Nehemiah",
57 .init = random_nehemiah_init,
58 .deinit = random_nehemiah_deinit,
59 .read = random_nehemiah_read,
60 .write = (random_write_func_t *)random_null_func,
61 .reseed = (random_reseed_func_t *)random_null_func,
62 .seeded = 1,
63};

--- 141 unchanged lines hidden (view full) ---

205 c = MIN(RANDOM_BLOCK_SIZE, c);
206 memcpy(buf, out, (size_t)c);
207
208 fpu_kern_leave(curthread, fpu_ctx_save);
209 mtx_unlock(&random_nehemiah_mtx);
210 return (c);
211}
212
213static int
214nehemiah_modevent(module_t mod, int type, void *unused)
215{
216
217 switch (type) {
218 case MOD_LOAD:
219 if (via_feature_rng & VIA_HAS_RNG) {
220 random_adaptor_register("nehemiah", &random_nehemiah);
221 EVENTHANDLER_INVOKE(random_adaptor_attach,
222 &random_nehemiah);
223 return (0);
224 } else {
225#ifndef KLD_MODULE
226 if (bootverbose)
227#endif
228 printf(
229 "%s: VIA RNG feature is not present on this CPU\n",
230 random_nehemiah.ident);
231 return (0);
232 }
233 }
234
235 return (EINVAL);
236}
237
238RANDOM_ADAPTOR_MODULE(nehemiah, nehemiah_modevent, 1);