net: Use NULL to signal lack of promisc/multicast
[akaros.git] / kern / arch / riscv / time.c
index 2059017..c03b80e 100644 (file)
@@ -1,48 +1,53 @@
 #include <arch/time.h>
 #include <ros/common.h>
-#include <arch/trap.h>
+#include <trap.h>
 #include <arch/arch.h>
 #include <stdio.h>
 #include <assert.h>
-
-system_timing_t system_timing = {0};
+#include <ros/procinfo.h>
 
 void
 timer_init(void)
-{      
-  mtpcr(PCR_COUNT, 0);
-  mtpcr(PCR_COMPARE, 0);
-       mtpcr(PCR_SR, mfpcr(PCR_SR) | (SR_IM & (1 << (TIMER_IRQ+SR_IM_SHIFT))));
-
-       system_timing.tsc_freq = TSC_HZ;
-       cprintf("TSC Frequency: %llu\n", system_timing.tsc_freq);
+{
+       __proc_global_info.tsc_freq = TSC_HZ;
+       cprintf("TSC Frequency: %llu\n", __proc_global_info.tsc_freq);
 }
 
-/* Warning: one-shot timers are unsupported; all timers are periodic.
- * Perhaps this support could be added with a per_cpu boolean, set
- * by set_core_timer, and interpreted by the interrupt handler. */
 void
 set_core_timer(uint32_t usec, bool periodic)
 {
-       uint32_t clocks =  (uint64_t)usec*TSC_HZ/1000000;
+       // we could implement periodic timers using one-shot timers,
+       // but for now we only support one-shot
+       assert(!periodic);
 
-  int8_t irq_state = 0;
-       disable_irqsave(&irq_state);
+       if (usec)
+       {
+               uint32_t clocks =  (uint64_t)usec*TSC_HZ/1000000;
+
+               int8_t irq_state = 0;
+               disable_irqsave(&irq_state);
 
-  mtpcr(PCR_COMPARE, mfpcr(PCR_COUNT) + clocks);
+               mtpcr(PCR_COUNT, 0);
+               mtpcr(PCR_COMPARE, clocks);
+               mtpcr(PCR_SR, mfpcr(PCR_SR) | (1 << (IRQ_TIMER+SR_IM_SHIFT)));
 
-       enable_irqsave(&irq_state);
+               enable_irqsave(&irq_state);
+       }
+       else
+       {
+               mtpcr(PCR_SR, mfpcr(PCR_SR) & ~(1 << (IRQ_TIMER+SR_IM_SHIFT)));
+       }
 }
 
 void
 udelay(uint64_t usec)
 {
-       if (system_timing.tsc_freq != 0)
+       if (__proc_global_info.tsc_freq != 0)
        {
                uint64_t start, end, now;
-        
+
                start = read_tsc();
-               end = start + (system_timing.tsc_freq * usec) / 1000000;
+               end = start + (__proc_global_info.tsc_freq * usec) / 1000000;
 
                do
                {
@@ -52,3 +57,8 @@ udelay(uint64_t usec)
        }
        else panic("udelay() was called before timer_init(), moron!");
 }
+
+uint64_t read_persistent_clock(void)
+{
+       return 1242129600 * 1000000000UL; /* nanwan's birthday */
+}