patch-2.4.25 linux-2.4.25/arch/ppc64/kernel/rtc.c
Next file: linux-2.4.25/arch/ppc64/kernel/scanlog.c
Previous file: linux-2.4.25/arch/ppc64/kernel/rtasd.c
Back to the patch index
Back to the overall index
- Lines: 113
- Date:
2004-02-18 05:36:30.000000000 -0800
- Orig file:
linux-2.4.24/arch/ppc64/kernel/rtc.c
- Orig date:
2004-01-05 05:53:56.000000000 -0800
diff -urN linux-2.4.24/arch/ppc64/kernel/rtc.c linux-2.4.25/arch/ppc64/kernel/rtc.c
@@ -33,6 +33,7 @@
#include <linux/proc_fs.h>
#include <linux/spinlock.h>
+#include <asm/hardirq.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/system.h>
@@ -273,20 +274,63 @@
}
+#define MAX_RTC_WAIT 5000 /* 5 sec */
+#define RTAS_CLOCK_BUSY (-2)
+void pSeries_get_boot_time(struct rtc_time *rtc_tm)
+{
+ unsigned long ret[8];
+ int error, wait_time;
+ unsigned long max_wait_tb;
+
+ max_wait_tb = __get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT;
+ do {
+ error = rtas_call(rtas_token("get-time-of-day"), 0, 8, (void *)&ret);
+ if (error == RTAS_CLOCK_BUSY || rtas_is_extended_busy(error)) {
+ wait_time = rtas_extended_busy_delay_time(error);
+ /* This is boot time so we spin. */
+ udelay(wait_time*1000);
+ error = RTAS_CLOCK_BUSY;
+ }
+ } while (error == RTAS_CLOCK_BUSY && (__get_tb() < max_wait_tb));
+
+ if (error != 0) {
+ printk(KERN_WARNING "error: reading the clock failed (%d)\n",
+ error);
+ return;
+ }
+
+ rtc_tm->tm_sec = ret[5];
+ rtc_tm->tm_min = ret[4];
+ rtc_tm->tm_hour = ret[3];
+ rtc_tm->tm_mday = ret[2];
+ rtc_tm->tm_mon = ret[1] - 1;
+ rtc_tm->tm_year = ret[0] - 1900;
+}
+
+/* NOTE: get_rtc_time will get an error if executed in interrupt context
+ * and if a delay is needed to read the clock. In this case we just
+ * silently return without updating rtc_tm.
+ */
void pSeries_get_rtc_time(struct rtc_time *rtc_tm)
{
unsigned long ret[8];
- int error;
- int count;
+ int error, wait_time;
+ unsigned long max_wait_tb;
- /*
- * error -2 is clock busy, we keep retrying a few times to see
- * if it will come good -- paulus
- */
- count = 0;
+ max_wait_tb = __get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT;
do {
error = rtas_call(rtas_token("get-time-of-day"), 0, 8, (void *)&ret);
- } while (error == -2 && ++count < 1000);
+ if (error == RTAS_CLOCK_BUSY || rtas_is_extended_busy(error)) {
+ if (in_interrupt()) {
+ printk(KERN_WARNING "error: reading clock would delay interrupt\n");
+ return; /* delay not allowed */
+ }
+ wait_time = rtas_extended_busy_delay_time(error);
+ set_current_state(TASK_INTERRUPTIBLE);
+ schedule_timeout(wait_time);
+ error = RTAS_CLOCK_BUSY;
+ }
+ } while (error == RTAS_CLOCK_BUSY && (__get_tb() < max_wait_tb));
if (error != 0) {
printk(KERN_WARNING "error: reading the clock failed (%d)\n",
@@ -304,20 +348,24 @@
int pSeries_set_rtc_time(struct rtc_time *tm)
{
- int error;
- int count;
+ int error, wait_time;
+ unsigned long max_wait_tb;
- /*
- * error -2 is clock busy, we keep retrying a few times to see
- * if it will come good -- paulus
- */
- count = 0;
+ max_wait_tb = __get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT;
do {
error = rtas_call(rtas_token("set-time-of-day"), 7, 1, NULL,
tm->tm_year + 1900, tm->tm_mon + 1,
tm->tm_mday, tm->tm_hour, tm->tm_min,
tm->tm_sec, 0);
- } while (error == -2 && ++count < 1000);
+ if (error == RTAS_CLOCK_BUSY || rtas_is_extended_busy(error)) {
+ if (in_interrupt())
+ return 1; /* probably decrementer */
+ wait_time = rtas_extended_busy_delay_time(error);
+ set_current_state(TASK_INTERRUPTIBLE);
+ schedule_timeout(wait_time);
+ error = RTAS_CLOCK_BUSY;
+ }
+ } while (error == RTAS_CLOCK_BUSY && (__get_tb() < max_wait_tb));
if (error != 0)
printk(KERN_WARNING "error: setting the clock failed (%d)\n",
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)