- rtclock.timebase_const.numer = numer;
- rtclock.timebase_const.denom = denom;
- UNLOCK_RTC(s);
-}
-
-/*
- * Configure the real-time clock device.
- */
-int
-sysclk_config(void)
-{
- int i;
-
- if (cpu_number() != master_cpu)
- return(1);
-
- for (i = 0; i < NCPUS; i++)
- timer_call_setup(&rtclock.alarm[i], rtclock_alarm_timer, NULL);
-
- simple_lock_init(&rtclock.lock, ETAP_MISC_RT_CLOCK);
-
- PE_register_timebase_callback(timebase_callback);
-
- return (1);
-}
-
-/*
- * Initialize the system clock device.
- */
-int
-sysclk_init(void)
-{
- uint64_t abstime;
- int decr, mycpu = cpu_number();
-
- if (mycpu != master_cpu) {
- if (rtclock_initialized == FALSE) {
- panic("sysclk_init on cpu %d, rtc not initialized\n", mycpu);
- }
- /* Set decrementer and hence our next tick due */
- clock_get_uptime(&abstime);
- rtclock_tick_deadline[mycpu] = abstime;
- rtclock_tick_deadline[mycpu] += rtclock_tick_interval;
- decr = deadline_to_decrementer(rtclock_tick_deadline[mycpu], abstime);
- mtdec(decr);
- rtclock.last_decr[mycpu] = decr;
-
- return(1);
- }
-
- /*
- * Initialize non-zero clock structure values.
- */
- clock_interval_to_absolutetime_interval(RTC_TICKPERIOD, 1,
- &rtclock_tick_interval);
- /* Set decrementer and our next tick due */
- clock_get_uptime(&abstime);
- rtclock_tick_deadline[mycpu] = abstime;
- rtclock_tick_deadline[mycpu] += rtclock_tick_interval;
- decr = deadline_to_decrementer(rtclock_tick_deadline[mycpu], abstime);
- mtdec(decr);
- rtclock.last_decr[mycpu] = decr;
-
- rtclock_initialized = TRUE;
-
- return (1);
-}
-
-#define UnsignedWide_to_scalar(x) (*(uint64_t *)(x))
-#define scalar_to_UnsignedWide(x) (*(UnsignedWide *)(x))
-
-/*
- * Perform a full 64 bit by 32 bit unsigned multiply,
- * yielding a 96 bit product. The most significant
- * portion of the product is returned as a 64 bit
- * quantity, with the lower portion as a 32 bit word.
- */
-static void
-umul_64by32(
- UnsignedWide now64,
- uint32_t mult32,
- UnsignedWide *result64,
- uint32_t *result32)
-{
- uint32_t mid, mid2;
-
- asm volatile(" mullw %0,%1,%2" :
- "=r" (*result32) :
- "r" (now64.lo), "r" (mult32));
-
- asm volatile(" mullw %0,%1,%2" :
- "=r" (mid2) :
- "r" (now64.hi), "r" (mult32));
- asm volatile(" mulhwu %0,%1,%2" :
- "=r" (mid) :
- "r" (now64.lo), "r" (mult32));
-
- asm volatile(" mulhwu %0,%1,%2" :
- "=r" (result64->hi) :
- "r" (now64.hi), "r" (mult32));
-
- asm volatile(" addc %0,%2,%3;
- addze %1,%4" :
- "=r" (result64->lo), "=r" (result64->hi) :
- "r" (mid), "r" (mid2), "1" (result64->hi));
-}
-
-/*
- * Perform a partial 64 bit by 32 bit unsigned multiply,
- * yielding a 64 bit product. Only the least significant
- * 64 bits of the product are calculated and returned.
- */
-static void
-umul_64by32to64(
- UnsignedWide now64,
- uint32_t mult32,
- UnsignedWide *result64)
-{
- uint32_t mid, mid2;
-
- asm volatile(" mullw %0,%1,%2" :
- "=r" (result64->lo) :
- "r" (now64.lo), "r" (mult32));
-
- asm volatile(" mullw %0,%1,%2" :
- "=r" (mid2) :
- "r" (now64.hi), "r" (mult32));
- asm volatile(" mulhwu %0,%1,%2" :
- "=r" (mid) :
- "r" (now64.lo), "r" (mult32));
-
- asm volatile(" add %0,%1,%2" :
- "=r" (result64->hi) :
- "r" (mid), "r" (mid2));
-}
-
-/*
- * Perform an unsigned division of a 96 bit value
- * by a 32 bit value, yielding a 96 bit quotient.
- * The most significant portion of the product is
- * returned as a 64 bit quantity, with the lower
- * portion as a 32 bit word.
- */
-static void
-udiv_96by32(
- UnsignedWide now64,
- uint32_t now32,
- uint32_t div32,
- UnsignedWide *result64,
- uint32_t *result32)
-{
- UnsignedWide t64;
-
- if (now64.hi > 0 || now64.lo >= div32) {
- UnsignedWide_to_scalar(result64) =
- UnsignedWide_to_scalar(&now64) / div32;