m68k: Add infrastructure for machine-specific get_cycles()
Geert Uytterhoeven
maintainerPATCH 1/2 m68k: Add infrastructure for machine-specific get_cycles()
Currently get_cycles() always returns zero. As get_cycles() is called to add entropy to the random number generator pool, security can be increased by adding a hook where platforms can provide their own implementation.
--- arch/m68k/include/asm/machdep.h | 1 + arch/m68k/include/asm/timex.h | 5 +---- arch/m68k/kernel/time.c | 13 +++++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-)
arch/m68k/include/asm/machdep.h +1 -0
@@ -22,6 +22,7 @@ extern unsigned int (*mach_get_ss)(void);extern int (*mach_get_rtc_pll)(struct rtc_pll_info *);extern int (*mach_set_rtc_pll)(struct rtc_pll_info *);extern int (*mach_set_clock_mmss)(unsigned long ); +extern cycles_t (*mach_get_cycles)(void );extern void (*mach_reset)(void );extern void (*mach_halt)(void );extern void (*mach_power_off)(void );
arch/m68k/include/asm/timex.h +1 -4
@@ -23,9 +23,6 @@typedef unsigned long cycles_t ; -static inline cycles_t get_cycles (void ) -{ -return 0 ; -} +extern cycles_t get_cycles (void );#endif
arch/m68k/kernel/time.c +13 -0
@@ -28,6 +28,19 @@#include <linux/timex.h> #include <linux/profile.h> + +cycles_t (*mach_get_cycles)(void); + +cycles_t get_cycles (void ) +{ +if (mach_get_cycles) +return mach_get_cycles (); + +return 0 ; +} +EXPORT_SYMBOL (get_cycles); + +/* * timer_interrupt() needs to keep up the real-time clock, * as well as call the "xtime_update()" routine every clocktick
Signature · 1 line
1.7.9.5
Geert Uytterhoeven
maintainerPATCH 2/2 m68k/amiga: Provide mach_get_cycles()
Use the 24-bit Time-Of-Day clock in CIA B, which is clocked by HSYNC.
---
1. Completely untested! It does compile ;-)
2. Is a 24-bit counter running at 15-31 kHz good enough?
Two cascaded 16-bit CIA timers running from the 700 kHz E-clock would be better, but as jiffies use CIA B Timer A and the floppy driver uses CIA A Timer B, we don't have two available timers in the same CIA without some code shuffling.
3. What are the semantics of get_cycles()?
Does it have to be a "nice" counter, or can there be some irregularities?
I.e. can I add one more line
x = (x << 8) | ciab.talo; // low byte of 700 kHz timer
to get 32 bits?
arch/m68k/amiga/config.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/m68k/amiga/config.c +16 -0
@@ -358,6 +358,20 @@ static void __init amiga_identify(void)#undef AMIGAHW_ANNOUNCE } + +static cycles_t amiga_get_cycles (void ) +{ +cycles_t x; + +/* CIA B 24-bit TOD is clocked by HSYNC */ + x = ciab.todhi; + x = (x <<8 ) | ciab.todmid; + x = (x <<8 ) | ciab.todlo; + +return x; +} + +/* * Setup the Amiga configuration info */
@@ -395,6 +409,8 @@ void __init config_amiga(void) mach_heartbeat = amiga_heartbeat;#endif + mach_get_cycles = amiga_get_cycles; +/* Fill in the clock value (based on the 700 kHz E-Clock) */ amiga_colorclock =5 *amiga_eclock;/* 3.5 MHz */
Signature · 1 line
1.7.9.5
Geert Uytterhoeven
maintainerPATCH 2/2 m68k/amiga: Provide mach_get_cycles()
In reply to Geert UytterhoevenUse the 24-bit Time-Of-Day clock in CIA B, which is clocked by HSYNC.
---
1. Completely untested! It does compile ;-)
2. Is a 24-bit counter running at 15-31 kHz good enough?
Two cascaded 16-bit CIA timers running from the 700 kHz E-clock would be better, but as jiffies use CIA B Timer A and the floppy driver uses CIA A Timer B, we don't have two available timers in the same CIA without some code shuffling.
3. What are the semantics of get_cycles()?
Does it have to be a "nice" counter, or can there be some irregularities?
I.e. can I add one more line
x = (x << 8) | ciab.talo; // low byte of 700 kHz timer
to get 32 bits?
arch/m68k/amiga/config.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/m68k/amiga/config.c +16 -0
@@ -358,6 +358,20 @@ static void __init amiga_identify(void)#undef AMIGAHW_ANNOUNCE } + +static cycles_t amiga_get_cycles (void ) +{ +cycles_t x; + +/* CIA B 24-bit TOD is clocked by HSYNC */ + x = ciab.todhi; + x = (x <<8 ) | ciab.todmid; + x = (x <<8 ) | ciab.todlo; + +return x; +} + +/* * Setup the Amiga configuration info */
@@ -395,6 +409,8 @@ void __init config_amiga(void) mach_heartbeat = amiga_heartbeat;#endif + mach_get_cycles = amiga_get_cycles; +/* Fill in the clock value (based on the 700 kHz E-Clock) */ amiga_colorclock =5 *amiga_eclock;/* 3.5 MHz */
Signature · 1 line
1.7.9.5
Geert Uytterhoeven dixit:
Quoted 2 lines
Currently
get_cycles()always returns zero. Asget_cycles()is called to add entropy to the random number generator pool, security can be increased
You rock for having something before MIPS ;-) (Note that other architectures like CRIS are also affected… just, MIPS probably has the broadest impact… even I have a FreeWRT WLAN AP.)
Sorry I can’t provide any feedback because I’m out of my depth on both the hardware and the requirements aspect.
bye,
//mirabilos
Signature · 4 lines
Sometimes they [people] care too much: pretty printers [and syntax highligh- ting, d.A.] mechanically produce pretty output that accentuates irrelevant detail in the program, which is as sensible as putting all the prepositions in English text in bold font. -- Rob Pike in "Notes on Programming in C"