2011-08-01 05:02:19 +08:00
|
|
|
/*
|
|
|
|
* This file is part of the Linux kernel.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011, Intel Corporation
|
|
|
|
* Authors: Fenghua Yu <fenghua.yu@intel.com>,
|
|
|
|
* H. Peter Anvin <hpa@linux.intel.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/archrandom.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
|
|
|
|
static int __init x86_rdrand_setup(char *s)
|
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_RDRAND);
|
2014-05-12 11:25:20 +08:00
|
|
|
setup_clear_cpu_cap(X86_FEATURE_RDSEED);
|
2011-08-01 05:02:19 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("nordrand", x86_rdrand_setup);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force a reseed cycle; we are architecturally guaranteed a reseed
|
|
|
|
* after no more than 512 128-bit chunks of random data. This also
|
|
|
|
* acts as a test of the CPU capability.
|
|
|
|
*/
|
|
|
|
#define RESEED_LOOP ((512*128)/sizeof(unsigned long))
|
|
|
|
|
x86: delete __cpuinit usage from all x86 files
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
are flagged as __cpuinit -- so if we remove the __cpuinit from
arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
content into no-ops as early as possible, since that will get rid
of these warnings. In any case, they are temporary and harmless.
This removes all the arch/x86 uses of the __cpuinit macros from
all C files. x86 only had the one __CPUINIT used in assembly files,
and it wasn't paired off with a .previous or a __FINIT, so we can
delete it directly w/o any corresponding additional change there.
[1] https://lkml.org/lkml/2013/5/20/589
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: H. Peter Anvin <hpa@linux.intel.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2013-06-19 06:23:59 +08:00
|
|
|
void x86_init_rdrand(struct cpuinfo_x86 *c)
|
2011-08-01 05:02:19 +08:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_ARCH_RANDOM
|
|
|
|
unsigned long tmp;
|
|
|
|
int i, count, ok;
|
|
|
|
|
|
|
|
if (!cpu_has(c, X86_FEATURE_RDRAND))
|
|
|
|
return; /* Nothing to do */
|
|
|
|
|
|
|
|
for (count = i = 0; i < RESEED_LOOP; i++) {
|
|
|
|
ok = rdrand_long(&tmp);
|
|
|
|
if (ok)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count != RESEED_LOOP)
|
|
|
|
clear_cpu_cap(c, X86_FEATURE_RDRAND);
|
|
|
|
#endif
|
|
|
|
}
|