]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/AT386/bbclock.c
xnu-792.tar.gz
[apple/xnu.git] / osfmk / i386 / AT386 / bbclock.c
index ffcad7a77b23af73a7d95691933b4d949a867572..f52b3694b6c73fedfb6575110e2eaeceaf8678c3 100644 (file)
@@ -51,6 +51,8 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <kern/spl.h>
 #include <kern/processor.h>
 #include <kern/misc_protos.h>
+#include <i386/cpu_data.h>
+#include <i386/cpu_number.h>
 #include <i386/pio.h>
 #include <i386/AT386/rtc.h>
 #include <i386/AT386/bbclock_entries.h>
@@ -81,13 +83,12 @@ bbc_config(void)
        int             BbcFlag;
        struct rtc_st   rtclk;
 
-#if    NCPUS > 1 && AT386
        mp_disable_preemption();
        if (cpu_number() != master_cpu) {
                mp_enable_preemption();
                return(1);
        }
-#endif
+
        /*
         * Setup device.
         */
@@ -104,9 +105,7 @@ bbc_config(void)
                printf("battery clock configured\n");
        else
                printf("WARNING: Battery Clock Failure!\n");
-#if    NCPUS > 1 && AT386
        mp_enable_preemption();
-#endif
        return (BbcFlag);
 }
 
@@ -124,7 +123,6 @@ bbc_gettime(
        spl_t           s;
        thread_t        thread;
 
-#if    NCPUS > 1 && AT386
        if ((thread = current_thread()) != THREAD_NULL) {
                thread_bind(thread, master_processor);
                mp_disable_preemption();
@@ -135,7 +133,7 @@ bbc_gettime(
                        mp_enable_preemption();
                }
        }
-#endif
+
        s = LOCK_BBC();
        rtcget(&rtclk);
        sec = hexdectodec(rtclk.rtc_sec);
@@ -159,10 +157,8 @@ bbc_gettime(
        cur_time->tv_nsec = 0;
        UNLOCK_BBC(s);
 
-#if    NCPUS > 1 && AT386
        if (thread != THREAD_NULL)
                thread_bind(thread, PROCESSOR_NULL);
-#endif
        return (KERN_SUCCESS);
 }
 
@@ -179,7 +175,6 @@ bbc_settime(
        spl_t           s;
        thread_t        thread;
 
-#if    NCPUS > 1 && AT386
        if ((thread = current_thread()) != THREAD_NULL) {
                thread_bind(thread, master_processor);
                mp_disable_preemption();
@@ -190,7 +185,7 @@ bbc_settime(
                        mp_enable_preemption();
                }
        }
-#endif
+
        s = LOCK_BBC();
        rtcget(&rtclk);
        diff = 0;
@@ -201,7 +196,7 @@ bbc_settime(
        rtclk.rtc_hr = dectohexdec(n/60);
        n = (new_time->tv_sec - diff) / (3600 * 24);    /* days */
        rtclk.rtc_dow = (n + 4) % 7;  /* 1/1/70 is Thursday */
-       for (j = 1970; n >= (i = yeartoday(j)); j++)
+       for (j = 70; n >= (i = yeartoday(j)); j++)
                n -= i;
        rtclk.rtc_yr = dectohexdec(j % 100);
        if (yeartoday(j) == 366)
@@ -214,39 +209,9 @@ bbc_settime(
        rtcput(&rtclk);
        UNLOCK_BBC(s);
 
-#if    NCPUS > 1 && AT386
        if (thread != THREAD_NULL)
                thread_bind(current_thread(), PROCESSOR_NULL);
-#endif
-       return (KERN_SUCCESS);
-}
 
-/*
- * Get clock device attributes.
- */
-kern_return_t
-bbc_getattr(
-       clock_flavor_t          flavor,
-       clock_attr_t            attr,           /* OUT */
-       mach_msg_type_number_t  *count)         /* IN/OUT */
-{
-       if (*count != 1)
-               return (KERN_FAILURE);
-       switch (flavor) {
-
-       case CLOCK_GET_TIME_RES:        /* >0 res */
-               *(clock_res_t *) attr = NSEC_PER_SEC;
-               break;
-
-       case CLOCK_ALARM_CURRES:        /* =0 no alarm */
-       case CLOCK_ALARM_MINRES:
-       case CLOCK_ALARM_MAXRES:
-               *(clock_res_t *) attr = 0;
-               break;
-
-       default:
-               return (KERN_INVALID_VALUE);
-       }
        return (KERN_SUCCESS);
 }
 
@@ -258,7 +223,7 @@ rtcget(
        struct rtc_st   * regs)
 {
        outb(RTC_ADDR, RTC_D); 
-       if (inb(RTC_DATA) & RTC_VRT == 0)
+       if ((inb(RTC_DATA) & RTC_VRT) == 0)
                return (-1);
        outb(RTC_ADDR, RTC_A);  
        while (inb(RTC_DATA) & RTC_UIP)         /* busy wait */
@@ -286,7 +251,7 @@ int
 yeartoday(
        int     year)
 {
-  year += 1900;
+        year += 1900;
        return((year % 4) ? 365 :
               ((year % 100) ? 366 : ((year % 400) ? 365: 366)));
 }