changeset 18:43275cae082f

Merge
author Jonathan Pevarnek <pevarnj@gmail.com>
date Thu, 10 Mar 2011 17:26:35 -0500
parents 525eab23e68a (current diff) d3c54eb7510b (diff)
children def4b04c99f9
files
diffstat 1 files changed, 78 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/tod.h	Thu Mar 10 17:26:35 2011 -0500
@@ -0,0 +1,78 @@
+#ifndef __TOD_H
+#define __TOD_H
+
+/*
+ * The Time Of Day (TOD) hardware adds 1 to the 51st bit every microsecond.
+ * The TOD value 0 is defined as 00:00:00 on Jan 1, 1900.
+ *
+ * Here are the TOD values for each of the leap seconds, as well as the
+ * beginning of UTC (Jan 1, 1970).
+ *
+ * Year  Month  Day  Leap Sec.  Clock Setting (Hex)
+ * ------------------------------------------------
+ * 1900      1    1       N/A   0000 0000 0000 0000
+ * 1972      1    1       N/A   8126 D60E 4600 0000
+ * 1972      7    1         1   820B A981 1E24 0000
+ * 1973      1    1         2   82F3 00AE E248 0000
+ * 1974      1    1         3   84BD E971 146C 0000
+ * 1975      1    1         4   8688 D233 4690 0000
+ * 1976      1    1         5   8853 BAF5 78B4 0000
+ * 1977      1    1         6   8A1F E595 20D8 0000
+ * 1978      1    1         7   8BEA CE57 52FC 0000
+ * 1979      1    1         8   8DB5 B719 8520 0000
+ * 1980      1    1         9   8F80 9FDB B744 0000
+ * 1981      7    1        10   9230 5C0F CD68 0000
+ * 1982      7    1        11   93FB 44D1 FF8C 0000
+ * 1983      7    1        12   95C6 2D94 31B0 0000
+ * 1985      7    1        13   995D 40F5 17D4 0000
+ * 1988      1    1        14   9DDA 69A5 57F8 0000
+ * 1990      1    1        15   A171 7D06 3E1C 0000
+ * 1991      1    1        16   A33C 65C8 7040 0000
+ * 1992      7    1        17   A5EC 21FC 8664 0000
+ * 1993      7    1        18   A7B7 0ABE B888 0000
+ * 1994      7    1        19   A981 F380 EAAC 0000
+ * 1996      1    1        20   AC34 336F ECD0 0000
+ * 1997      7    1        21   AEE3 EFA4 02F4 0000
+ * 1999      1    1        22   B196 2F93 0518 0000
+ * 2006      1    1        23   BE25 1097 973C 0000
+ * 2009      1    1        24   C387 0CB9 BB60 0000
+ */
+
+#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