nehemiah.c revision 128059
1/*-
2 * Copyright (c) 2004 Mark R V Murray
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer
10 *    in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/dev/random/nehemiah.c 128059 2004-04-09 15:47:10Z markm $");
30
31#include <sys/types.h>
32#include <sys/time.h>
33#include <sys/lock.h>
34#include <sys/mutex.h>
35#include <sys/selinfo.h>
36
37#include <dev/random/randomdev.h>
38
39static int random_nehemiah_read(void *, int);
40
41struct random_systat random_nehemiah = {
42	.ident = "Hardware, VIA Nehemiah",
43	.init = (random_init_func_t *)random_null_func,
44	.deinit = (random_deinit_func_t *)random_null_func,
45	.read = random_nehemiah_read,
46	.write = (random_write_func_t *)random_null_func,
47	.reseed = (random_reseed_func_t *)random_null_func,
48	.seeded = 1,
49};
50
51/* ARGSUSED */
52static int
53random_nehemiah_read(void *buf, int c)
54{
55#if (defined(__GNUC__) || defined(__INTEL_COMPILER)) && defined(__i386__)
56	int count = c;
57	int rate = 0;
58
59	/* VIA C3 Nehemiah "rep; xstore" */
60	__asm __volatile("rep; .byte 0x0f, 0xa7, 0xc0"
61				: "+D" (buf), "+c" (count), "=d" (rate)
62				:
63				: "memory");
64#endif
65	return (c);
66}
67