# HG changeset patch # User Josef 'Jeff' Sipek # Date 1299713994 18000 # Node ID a4d737f03f883895d1718d9b346073e513f0e5bb # Parent e2b1d61847032f4484b1d853336df4ae2dfd2e2f import TOD code diff -r e2b1d6184703 -r a4d737f03f88 include/tod.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/tod.h Wed Mar 09 18:39:54 2011 -0500 @@ -0,0 +1,45 @@ +#ifndef __TOD_H +#define __TOD_H + +/* + * The Time Of Day (TOD) hardware adds 1 to the 51st bit every microsecond + * The timer hardware subtracts 1 from the 51st bit every microsecond + */ +#define TOD_MICROSEC 0x0000000000001000UL +#define TOD_SEC 0x0000000f4240000ULL +#define TOD_MIN 0x000003938700000ULL +#define TOD_HOUR 0x0000d693a400000ULL +#define TOD_DAY 0x00141dd76000000ULL +#define TOD_YEAR 0x1cae8c13e000000ULL /* not leap */ +#define TOD_FOURYEARS 0x72ce4e26e000000ULL + +/* + * Stores (if possible) the current TOD value. + * + * Returns: + * 0 on success, *tod contains current time & date + * *tod == 0 is midnight, Jan 1, 1900 + * 1 on success, *tod contains uptime + * *tod == 0 is the instant the system powered on + * 2 or 3 on failure, value of *tod is unpredictable + */ +static inline int get_tod(u64 *tod) +{ + int cc; + + asm volatile( + "stck %0\n" + "ipm %1\n" + "srl %1,28\n" + : /* output */ + "=m" (*tod), + "=d" (cc) + : /* input */ + : /* clobber */ + "cc" + ); + + return cc; +} + +#endif