]> git.baikalelectronics.ru Git - kernel.git/commit
MIPS: Implement random_get_entropy with CP0 Random
authorMaciej W. Rozycki <macro@linux-mips.org>
Sun, 6 Apr 2014 20:31:29 +0000 (21:31 +0100)
committerRalf Baechle <ralf@linux-mips.org>
Fri, 30 May 2014 16:21:30 +0000 (18:21 +0200)
commit20c1906bd037ddb6b1a77aeea729d54afb3df1ee
treee9ace017ae9b79a8f2ad6c7f851f79ef97f1b4d1
parenta9851cae7bae9c3f96ea280b3f2f976fe5eb66d2
MIPS: Implement random_get_entropy with CP0 Random

Update to commit 4c091c924a8f18db26219b3cf335745547659522 [MIPS:
Reimplement get_cycles().]

On systems were for whatever reasons we can't use the cycle counter, fall
back to the c0_random register as an entropy source.  It has however a
very small range that makes it suitable for random_get_entropy only and
not get_cycles.

This optimised version compiles to 8 instructions in the fast path even in
the worst case of all the conditions to check being variable (including a
MFC0 move delay slot that is only required for very old processors):

     828: 8cf90000  lw t9,0(a3)
828: R_MIPS_LO16 jiffies
     82c: 40057800  mfc0 a1,c0_prid
     830: 3c0200ff  lui v0,0xff
     834: 00a21024  and v0,a1,v0
     838: 1040007d  beqz v0,a30 <add_interrupt_randomness+0x22c>
     83c: 3c030000  lui v1,0x0
83c: R_MIPS_HI16 cpu_data
     840: 40024800  mfc0 v0,c0_count
     844: 00000000  nop
     848: 00409021  move s2,v0
     84c: 8ce20000  lw v0,0(a3)
84c: R_MIPS_LO16 jiffies

On most targets the sequence will be shorter and on some it will reduce to
a single `MFC0 <reg>,c0_count', as all MIPS architecture (i.e. non-legacy
MIPS) processors require the CP0 Count register to be present.

The only known exception that reports MIPS architecture compliance, but
contrary to that lacks CP0 Count is the Ingenic JZ4740 thingy.  For broken
platforms like that this code requires cpu_has_counter to be hardcoded to
0 (i.e. no variable setting is permitted) so as not to penalise all the
other good platforms out there.

The asm barrier is required so that the compiler does not pull any
potentially costly (cold cache!) `cpu_data' variable access into the fast
path.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: John Crispin <blogic@openwrt.org>
Cc: Andrew McGregor <andrewmcgr@gmail.com>
Cc: Dave Taht <dave.taht@bufferbloat.net>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Simon Kelley <simon@thekelleys.org.uk>
Cc: Jim Gettys <jg@freedesktop.org>
Cc: David Daney <ddaney@caviumnetworks.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/6702/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/include/asm/timex.h
arch/mips/kernel/cpu-probe.c